Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Memory-allocation/Nim/memory-allocation.nim
Normal file
18
Task/Memory-allocation/Nim/memory-allocation.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Allocate thread local heap memory
|
||||
var a = alloc(1000)
|
||||
dealloc(a)
|
||||
|
||||
# Allocate memory block on shared heap
|
||||
var b = allocShared(1000)
|
||||
deallocShared(b)
|
||||
|
||||
# Allocate and Dellocate a single int on the thread local heap
|
||||
var p = create(int, sizeof(int)) # allocate memory
|
||||
# create zeroes memory; createU does not.
|
||||
echo p[] # 0
|
||||
p[] = 123 # assign a value
|
||||
echo p[] # 123
|
||||
discard resize(p, 0) # deallocate it
|
||||
# p is now invalid. Let's set it to nil
|
||||
p = nil # set pointer to nil
|
||||
echo isNil(p) # true
|
||||
Loading…
Add table
Add a link
Reference in a new issue