Skip to content

Commit

Permalink
take the one good idea from --os:standalone and enable it via -d:Stan…
Browse files Browse the repository at this point in the history
…daloneHeapSize (#13077)
  • Loading branch information
Araq authored Jan 9, 2020
1 parent 27fee4d commit 852170c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/system/mmdisp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const

proc raiseOutOfMem() {.noinline.} =
if outOfMemHook != nil: outOfMemHook()
cstderr.rawWrite("out of memory")
cstderr.rawWrite("out of memory\n")
quit(1)

when defined(boehmgc):
Expand Down
14 changes: 7 additions & 7 deletions lib/system/osalloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const doNotUnmap = not (defined(amd64) or defined(i386)) or
defined(windows) or defined(nimAllocNoUnmap)


when defined(emscripten):
when defined(emscripten) and not defined(StandaloneHeapSize):
const
PROT_READ = 1 # page can be read
PROT_WRITE = 2 # page can be written
Expand Down Expand Up @@ -77,10 +77,10 @@ when defined(emscripten):
var mmapDescr = cast[EmscriptenMMapBlock](mmapDescrPos)
munmap(mmapDescr.realPointer, mmapDescr.realSize)

elif defined(genode):
elif defined(genode) and not defined(StandaloneHeapSize):
include genode/alloc # osAllocPages, osTryAllocPages, osDeallocPages

elif defined(nintendoswitch):
elif defined(nintendoswitch) and not defined(StandaloneHeapSize):

import nintendoswitch/switch_memory

Expand Down Expand Up @@ -191,7 +191,7 @@ elif defined(nintendoswitch):
when reallyOsDealloc:
freeMem(p)

elif defined(posix):
elif defined(posix) and not defined(StandaloneHeapSize):
const
PROT_READ = 1 # page can be read
PROT_WRITE = 2 # page can be written
Expand Down Expand Up @@ -234,7 +234,7 @@ elif defined(posix):
proc osDeallocPages(p: pointer, size: int) {.inline.} =
when reallyOsDealloc: discard munmap(p, cast[csize_t](size))

elif defined(windows):
elif defined(windows) and not defined(StandaloneHeapSize):
const
MEM_RESERVE = 0x2000
MEM_COMMIT = 0x1000
Expand Down Expand Up @@ -274,10 +274,10 @@ elif defined(windows):
quit 1
#VirtualFree(p, size, MEM_DECOMMIT)

elif hostOS == "standalone":
elif hostOS == "standalone" or defined(StandaloneHeapSize):
const StandaloneHeapSize {.intdefine.}: int = 1024 * PageSize
var
theHeap: array[StandaloneHeapSize, float64] # 'float64' for alignment
theHeap: array[StandaloneHeapSize div sizeof(float64), float64] # 'float64' for alignment
bumpPointer = cast[int](addr theHeap)

proc osAllocPages(size: int): pointer {.inline.} =
Expand Down

0 comments on commit 852170c

Please sign in to comment.