Memory allocation: Difference between revisions

Memory allocation en FreeBASIC
(Memory allocation en FreeBASIC)
Line 690:
deallocate(ptr) ! Deallocate a pointer
end program allocation_test</lang>
 
 
=={{header|FreeBASIC}}==
{{trans|BBC BASIC}}
===Heap===
<lang freebasic>Dim As Integer size = 12345
Dim As Integer mem = size-1
Print size; " bytes of heap allocated at " ; mem
Clear (mem, , 10)
Print size; " bytes of heap allocated at " ; mem</lang>
Memory allocated from the heap is only freed on program termination or CLEAR
 
===Stack===
<lang freebasic>Dim As Integer size = 12345
Dim As Integer mem = size-1
 
Sub Stack(s As Integer)
Dim As Integer mem = s-1
Print s; " bytes of stack allocated at " ; mem
End Sub
 
Stack(size)
Print size; " bytes of stack allocated at " ; mem</lang>
Memory allocated from the stack is freed on exit from the Sub/Function
 
 
=={{header|Go}}==
2,130

edits