diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-11-29 20:10:52 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-11-29 20:10:52 +0100 |
commit | 350396e1cab824ec69a9a06380ff15a7fa799819 (patch) | |
tree | 07260fc98ad5fec45e506df61b31010f49023046 /lib/core/allocators.nim | |
parent | 7d82df20be6db24d54ebe8963805f66e8f3c75f7 (diff) | |
download | Nim-350396e1cab824ec69a9a06380ff15a7fa799819.tar.gz |
gc:destructors: more progress
Diffstat (limited to 'lib/core/allocators.nim')
-rw-r--r-- | lib/core/allocators.nim | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/core/allocators.nim b/lib/core/allocators.nim index 9d79c9c32..5189bb762 100644 --- a/lib/core/allocators.nim +++ b/lib/core/allocators.nim @@ -18,6 +18,8 @@ type realloc*: proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.} deallocAll*: proc (a: Allocator) {.nimcall.} flags*: set[AllocatorFlag] + allocCount: int + deallocCount: int var localAllocator {.threadvar.}: Allocator @@ -30,8 +32,10 @@ proc getLocalAllocator*(): Allocator = result = addr allocatorStorage result.alloc = proc (a: Allocator; size: int; alignment: int = 8): pointer {.nimcall.} = result = system.alloc(size) + inc a.allocCount result.dealloc = proc (a: Allocator; p: pointer; size: int) {.nimcall.} = system.dealloc(p) + inc a.deallocCount result.realloc = proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.} = result = system.realloc(p, newSize) result.deallocAll = nil @@ -47,15 +51,6 @@ proc getSharedAllocator*(): Allocator = proc setSharedAllocator*(a: Allocator) = sharedAllocator = a -when false: - proc alloc*(size: int; alignment: int = 8): pointer = - let a = getCurrentAllocator() - result = a.alloc(a, size, alignment) - - proc dealloc*(p: pointer; size: int) = - let a = getCurrentAllocator() - a.dealloc(a, p, size) - - proc realloc*(p: pointer; oldSize, newSize: int): pointer = - let a = getCurrentAllocator() - result = a.realloc(a, p, oldSize, newSize) +proc allocCounters*(): (int, int) = + let a = getLocalAllocator() + result = (a.allocCount, a.deallocCount) |