Mirror of
forum.nim-lang.org
index
11106 :: What will happen if allocation fails?
[2024-02-28T03:23:33+01:00]
View Orginal
sls1005
(orginal)
[2024-02-28T03:23:33+01:00]
view original
It's well-known that a (heap memory) allocation can fail if the system has run out of memory and has no swap space available. So, what will happen if a call to
new
or
alloc
fails to do so?
PMunch
(orginal)
[2024-02-28T05:16:54+01:00]
view original
A
MemoryDefect
or a panic I'd imagine
Araq
(orginal)
[2024-02-28T09:30:53+01:00]
view original
OutOfMemDefect
is raised. There is also
system.outOfMemHook
that you can set.
sls1005
(orginal)
[2024-02-28T17:03:57+01:00]
view original
So a
ref
returned by
new
, or a
ptr
returned by
alloc
(or
allocShared
, or
create
, or similar), is never
nil
?
Araq
(orginal)
[2024-02-28T21:53:52+01:00]
view original
Correct.