summary refs log tree commit diff stats
path: root/lib/system/alloc.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-11-28 20:59:30 +0100
committerAraq <rumpf_a@web.de>2016-11-28 20:59:30 +0100
commit27723af469a937835b9679c41364d9db0090036e (patch)
treeecdd90e6287d4c172e63cae3f6b25169f4b88708 /lib/system/alloc.nim
parentebaf57ea3bc17d1476e9d4bbd8d107eb6dd631a2 (diff)
parentf9c184a4932eb839a6ec4b9293e37583cd33a89a (diff)
downloadNim-27723af469a937835b9679c41364d9db0090036e.tar.gz
Merge branch 'devel' into sighashes
Diffstat (limited to 'lib/system/alloc.nim')
-rw-r--r--lib/system/alloc.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index 745bbbf62..3a8e8a1b6 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -15,6 +15,10 @@
 
 include osalloc
 
+template track(op, address, size) =
+  when defined(memTracker):
+    memTrackerOp(op, address, size)
+
 # We manage *chunks* of memory. Each chunk is a multiple of the page size.
 # Each chunk starts at an address that is divisible by the page size. Chunks
 # that are bigger than ``ChunkOsReturn`` are returned back to the operating
@@ -645,6 +649,7 @@ proc alloc(allocator: var MemRegion, size: Natural): pointer =
   cast[ptr FreeCell](result).zeroField = 1 # mark it as used
   sysAssert(not isAllocatedPtr(allocator, result), "alloc")
   result = cast[pointer](cast[ByteAddress](result) +% sizeof(FreeCell))
+  track("alloc", result, size)
 
 proc alloc0(allocator: var MemRegion, size: Natural): pointer =
   result = alloc(allocator, size)
@@ -658,6 +663,7 @@ proc dealloc(allocator: var MemRegion, p: pointer) =
   sysAssert(cast[ptr FreeCell](x).zeroField == 1, "dealloc 2")
   rawDealloc(allocator, x)
   sysAssert(not isAllocatedPtr(allocator, x), "dealloc 3")
+  track("dealloc", p, 0)
 
 proc realloc(allocator: var MemRegion, p: pointer, newsize: Natural): pointer =
   if newsize > 0: