OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

malloc.h
1 /* Prototypes and definition for malloc implementation.
2 Copyright (C) 1996,97,99,2000,2002,2003,2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20 #ifndef _MALLOC_H
21 #define _MALLOC_H 1
22
23 /* add the opal config header file for the OPAL_DECLSPEC */
24 #include "opal_config.h"
25
26
27 #ifdef _LIBC
28 #include <features.h>
29 #endif
30
31 /*
32 $Id: malloc.h,v 1.7 2004/08/08 12:34:57 wg Exp $
33 `ptmalloc2', a malloc implementation for multiple threads without
34 lock contention, by Wolfram Gloger <wg@malloc.de>.
35
36 VERSION 2.7.0
37
38 This work is mainly derived from malloc-2.7.0 by Doug Lea
39 <dl@cs.oswego.edu>, which is available from:
40
41 ftp://gee.cs.oswego.edu/pub/misc/malloc.c
42
43 This trimmed-down header file only provides function prototypes and
44 the exported data structures. For more detailed function
45 descriptions and compile-time options, see the source file
46 `malloc.c'.
47 */
48
49 #if defined(__STDC__) || defined (__cplusplus)
50 # include <stddef.h>
51 # define __malloc_ptr_t void *
52 #else
53 # undef size_t
54 # define size_t unsigned int
55 # undef ptrdiff_t
56 # define ptrdiff_t int
57 # define __malloc_ptr_t char *
58 #endif
59
60 #ifdef _LIBC
61 /* Used by GNU libc internals. */
62 # define __malloc_size_t size_t
63 # define __malloc_ptrdiff_t ptrdiff_t
64 #elif !defined __attribute_malloc__
65 # define __attribute_malloc__
66 #endif
67
68 #ifdef __GNUC__
69
70 /* GCC can always grok prototypes. For C++ programs we add throw()
71 to help it optimize the function calls. But this works only with
72 gcc 2.8.x and egcs. */
73 # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
74 # define __THROW throw ()
75 # else
76 #ifdef __THROW
77 # undef __THROW
78 #endif
79 # define __THROW
80 # endif
81 # define __MALLOC_P(args) args __THROW
82 /* This macro will be used for functions which might take C++ callback
83 functions. */
84 # define __MALLOC_PMT(args) args
85
86 #else /* Not GCC. */
87
88 # define __THROW
89
90 # if (defined __STDC__ && __STDC__) || defined __cplusplus
91
92 # define __MALLOC_P(args) args
93 # define __MALLOC_PMT(args) args
94
95 # ifndef __const
96 # define __const const
97 # endif
98
99 # else /* Not ANSI C or C++. */
100
101 # define __MALLOC_P(args) () /* No prototypes. */
102 # define __MALLOC_PMT(args) ()
103
104 # ifndef __const
105 # define __const
106 # endif
107
108 # endif /* ANSI C or C++. */
109
110 #endif /* GCC. */
111
112 #ifndef NULL
113 # ifdef __cplusplus
114 # define NULL 0
115 # else
116 # define NULL ((__malloc_ptr_t) 0)
117 # endif
118 #endif
119
120 #ifdef __cplusplus
121 extern "C" {
122 #endif
123
124 /* Nonzero if the malloc is already initialized. */
125 #ifdef _LIBC
126 /* In the GNU libc we rename the global variable
127 `__malloc_initialized' to `__libc_malloc_initialized'. */
128 # define __malloc_initialized __libc_malloc_initialized
129 #endif
130 extern int __malloc_initialized;
131
132 /* Allocate SIZE bytes of memory. */
133 OPAL_DECLSPEC extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
134
135 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
136 OPAL_DECLSPEC extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
137 __attribute_malloc__;
138
139 /* Re-allocate the previously allocated block in __ptr, making the new
140 block SIZE bytes long. */
141 OPAL_DECLSPEC extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
142 size_t __size))
143 __attribute_malloc__;
144
145 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
146 OPAL_DECLSPEC extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
147
148 /* Free a block allocated by `calloc'. */
149 OPAL_DECLSPEC extern void cfree __MALLOC_P ((__malloc_ptr_t __ptr));
150
151 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
152 OPAL_DECLSPEC extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
153
154 /* Allocate SIZE bytes on a page boundary. */
155 OPAL_DECLSPEC extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
156
157 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
158 __size to nearest pagesize. */
159 OPAL_DECLSPEC extern __malloc_ptr_t pvalloc __MALLOC_P ((size_t __size))
160 __attribute_malloc__;
161
162 /* Underlying allocation function; successive calls should return
163 contiguous pieces of memory. */
164 OPAL_DECLSPEC extern __malloc_ptr_t (*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
165
166 /* Default value of `__morecore'. */
167 OPAL_DECLSPEC extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size))
168 __attribute_malloc__;
169
170 /* SVID2/XPG mallinfo structure */
171
172 struct mallinfo {
173 int arena; /* non-mmapped space allocated from system */
174 int ordblks; /* number of free chunks */
175 int smblks; /* number of fastbin blocks */
176 int hblks; /* number of mmapped regions */
177 int hblkhd; /* space in mmapped regions */
178 int usmblks; /* maximum total allocated space */
179 int fsmblks; /* space available in freed fastbin blocks */
180 int uordblks; /* total allocated space */
181 int fordblks; /* total free space */
182 int keepcost; /* top-most, releasable (via malloc_trim) space */
183 };
184
185 /* Returns a copy of the updated current mallinfo. */
186 OPAL_DECLSPEC extern struct mallinfo mallinfo __MALLOC_P ((void));
187
188 /* SVID2/XPG mallopt options */
189 #ifndef M_MXFAST
190 # define M_MXFAST 1 /* maximum request size for "fastbins" */
191 #endif
192 #ifndef M_NLBLKS
193 # define M_NLBLKS 2 /* UNUSED in this malloc */
194 #endif
195 #ifndef M_GRAIN
196 # define M_GRAIN 3 /* UNUSED in this malloc */
197 #endif
198 #ifndef M_KEEP
199 # define M_KEEP 4 /* UNUSED in this malloc */
200 #endif
201
202 /* mallopt options that actually do something */
203 #define M_TRIM_THRESHOLD -1
204 #define M_TOP_PAD -2
205 #define M_MMAP_THRESHOLD -3
206 #define M_MMAP_MAX -4
207 #define M_CHECK_ACTION -5
208
209 /* General SVID/XPG interface to tunable parameters. */
210 OPAL_DECLSPEC extern int mallopt __MALLOC_P ((int __param, int __val));
211
212 /* Release all but __pad bytes of freed top-most memory back to the
213 system. Return 1 if successful, else 0. */
214 OPAL_DECLSPEC extern int malloc_trim __MALLOC_P ((size_t __pad));
215
216 /* Report the number of usable allocated bytes associated with allocated
217 chunk __ptr. */
218 OPAL_DECLSPEC extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
219
220 /* Prints brief summary statistics on stderr. */
221 OPAL_DECLSPEC extern void malloc_stats __MALLOC_P ((void));
222
223 /* Record the state of all malloc variables in an opaque data structure. */
224 OPAL_DECLSPEC extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
225
226 /* Restore the state of all malloc variables from data obtained with
227 malloc_get_state(). */
228 OPAL_DECLSPEC extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
229
230 /* Called once when malloc is initialized; redefining this variable in
231 the application provides the preferred way to set up the hook
232 pointers. */
233 OPAL_DECLSPEC extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
234 /* Hooks for debugging and user-defined versions. */
235 OPAL_DECLSPEC extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
236 __const __malloc_ptr_t));
237 OPAL_DECLSPEC extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
238 __const __malloc_ptr_t));
239 OPAL_DECLSPEC extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
240 size_t __size,
241 __const __malloc_ptr_t));
242 OPAL_DECLSPEC extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
243 size_t __size,
244 __const __malloc_ptr_t));
245 OPAL_DECLSPEC extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
246
247 /* Activate a standard set of debugging hooks. */
248 OPAL_DECLSPEC extern void __malloc_check_init __MALLOC_P ((void));
249
250 /* Internal routines, operating on "arenas". */
251 struct malloc_state;
252 typedef struct malloc_state *mstate;
253
254 OPAL_DECLSPEC extern mstate _int_new_arena __MALLOC_P ((size_t __ini_size));
255 OPAL_DECLSPEC extern __malloc_ptr_t _int_malloc __MALLOC_P ((mstate __m, size_t __size));
256 OPAL_DECLSPEC extern void _int_free __MALLOC_P ((mstate __m, __malloc_ptr_t __ptr));
257 OPAL_DECLSPEC extern __malloc_ptr_t _int_realloc __MALLOC_P ((mstate __m,
258 __malloc_ptr_t __ptr,
259 size_t __size));
260 OPAL_DECLSPEC extern __malloc_ptr_t _int_memalign __MALLOC_P ((mstate __m, size_t __alignment,
261 size_t __size));
262 /* Return arena number __n, or 0 if out of bounds. Arena 0 is the
263 main arena. */
264 OPAL_DECLSPEC extern mstate _int_get_arena __MALLOC_P ((int __n));
265
266 /* Implementation-specific mallinfo. More detailed than mallinfo, and
267 also works for size_t wider than int. */
268 struct malloc_arena_info {
269 int nfastblocks; /* number of freed "fastchunks" */
270 int nbinblocks; /* number of available chunks in bins */
271 size_t fastavail; /* total space in freed "fastchunks" */
272 size_t binavail; /* total space in binned chunks */
273 size_t top_size; /* size of top chunk */
274 size_t system_mem; /* bytes allocated from system in this arena */
275 size_t max_system_mem; /* max. bytes allocated from system */
276 /* Statistics for locking. Only kept if THREAD_STATS is defined
277 at compile time. */
278 long stat_lock_direct, stat_lock_loop, stat_lock_wait;
279 };
280
281 struct malloc_global_info {
282 int n_mmaps; /* number of mmap'ed chunks */
283 int max_n_mmaps; /* max. number of mmap'ed chunks reached */
284 size_t mmapped_mem; /* total bytes allocated in mmap'ed chunks */
285 size_t max_mmapped_mem; /* max. bytes allocated in mmap'ed chunks */
286 size_t max_total_mem; /* only kept for NO_THREADS */
287 int stat_n_heaps; /* only kept if THREAD_STATS is defined */
288 };
289
290 OPAL_DECLSPEC extern void _int_get_arena_info __MALLOC_P ((mstate __m,
291 struct malloc_arena_info *__ma));
292 OPAL_DECLSPEC extern void _int_get_global_info __MALLOC_P ((struct malloc_global_info *__m));
293
294 OPAL_DECLSPEC extern int posix_memalign (void **memptr, size_t alignment, size_t size);
295
296 #ifdef __cplusplus
297 } /* end of extern "C" */
298 #endif
299
300 #endif /* malloc.h */
malloc_arena_info
Definition: malloc.h:268
malloc_global_info
Definition: malloc.h:281
malloc_state
Definition: malloc.c:2259
mallinfo
Definition: malloc.h:172