Memory allocation: Difference between revisions
Content added Content deleted
m ({{omit from|GUISS}}) |
|||
Line 660: | Line 660: | ||
<lang rexx>drop xyz NamesRoster j k m caves names.</lang> |
<lang rexx>drop xyz NamesRoster j k m caves names.</lang> |
||
=={{header|SNOBOL4}}== |
|||
In SNOBOL4, simple data values are just created and assigned to variables. Here, three separate strings are concatenated and stored as a newly allocated string variable: |
|||
<lang snobol4> newstring = "This is creating and saving" " a new single string " "starting with three separate strings."</lang> |
|||
Empty arrays are created by using the built-in function (the size is determined when it is created): |
|||
<lang snobol4> newarray = array(100)</lang> |
|||
Empty tables are similarly created using the built-in function (new entries can be simply added at any later time by just storing them into the table): |
|||
<lang snobol4> newtable = table()</lang> |
|||
User-defined datatypes (usually, multi-field structures) are defined using the data() built-in function (which creates the constructor and field access functions): |
|||
<lang snobol4> data("listnode(next,prev,datafield1,datafield2)")</lang> |
|||
Then you allocate a new example of the defined listnode data item by using the constructor the data() function created: |
|||
<lang snobol4> newnode = listnode(,,"string data value1",17)</lang> |
|||
The example thus created can be updated using the field access functions also created by the data() function: |
|||
<lang snobol4> datafield1(newnode) = "updated data value 1"</lang> |
|||
You don't need to explicitly de-allocate memory. When you leave a function which has declared local variables, data stored in those local variables is released upon return. You can also just store a null string into a variable, releasing the value that was stored in that variable previously: |
|||
<lang snobol4> newnode = </lang> |
|||
SNOBOL4 automatically garbage collects released data items on an as-needed basis, and moves allocated items to consolidate all released space (so memory fragmentation is never a problem). You can explicitly garbage collect if you really want to: |
|||
<lang snobol4> collect() |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |