Maintain size of allocated memory in the heap.
This commit is contained in:
parent
6971cc59b0
commit
5f2106f512
1 changed files with 9 additions and 0 deletions
|
@ -221,6 +221,9 @@ size_t heapmaxsize = SIZE_MAX;
|
|||
// excludes the wilderness.
|
||||
size_t heapsize = 0;
|
||||
|
||||
// How many bytes of actual storage the heap contains.
|
||||
size_t heapstorage = 0;
|
||||
|
||||
// bins[N] contain a linked list of chunks that are at least 2^(N+1)
|
||||
// bytes, but less than 2^(N+2) bytes. By selecting the proper bin in
|
||||
// constant time, we can allocate chunks in constant time.
|
||||
|
@ -502,6 +505,8 @@ extern "C" void* malloc(size_t size)
|
|||
chunk->magic = MAGIC;
|
||||
chunk->GetTrailer()->magic = MAGIC;
|
||||
|
||||
heapstorage += chunk->size;
|
||||
|
||||
#if 3 <= PARANOIA
|
||||
assert(ValidateHeap());
|
||||
#endif
|
||||
|
@ -546,6 +551,8 @@ extern "C" void* malloc(size_t size)
|
|||
chunk->magic = MAGIC;
|
||||
trailer->magic = MAGIC;
|
||||
|
||||
heapstorage += chunk->size;
|
||||
|
||||
#if 3 <= PARANOIA
|
||||
assert(ValidateHeap());
|
||||
#endif
|
||||
|
@ -671,6 +678,8 @@ extern "C" void free(void* addr)
|
|||
assert(chunk->IsUsed());
|
||||
assert(chunk->IsSane());
|
||||
|
||||
heapstorage -= chunk->size;
|
||||
|
||||
UnifyNeighbors(&chunk);
|
||||
|
||||
bool nexttowilderness = IsRightmostChunk(chunk);
|
||||
|
|
Loading…
Reference in a new issue