Memory allocation: Difference between revisions
Content added Content deleted
(Added Erlang) |
(Added COBOL section. Corrected R lang tag.) |
||
Line 318: | Line 318: | ||
operator delete(p, whatever); // explicitly deallocate the memory |
operator delete(p, whatever); // explicitly deallocate the memory |
||
}</lang> |
}</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}}== |
=={{header|Common Lisp}}== |
||
Line 968: | Line 991: | ||
=={{header|R}}== |
=={{header|R}}== |
||
<lang |
<lang rsplus>x=numeric(10) # allocate a numeric vector of size 10 to x |
||
rm(x) # remove x |
rm(x) # remove x |
||