A memtable cannot grow forever - eventually it must flush to disk. Today you track its approximate size in bytes so a later lesson can decide "this is full, time to flush".
Maintain a running byte-size total for the memtable that reflects the current live entries.
The memtable lives in RAM, so it has a budget. When it fills past a threshold, the engine freezes it and writes it out as an SSTable - the event that makes an LSM engine an on-disk store. To make that decision, the memtable has to know roughly how big it is.
Today’s total is deliberately simple: the sum of len(key) + len(value) over the
live entries. The subtle part is overwrites - putting a new value for an
existing key must adjust the total by the difference, not just add the new
length, or a hot key rewritten many times would inflate the size far beyond what
it actually occupies. Get this right and the flush trigger you wire up later fires
at the right moment.
// size = sum over live entries of len(key)+len(value)// on overwrite, subtract the old value's length before adding// the new one so the total tracks what is actually storedfunc (m *Memtable) Size() int { return m.size }