diff options
Diffstat (limited to 'lib/system/alloc.nim')
-rw-r--r-- | lib/system/alloc.nim | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 95becde22..ffb7aaf86 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -116,6 +116,8 @@ type nextChunkSize: int bottomData: AvlNode heapLinks: HeapLinks + when defined(nimTypeNames): + allocCounter, deallocCounter: int const fsLookupTable: array[byte, int8] = [ @@ -434,8 +436,9 @@ proc requestOsChunks(a: var MemRegion, size: int): PBigChunk = a.nextChunkSize = PageSize*4 else: a.nextChunkSize = min(roundup(usedMem shr 2, PageSize), a.nextChunkSize * 2) - var size = size + a.nextChunkSize = min(a.nextChunkSize, MaxBigChunkSize) + var size = size if size > a.nextChunkSize: result = cast[PBigChunk](osAllocPages(size)) else: @@ -737,6 +740,8 @@ when false: result = nil proc rawAlloc(a: var MemRegion, requestedSize: int): pointer = + when defined(nimTypeNames): + inc(a.allocCounter) sysAssert(allocInv(a), "rawAlloc: begin") sysAssert(roundup(65, 8) == 72, "rawAlloc: roundup broken") sysAssert(requestedSize >= sizeof(FreeCell), "rawAlloc: requested size too small") @@ -810,6 +815,8 @@ proc rawAlloc0(a: var MemRegion, requestedSize: int): pointer = zeroMem(result, requestedSize) proc rawDealloc(a: var MemRegion, p: pointer) = + when defined(nimTypeNames): + inc(a.deallocCounter) #sysAssert(isAllocatedPtr(a, p), "rawDealloc: no allocated pointer") sysAssert(allocInv(a), "rawDealloc: begin") var c = pageAddr(p) @@ -975,6 +982,10 @@ proc getOccupiedMem(a: MemRegion): int {.inline.} = result = a.occ # a.currMem - a.freeMem +when defined(nimTypeNames): + proc getMemCounters(a: MemRegion): (int, int) {.inline.} = + (a.allocCounter, a.deallocCounter) + # ---------------------- thread memory region ------------------------------- template instantiateForRegion(allocator: untyped) = @@ -1018,6 +1029,9 @@ template instantiateForRegion(allocator: untyped) = proc getOccupiedMem(): int = return allocator.occ #getTotalMem() - getFreeMem() proc getMaxMem*(): int = return getMaxMem(allocator) + when defined(nimTypeNames): + proc getMemCounters*(): (int, int) = getMemCounters(allocator) + # -------------------- shared heap region ---------------------------------- when hasThreadSupport: var sharedHeap: MemRegion |