aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/doc/src/erl_malloc.xml
blob: c0eebc29e977bbb6d15c61b29e0a39202962f01b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cref SYSTEM "cref.dtd">

<cref>
  <header>
    <copyright>
      <year>1996</year><year>2016</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>

    <title>erl_malloc</title>
    <prepared>Torbj&ouml;rn T&ouml;rnkvist</prepared>
    <responsible>Torbj&ouml;rn T&ouml;rnkvist</responsible>
    <docno></docno>
    <approved>Bjarne D&auml;cker</approved>
    <checked>Torbj&ouml;rn T&ouml;rnkvist</checked>
    <date>1998-07-03</date>
    <rev>A</rev>
    <file>erl_malloc.xml</file>
  </header>
  <lib>erl_malloc</lib>
  <libsummary>Memory allocation functions.</libsummary>
  <description>
    <p>This module provides functions for allocating and deallocating
      memory.</p>
  </description>

  <funcs>
    <func>
      <name><ret>ETERM *</ret><nametext>erl_alloc_eterm(etype)</nametext></name>
      <fsummary>Allocate an ETERM structure.</fsummary>
      <type>
        <v>unsigned char etype;</v>
      </type>
      <desc>
        <p>Allocates an <c>(ETERM)</c> structure.</p>
        <p>Specify <c>etype</c> as one of the following
          constants:</p>
        <list type="bulleted">
          <item><c>ERL_INTEGER</c>
          </item>
          <item><c>ERL_U_INTEGER</c> (unsigned integer)
          </item>
          <item><c>ERL_ATOM</c>
          </item>
          <item><c>ERL_PID</c> (Erlang process identifier)
          </item>
          <item><c>ERL_PORT</c>
          </item>
          <item><c>ERL_REF</c> (Erlang reference)
          </item>
          <item><c>ERL_LIST</c>
          </item>
          <item><c>ERL_EMPTY_LIST</c>
          </item>
          <item><c>ERL_TUPLE</c>
          </item>
          <item><c>ERL_BINARY</c>
          </item>
          <item><c>ERL_FLOAT</c>
          </item>
          <item><c>ERL_VARIABLE</c>
          </item>
          <item><c>ERL_SMALL_BIG</c> (bignum)
          </item>
          <item><c>ERL_U_SMALL_BIG</c> (bignum)
          </item>
        </list>
        <p><c>ERL_SMALL_BIG</c> and
          <c>ERL_U_SMALL_BIG</c> are for
          creating Erlang <c>bignums</c>, which can contain integers
          of any size. The size of an integer in Erlang is machine-dependent,
          but any integer &gt; 2^28 requires a bignum.</p>
      </desc>
    </func>

    <func>
      <name><ret>void</ret><nametext>erl_eterm_release(void)</nametext></name>
      <fsummary>Clear the ETERM freelist.</fsummary>
      <desc>
        <p>Clears the freelist, where blocks are placed when they are
          released by <c>erl_free_term()</c> and
          <c>erl_free_compound()</c>.</p>
      </desc>
    </func>

    <func>
      <name><ret>void</ret><nametext>erl_eterm_statistics(allocated, freed)</nametext></name>
      <fsummary>Report term allocation statistics.</fsummary>
      <type>
        <v>long *allocated;</v>
        <v>long *freed;</v>
      </type>
      <desc>
        <p>Reports term allocation statistics.</p>
        <p><c>allocated</c> and <c>freed</c> are
          initialized to
          contain information about the fix-allocator used to allocate
          <c>ETERM</c> components.</p>
        <list type="bulleted">
          <item>
            <p><c>allocated</c> is the number of blocks currently
              allocated to <c>ETERM</c> objects.</p>
          </item>
          <item>
            <p><c>freed</c> is the length of the freelist, where
              blocks are placed when they are
              released by <c>erl_free_term()</c> and
              <c>erl_free_compound()</c>.</p>
          </item>
        </list>
      </desc>
    </func>

    <func>
      <name><ret>void</ret><nametext>erl_free(ptr)</nametext></name>
      <fsummary>Free some memory.</fsummary>
      <type>
        <v>void *ptr;</v>
      </type>
      <desc>
        <p>Calls the standard
          <c>free()</c> function.</p>
      </desc>
    </func>

    <func>
      <name><ret>void</ret><nametext>erl_free_array(array, size)</nametext></name>
      <fsummary>Free an array of ETERM structures.</fsummary>
      <type>
        <v>ETERM **array;</v>
        <v>int size;</v>
      </type>
      <desc>
        <p>Frees an array of Erlang terms.</p>
        <list type="bulleted">
          <item><c>array</c> is an array of ETERM* objects.</item>
          <item><c>size</c> is the number of terms in the array.
          </item>
        </list>
      </desc>
    </func>

    <func>
      <name><ret>void</ret><nametext>erl_free_compound(t)</nametext></name>
      <fsummary>Free an array of ETERM structures.</fsummary>
      <type>
        <v>ETERM *t;</v>
      </type>
      <desc>
        <p>Normally it is the programmer's responsibility to free each
          Erlang term that has been returned from any of the
          <c>Erl_Interface</c> functions. However, as many of the
          functions that build new Erlang terms in fact share objects
          with other existing terms, it can be difficult for the
          programmer to maintain pointers to all such terms to
          free them individually.</p>
        <p><c>erl_free_compound()</c> recursively frees all of the
          subterms associated with a specified Erlang term, regardless of
          whether we are still holding pointers to the subterms.</p>
        <p>For an example, see section
            <seealso marker="ei_users_guide#building_terms_and_patterns">Building Terms and Patterns</seealso>
            in the User's Guide.</p>
      </desc>
    </func>

    <func>
      <name><ret>void</ret><nametext>erl_free_term(t)</nametext></name>
      <fsummary>Free an ETERM structure.</fsummary>
      <type>
        <v>ETERM *t;</v>
      </type>
      <desc>
        <p>Frees an Erlang term.</p>
      </desc>
    </func>

    <func>
      <name><ret>void</ret><nametext>erl_malloc(size)</nametext></name>
      <fsummary>Allocate some memory.</fsummary>
      <type>
        <v>long size;</v>
      </type>
      <desc>
        <p>Calls the standard
          <c>malloc()</c> function.</p>
      </desc>
    </func>
  </funcs>
</cref>