Skip to content

Zero-copy access to VectorFloat<?> vectors backed by float[] arrays #696

Description

@reta

Problem

At the moment, the general patterns to extract float[] arrays from VectorFloat<?> instances are as such:

The reality is that all current implementations of VectorFloat<?> (but not necessarily future ones) are backed by float[] and could provide fast, zero-copy access to it.

Possible solutions

New API, opt-in only

Add FloatArray interface to allow easy float[] vector extraction from MemorySegmentVectorFloat and ArrayVectorFloat instances. It solves the problem by directly exposing the backed array through float[] array() method, no copying. This is opt-in only, the change is 100% non-breaking.

See please: #694

Change existing API

Add toArray method to existing VectorFloat<?> API. This is simpler change (since we could provide the default implementation using length() + get(index)) but we cannot guarantee that every toArray implementation is going to be zero copy, although we could document that.

See please: #697

CC @ashkrisk @akash-shankaran

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions