Skip to content

Move from ByteBuffer to Memory #3892

@leventov

Description

@leventov

The goal of this issue is to agree on basic design principles and expectations from this refactoring.

Goals

Design

  • Based on DataSketches's Memory.
  • It is moved to Druid source tree, not used as a dependency. See Move from ByteBuffer to Memory #3892 (comment)
  • Memory object is immutable. "position and limit", if needed, are passed along with Memory as two primitive longs.
  • Upon creation a mutable Memory object has a cached immutable "view" object (which implements read methods and throws exception from write methods), this object is always returned when "as read only" is needed.
  • Explicit close() or free() on Memory is possible, but not strictly required, there is a sun.misc.Cleaner safety net, as well as in DirectByteBuffer.
  • While transition from ByteBuffer to Memory is in progress (not expected to be done all at once, but subsystem by subsystem, class by class see Move from ByteBuffer to Memory #3892 (comment)), and also when we need to interop with external libraries which require ByteBuffer, conversion from Memory to ByteBuffer and vice versa is possible. Likely it requires to
    • Use DirectByteBuffer-compatible format of Cleaner inside Memory
    • Be able to access private DirectByteBuffer constructors via MagicAccessorImpl.
  • + "Global" (immutable) Memory's bounds are checked optionally via assertions/guarded by static final boolean flag, "local" position and limit are check explicitly manually, with helper methods or versions of read and write methods of Memory, which accept read/write position and "local" limits. Move from ByteBuffer to Memory #3892 (comment)

Objections, additions, corrections, questions are welcome.
@leerho @cheddar @weijietong @akashdw @himanshug @fjy @niketh

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    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