File: erl_malloc.3

package info (click to toggle)
erlang-manpages 1%3A12.b.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,188 kB
  • ctags: 2
  • sloc: makefile: 68; perl: 30; sh: 15
file content (172 lines) | stat: -rw-r--r-- 3,146 bytes parent folder | download
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
.TH erl_malloc 3 "erl_interface  3.5.7" "Ericsson AB" "C LIBRARY FUNCTIONS"
.SH NAME
erl_malloc \- Memory Allocation Functions
.SH DESCRIPTION
.LP
This module provides functions for allocating and deallocating memory\&.

.SH EXPORTS
.LP
.B
ETERM * erl_alloc_eterm(etype)
.br
.RS
.TP
Types
unsigned char etype;
.br
.RE
.RS
.LP
This function allocates an \fI(ETERM)\fR structure\&. Specify \fIetype\fR as one of the following constants:
.RS 2
.TP 2
*
ERL_INTEGER
.TP 2
*
ERL_U_INTEGER \fI/* unsigned integer */\fR
.TP 2
*
ERL_ATOM
.TP 2
*
ERL_PID \fI/* Erlang process identifier */\fR
.TP 2
*
ERL_PORT
.TP 2
*
ERL_REF \fI/* Erlang reference */\fR
.TP 2
*
ERL_LIST
.TP 2
*
ERL_EMPTY_LIST
.TP 2
*
ERL_TUPLE
.TP 2
*
ERL_BINARY
.TP 2
*
ERL_FLOAT
.TP 2
*
ERL_VARIABLE
.TP 2
*
ERL_SMALL_BIG \fI/* bignum */\fR
.TP 2
*
ERL_U_SMALL_BIG \fI/* bignum */\fR
.RE
.LP
\fIERL_SMALL_BIG\fR and \fIERL_U_SMALL_BIG\fR are for creating Erlang \fIbignums\fR, which can contain integers of arbitrary size\&. The size of an integer in Erlang is machine dependent, but in general any integer larger than 2^28 requires a bignum\&.
.RE
.LP
.B
void erl_eterm_release(void)
.br
.RS
.LP
Clears the freelist, where blocks are placed when they are released by \fIerl_free_term()\fR and \fIerl_free_compound()\fR\&. 
.RE
.LP
.B
void erl_eterm_statistics(allocated, freed)
.br
.RS
.TP
Types
long *allocated;
.br
long *freed;
.br
.RE
.RS
.LP
\fIallocated\fR and \fIfreed\fR are initialized to contain information about the fix-allocator used to allocate ETERM components\&. \fIallocated\fR is the number of blocks currently allocated to ETERM objects\&. \fIfreed\fR is the length of the freelist, where blocks are placed when they are released by \fIerl_free_term()\fR and \fIerl_free_compound()\fR\&. 
.RE
.LP
.B
void erl_free_array(array, size)
.br
.RS
.TP
Types
ETERM **array;
.br
int size;
.br
.RE
.RS
.LP
This function frees an array of Erlang terms\&.
.LP
\fIarray\fR is an array of ETERM* objects\&. 
.LP
\fIsize\fR is the number of terms in the array\&.
.RE
.LP
.B
void erl_free_term(t)
.br
.RS
.TP
Types
ETERM *t;
.br
.RE
.RS
.LP
Use this function to free an Erlang term\&.
.RE
.LP
.B
void erl_free_compound(t)
.br
.RS
.TP
Types
ETERM *t;
.br
.RE
.RS
.LP
Normally it is the programmer\&'s responsibility to free each Erlang term that has been returned from any of the \fIerl_interface\fR functions\&. However since many of the functions that build new Erlang terms in fact share objects with other existing terms, it may be difficult for the programmer to maintain pointers to all such terms in order to free them individually\&. 
.LP
\fIerl_free_compound()\fR will recursively free all of the sub-terms associated with a given Erlang term, regardless of whether we are still holding pointers to the sub-terms\&. 
.LP
There is an example in the User Manual under "Building Terms and Patterns" 
.RE
.LP
.B
void erl_malloc(size)
.br
.RS
.TP
Types
long size;
.br
.RE
.RS
.LP
This function calls the standard \fImalloc()\fR function\&. 
.RE
.LP
.B
void erl_free(ptr)
.br
.RS
.TP
Types
void *ptr;
.br
.RE
.RS
.LP
This function calls the standard \fIfree()\fR function\&. 
.RE