Memory allocation: Difference between revisions

Added COBOL section. Corrected R lang tag.
(Added Erlang)
(Added COBOL section. Corrected R lang tag.)
Line 318:
operator delete(p, whatever); // explicitly deallocate the memory
}</lang>
 
=={{header|COBOL}}==
In some implementations, programs with the <code>INITIAL</code> clause will have data in the <code>WORKING-STORAGE SECTION</code> stored on the stack. However, the COBOL standard does not specify where the data in a program should be stored.
 
Manual memory allocation is primarily done using <code>ALLOCATE</code> and <code>FREE</code>. They are used with data items with a <code>BASED</code> clause, which indicates that the data will be allocated at runtime. A <code>BASED</code> data item cannot be used before it has been allocated or after it has been freed. Example usage:
<lang cobol> PROGRAM-ID. memory-allocation.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 based-data PIC X(20) VALUE "Hello, World!"
BASED.
 
PROCEDURE DIVISION.
*> INITIALIZED sets the data item to the VALUE.
ALLOCATE based-data INITIALIZED
DISPLAY based-data
FREE based-data
 
GOBACK
.</lang>
 
{{out}}
<pre>Hello, World!</pre>
 
=={{header|Common Lisp}}==
Line 968 ⟶ 991:
 
=={{header|R}}==
<lang Rrsplus>x=numeric(10) # allocate a numeric vector of size 10 to x
rm(x) # remove x
 
Anonymous user