diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-03-07 20:42:22 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-03-07 20:42:22 +0300 |
commit | 4a36bbbb9f40ce72a86c5444f44dd91fb8044f8b (patch) | |
tree | b115eb51562c2f931d784a7e6a7fa4279e4a1373 /src/Platform | |
parent | 45672a6ccab933868acd42010900aceab803e2f8 (diff) |
Corrected heap reporting
Diffstat (limited to 'src/Platform')
-rw-r--r-- | src/Platform/Heap.cpp | 18 | ||||
-rw-r--r-- | src/Platform/Heap.h | 1 |
2 files changed, 6 insertions, 13 deletions
diff --git a/src/Platform/Heap.cpp b/src/Platform/Heap.cpp index 480617a4..1f7f389a 100644 --- a/src/Platform/Heap.cpp +++ b/src/Platform/Heap.cpp @@ -327,22 +327,14 @@ unsigned int StringHandle::gcCyclesDone = 0; // Create a new heap block heapRoot = new HeapBlock(heapRoot); - heapAllocated += HeapBlockSize - (length + sizeof(StorageSpace::length)); + heapAllocated += HeapBlockSize; + heapUsed += length + sizeof(StorageSpace::length); StorageSpace * const ret2 = reinterpret_cast<StorageSpace*>(heapRoot->data); ret2->length = length; heapRoot->allocated = length + sizeof(StorageSpace::length); return ret2; } -/*static*/ void StringHandle::ReleaseSpace(StorageSpace *ptr) noexcept -{ - if (ptr != nullptr) - { - heapToRecycle += ptr->length; - ptr->length |= 1; // flag the space as unused - } -} - // StringHandle members // Build a handle from a single null-terminated string StringHandle::StringHandle(const char *s) noexcept : StringHandle(s, strlen(s)) { } @@ -374,7 +366,7 @@ void StringHandle::Assign(const char *s) noexcept void StringHandle::InternalAssign(const char *s, size_t len) noexcept { - IndexSlot * const slot = AllocateHandle(); // allocate a handle + IndexSlot * const slot = AllocateHandle(); // allocate a handle StorageSpace * const space = AllocateSpace(len + 1); const size_t lengthToCopy = min<size_t>(len, space->length - 1); // truncate the string if it won't fit memcpy(space->data, s, lengthToCopy); @@ -406,9 +398,11 @@ const StringHandle& StringHandle::IncreaseRefCount() const noexcept void StringHandle::InternalDelete() noexcept { RRF_ASSERT(slotPtr->refCount != 0); + RRF_ASSERT(slotPtr->storage != nullptr); if (--slotPtr->refCount == 0) { - ReleaseSpace(slotPtr->storage); // release the space + heapToRecycle += slotPtr->storage->length + sizeof(StorageSpace::length); + slotPtr->storage->length |= 1; // flag the space as unused slotPtr->storage = nullptr; // release the handle entry --handlesUsed; } diff --git a/src/Platform/Heap.h b/src/Platform/Heap.h index 4952af6b..31c3619a 100644 --- a/src/Platform/Heap.h +++ b/src/Platform/Heap.h @@ -47,7 +47,6 @@ protected: static IndexSlot *AllocateHandle() noexcept; static StorageSpace *AllocateSpace(size_t length) noexcept; - static void ReleaseSpace(StorageSpace *ptr) noexcept; static void GarbageCollectInternal() noexcept; static void AdjustHandles(char *startAddr, char *endAddr, size_t moveDown, unsigned int numHandles) noexcept; |