summary refs log tree commit diff stats
path: root/lib/system/mmdisp.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-01-15 23:47:49 +0100
committerAraq <rumpf_a@web.de>2012-01-15 23:47:49 +0100
commit4de5b82fdca41204afe0e5405b27d325bb9cf164 (patch)
treebec9edee9bb7d4ddcf21005bf9bcfb0303abd255 /lib/system/mmdisp.nim
parent9a2df340a78c10d092599cf5b0222eea5ecb67f2 (diff)
downloadNim-4de5b82fdca41204afe0e5405b27d325bb9cf164.tar.gz
better inferfacing to boehm GC
Diffstat (limited to 'lib/system/mmdisp.nim')
-rwxr-xr-xlib/system/mmdisp.nim30
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim
index 9dc0ca8ee..33df8e89a 100755
--- a/lib/system/mmdisp.nim
+++ b/lib/system/mmdisp.nim
@@ -79,6 +79,23 @@ when defined(boehmgc):
     importc: "GC_realloc", dynlib: boehmLib.}
   proc boehmDealloc(p: pointer) {.importc: "GC_free", dynlib: boehmLib.}
   
+  proc boehmGetHeapSize: int {.importc: "GC_get_heap_size", dynlib: boehmLib.}
+    ## Return the number of bytes in the heap.  Excludes collector private
+    ## data structures. Includes empty blocks and fragmentation loss.
+    ## Includes some pages that were allocated but never written.
+
+  proc boehmGetFreeBytes: int {.importc: "GC_get_free_bytes", dynlib: boehmLib.}
+    ## Return a lower bound on the number of free bytes in the heap.
+
+  proc boehmGetBytesSinceGC: int {.importc: "GC_get_bytes_since_gc",
+    dynlib: boehmLib.}
+    ## Return the number of bytes allocated since the last collection.
+
+  proc boehmGetTotalBytes: int {.importc: "GC_get_total_bytes",
+    dynlib: boehmLib.}
+    ## Return the total number of bytes allocated in this process.
+    ## Never decreases.
+
   when not defined(useNimRtl):
     
     proc alloc(size: int): pointer =
@@ -91,6 +108,10 @@ when defined(boehmgc):
       result = boehmRealloc(p, newsize)
       if result == nil: raiseOutOfMem()
     proc dealloc(p: Pointer) = boehmDealloc(p)
+    
+    proc allocAtomic(size: int): pointer =
+      result = boehmAllocAtomic(size)
+      zeroMem(result, size)
 
     proc allocShared(size: int): pointer =
       result = boehmAlloc(size)
@@ -113,9 +134,9 @@ when defined(boehmgc):
     proc GC_disableMarkAndSweep() = nil
     proc GC_getStatistics(): string = return ""
     
-    proc getOccupiedMem(): int = return -1
-    proc getFreeMem(): int = return -1
-    proc getTotalMem(): int = return -1
+    proc getOccupiedMem(): int = return boehmGetHeapSize()-boehmGetFreeBytes()
+    proc getFreeMem(): int = return boehmGetFreeBytes()
+    proc getTotalMem(): int = return boehmGetHeapSize()
 
     proc setStackBottom(theStackBottom: pointer) = nil
 
@@ -123,7 +144,8 @@ when defined(boehmgc):
     when defined(macosx): boehmGCinit()
 
   proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
-    result = alloc(size)
+    if ntfNoRefs in typ.flags: result = allocAtomic(size)
+    else: result = alloc(size)
   proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
     result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
     cast[PGenericSeq](result).len = len