summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-02-10 09:22:28 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-02-10 09:22:28 +0100
commit0bb18d1821183b08079e8cff03498454ff0b36f1 (patch)
treeadc3515b64c7114b270f4da2d781f4c920a8d983 /lib
parent601dc2098df48838f044fa2e68d8227a164a0fc8 (diff)
downloadNim-0bb18d1821183b08079e8cff03498454ff0b36f1.tar.gz
introduce nimMaxHeap define to fight memory overcommit
Diffstat (limited to 'lib')
-rw-r--r--lib/system/alloc.nim5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index a124d7537..f28a124d2 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -292,10 +292,15 @@ proc writeFreeList(a: MemRegion) =
               it, it.next, it.prev, it.size)
     it = it.next
 
+const nimMaxHeap {.intdefine.} = 0
+
 proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
   when not defined(emscripten):
     if not a.blockChunkSizeIncrease:
       let usedMem = a.currMem # - a.freeMem
+      when nimMaxHeap != 0:
+        if usedMem > nimMaxHeap * 1024 * 1024:
+          raiseOutOfMem()
       if usedMem < 64 * 1024:
         a.nextChunkSize = PageSize*4
       else: