Skip to content

Instantly share code, notes, and snippets.

@izackp
Last active November 25, 2021 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izackp/107a8f733c686276d396e30f65249d7c to your computer and use it in GitHub Desktop.
Save izackp/107a8f733c686276d396e30f65249d7c to your computer and use it in GitHub Desktop.
Nim OOM Tests
type
FatArray = array[50_000_000, uint8]
FatArrayRef = ref FatArray
var container: array[50_000_000, FatArrayRef]
var i = 0
while true:
try:
# Will eventually return nil
var x:FatArrayRef = new FatArray
container[i] = x
i += 1
echo i
except:
echo getCurrentExceptionMsg()
let ose = getCurrentException()
echo ose.name
break
type
FatArray = array[50_000, uint8]
var container = newSeq[FatArray](1)
var i = 0
while true:
try:
#Will eventually hang
var x:FatArray
x[0]=5
container.add(x)
i += 1
echo i
except:
echo getCurrentExceptionMsg()
let ose = getCurrentException()
echo ose.name
break
type
FatArray = array[50_000_000, uint8]
# Doesn't compile needs a const size
proc fatStack(size:int) =
var container: array[size, FatArray]
var i = 0
try:
var x:FatArray
container[i] = x
i += 1
except:
echo getCurrentExceptionMsg()
let ose = getCurrentException()
echo ose.name
var size = 1
while true:
try:
fatStack(size)
size += 1
echo size
except:
echo getCurrentExceptionMsg()
let ose = getCurrentException()
echo ose.name
break
# From within newSeq:
# SIGSEGV: Illegal storage access. (Attempt to read from nil?)
var container = newSeq[uint64](50_000_000*50_000_000)
container[0] = 5
# Linker Error: ARM64 ADRP out of range (20000000024576 max is +/-4GB): from _main (0x100006F20) to _gEnv (0x12319CE606F0) in '_main' from @moomStackSafe.nim.cpp.o for architecture arm64
var container: array[50_000*50_000_000, uint64]
container[0] = 5
# Program terminates with error code 1 after 2 iterations
proc fatStack(depth:int) =
var fatty:array[500_000, uint64]
try:
fatty[0] = 1
echo depth
if (depth > 0):
fatStack(depth + 1)
except:
echo getCurrentExceptionMsg()
let ose = getCurrentException()
echo ose.name
fatStack(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment