Class AddressesScratch

java.lang.Object
org.elasticsearch.simdvec.internal.AddressesScratch

public final class AddressesScratch extends Object
Reusable, lazily-grown scratch buffer for an array of native addresses (pointer-width values), used to hand a contiguous MemorySegment of MemorySegment#address()-style values (array of pointers).

Not thread-safe; instances must not be shared across threads.

  • Constructor Details

    • AddressesScratch

      public AddressesScratch()
  • Method Details

    • get

      public MemorySegment get(int count)
      Returns a MemorySegment of at least count native-address slots. The buffer may be larger than requested (it is grown lazily and never shrunk across calls); callers must respect their own count when reading or writing addresses. Always returns the same backing segment for a given instance until a larger one is needed.

      Segments are returned from an auto arena, so they are garbage-collected. Choice here was between:

      • a confined arena (but confined arenas have thread affinity, which is probably OK for our use cases, but it would add a very implicit contract),
      • a shared arena (but that has extra invocation costs)
      • or an auto arena.
      The first 2 would have to be closed and re-created (basically, 1 arena - 1 segment). The pro would have been a more controlled/deterministic lifecycle. The cons are listed above, plus the additional complexity that an auto arena does not have. Auto here seems to be the sweet spot.