ArrayManager

The ArrayManager class is an internal class that manages arrays allocated in memory.

Allocation and Referencing

When you create a new array, it needs to have space in memory allocated for it. CreateArrayBlock<T>() is called in the array’s Construct method, called when an array is instantiated. Memory segments generated by allocating memory blocks is stored in the Segments field.

When you rereference the same array, such as by referencing an array’s contents to another object, the reference counter increments by calling RefArrayBlock(). When you dereference an array, such as when its deconstructor is called, the reference counter decrements by calling UnrefArrayBlock().

When the ref count drops below 1, the array is deallocated.

MemorySegmentSpec

MemorySegmentSpec is a struct that holds data about arrays currently stored in memory, and is only available to the ArrayManager class.

  • Address - Aligned IntPtr address ready for use.
  • ByteCount - Number of bytes guarenteed allocated.
  • Alignment - Guarenteed alignment.
  • RefCount - Number of references.