Track memory during deallocation correctly.

It used to subtract the number of bytes during deallocation, but
that required knowing the size of an object at free time. That
isn't always available. The old code could read a freed object
while doing this. Bad!

Instead, this tracks how much memory is still being used by
marked objects. It's correct, and is also a bit less code and
faster.
This commit is contained in:
Bob Nystrom
2013-12-14 14:17:16 -08:00
parent 3fd7fa56fb
commit 5c807c0ec5
4 changed files with 124 additions and 124 deletions
+6 -2
View File
@@ -212,8 +212,12 @@ struct WrenVM
// Memory management data:
// How many bytes of object data have been allocated so far.
size_t totalAllocated;
// TODO(bob): Temp.
// The number of bytes that are known to be currently allocated. Includes all
// memory that was proven live after the last GC, as well as any new bytes
// that were allocated since then. Does *not* include bytes for objects that
// were freed since the last GC.
size_t bytesAllocated;
// The number of total allocated bytes that will trigger the next GC.
size_t nextGC;