To read binary/string data without copying, we need a method that returns a reference to the binary data. In this implementation, we should manage the lifetime of the referenced data.
A possible approach is
- Creating a raw data reference that is a slice of a memory region, that is, a slice of an
MessageBuffer. When this message buffer is garbage collected, it means that the returned reference is no longer used in the program and we can safely release the memory.
- To implement this, we can use
ReferenceQueue to be notified when the target object is garbage-collected.
- We also need MemoryAllocator that manages the total amount of allocated memories.