Restore java serialize behavior - #3
Conversation
| MemorySegment datasetOutPtr = arena.allocate(cuvsDataset_t); | ||
| datasetOutPtr.set(cuvsDataset_t, 0, MemorySegment.NULL); |
There was a problem hiding this comment.
Is there a reason why we allocate dataset like this rather than call C API's factory?
There was a problem hiding this comment.
This only allocates the pointer-sized out-parameter slot required by Panama. The slot is initialized to NULL, and cuvsCagraDeserializeGraphAndDataset allocates the actual dataset and populates it. Calling cuvsDatasetCreate` first would pass a non-null handle and violate the deserializer contract.
| * @param inputStream an instance of {@link InputStream} | ||
| * @return an instance of {@link IndexReference} | ||
| */ | ||
| private IndexReference deserialize( |
There was a problem hiding this comment.
Is there a reason why we return IndexReference which is a pointer to the dataset? I thought outDataset was pre-allocated by the user and passed in by reference to be populated by within deserialize(). Is there a reason why we are moving away from this API contract and going back to the original where deserialize can internally allocate and hide memory allocations?
There was a problem hiding this comment.
IndexReference is an internal Java construction result, not a dataset pointer or public return value. It carries the newly populated native index handle and optionally retains the dataset lifetime holder for the ordinary upstream load path. When outDataset is provided, that wrapper receives the single native dataset handle and IndexReference does not retain another owner.
| this(inputStream, resources, null); | ||
| } | ||
|
|
||
| private CagraIndexImpl( |
There was a problem hiding this comment.
What is this used for? Is this a java specific thing?
There was a problem hiding this comment.
Yes, this is Java-specific. The existing two-argument constructor preserves Builder.from(inputStream).build() behavior and delegates to the overload with no explicit output. The overload is used only when the caller asks to retain the deserialized dataset separately.
No description provided.