1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE cref SYSTEM "cref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
26
<title>erl_malloc</title>
27
<prepared>Torbjörn Törnkvist</prepared>
28
<responsible>Torbjörn Törnkvist</responsible>
30
<approved>Bjarne Däcker</approved>
31
<checked>Torbjörn Törnkvist</checked>
34
<file>erl_malloc.sgml</file>
37
<libsummary>Memory Allocation Functions</libsummary>
39
<p>This module provides functions for allocating and deallocating
44
<name><ret>ETERM *</ret><nametext>erl_alloc_eterm(etype)</nametext></name>
45
<fsummary>Allocates an ETERM structure</fsummary>
47
<v>unsigned char etype;</v>
50
<p>This function allocates an <c><![CDATA[(ETERM)]]></c> structure.
51
Specify <c><![CDATA[etype]]></c> as one of the following constants:</p>
52
<list type="bulleted">
57
<p>ERL_U_INTEGER <c><![CDATA[/* unsigned integer */]]></c></p>
63
<p>ERL_PID <c><![CDATA[/* Erlang process identifier */]]></c></p>
69
<p>ERL_REF <c><![CDATA[/* Erlang reference */]]></c></p>
90
<p>ERL_SMALL_BIG <c><![CDATA[/* bignum */]]></c></p>
93
<p>ERL_U_SMALL_BIG <c><![CDATA[/* bignum */]]></c></p>
96
<p><c><![CDATA[ERL_SMALL_BIG]]></c> and <c><![CDATA[ERL_U_SMALL_BIG]]></c> are for
97
creating Erlang <c><![CDATA[bignums]]></c>, which can contain integers of
98
arbitrary size. The size of an integer in Erlang is machine
99
dependent, but in general any integer larger than 2^28
100
requires a bignum.</p>
104
<name><ret>void</ret><nametext>erl_eterm_release(void)</nametext></name>
105
<fsummary>Clears the ETERM freelist</fsummary>
108
freelist, where blocks are placed when they are
109
released by <c><![CDATA[erl_free_term()]]></c> and
110
<c><![CDATA[erl_free_compound()]]></c>. </p>
114
<name><ret>void</ret><nametext>erl_eterm_statistics(allocated, freed)</nametext></name>
115
<fsummary>Reports term allocation statistics</fsummary>
117
<v>long *allocated;</v>
121
<p><c><![CDATA[allocated]]></c> and <c><![CDATA[freed]]></c> are initialized to
122
contain information about the fix-allocator used to allocate
123
ETERM components. <c><![CDATA[allocated]]></c> is the number of blocks
124
currently allocated to ETERM objects. <c><![CDATA[freed]]></c> is the
125
length of the freelist, where blocks are placed when they are
126
released by <c><![CDATA[erl_free_term()]]></c> and
127
<c><![CDATA[erl_free_compound()]]></c>. </p>
131
<name><ret>void</ret><nametext>erl_free_array(array, size)</nametext></name>
132
<fsummary>Frees an array of ETERM structures</fsummary>
134
<v>ETERM **array;</v>
138
<p>This function frees an array of Erlang terms.</p>
139
<p><c><![CDATA[array]]></c> is an array of ETERM* objects.
141
<p><c><![CDATA[size]]></c> is the number of terms in the array.</p>
145
<name><ret>void</ret><nametext>erl_free_term(t)</nametext></name>
146
<fsummary>Frees an ETERM structure</fsummary>
151
<p>Use this function to free an Erlang term.</p>
155
<name><ret>void</ret><nametext>erl_free_compound(t)</nametext></name>
156
<fsummary>Frees an array of ETERM structures</fsummary>
161
<p>Normally it is the programmer's responsibility to free each
162
Erlang term that has been returned from any of the
163
<c><![CDATA[erl_interface]]></c> functions. However since many of the
164
functions that build new Erlang terms in fact share objects
165
with other existing terms, it may be difficult for the
166
programmer to maintain pointers to all such terms in order to
167
free them individually.
169
<p><c><![CDATA[erl_free_compound()]]></c> will recursively free all of the
170
sub-terms associated with a given Erlang term, regardless of
171
whether we are still holding pointers to the sub-terms.
173
<p>There is an example in the User Manual under "Building
179
<name><ret>void</ret><nametext>erl_malloc(size)</nametext></name>
180
<fsummary>Allocates some memory</fsummary>
185
<p>This function calls the standard
186
<c><![CDATA[malloc()]]></c> function. </p>
190
<name><ret>void</ret><nametext>erl_free(ptr)</nametext></name>
191
<fsummary>Frees some memory</fsummary>
196
<p>This function calls the standard
197
<c><![CDATA[free()]]></c> function. </p>