memory method

int memory({
  1. int objectReferenceBytes = 8,
})

Estimates internal memory usage in bytes.

objectReferenceBytes is the assumed size (in bytes) of a single object reference (typically 8 bytes on 64-bit runtimes).

The estimate includes all core internal buffers and scalar fields, but excludes VM object headers, alignment, and allocator overhead. Intended for diagnostics and relative comparisons only.

Implementation

int memory({int objectReferenceBytes = 8}) {
  final capacityBytes = capacityBits ~/ 8;
  return
      // key/value references
      objectReferenceBytes +
          (_chainKey.length * objectReferenceBytes) +
          objectReferenceBytes +
          (_chainVal.length * objectReferenceBytes) +
          // stored hash codes (Uint32)
          objectReferenceBytes +
          (_chainHash.length * 4) +
          // chain pointers (adaptive width)
          objectReferenceBytes +
          (_chainNext.length * capacityBytes) +
          // bucket heads and bucket sizes (Uint32)
          objectReferenceBytes +
          (_groups.length * 4) +
          objectReferenceBytes +
          (_groupsSizes.length * 4) +
          // scalar fields (ints):
          // _size, _chainLength, _chainRemoved
          (3 * 8);
}