1 /* Prototypes and definition for malloc implementation.
2 Copyright (C) 1996,97,99,2000,2002-2004,2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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
29 `ptmalloc2', a malloc implementation for multiple threads without
30 lock contention, by Wolfram Gloger <wg@malloc.de>.
34 This work is mainly derived from malloc-2.7.0 by Doug Lea
35 <dl@cs.oswego.edu>, which is available from:
37 ftp://gee.cs.oswego.edu/pub/misc/malloc.c
39 This trimmed-down header file only provides function prototypes and
40 the exported data structures. For more detailed function
41 descriptions and compile-time options, see the source file
45 #if defined(__STDC__) || defined (__cplusplus)
47 # define __malloc_ptr_t void *
50 # define size_t unsigned int
52 # define ptrdiff_t int
53 # define __malloc_ptr_t char *
57 /* Used by GNU libc internals. */
58 # define __malloc_size_t size_t
59 # define __malloc_ptrdiff_t ptrdiff_t
60 #elif !defined __attribute_malloc__
61 # define __attribute_malloc__
66 /* GCC can always grok prototypes. For C++ programs we add throw()
67 to help it optimize the function calls. But this works only with
68 gcc 2.8.x and egcs. */
70 # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
71 # define __THROW throw ()
76 # define __MALLOC_P(args) args __THROW
77 /* This macro will be used for functions which might take C++ callback
79 # define __MALLOC_PMT(args) args
85 # if (defined __STDC__ && __STDC__) || defined __cplusplus
87 # define __MALLOC_P(args) args
88 # define __MALLOC_PMT(args) args
91 # define __const const
94 # else /* Not ANSI C or C++. */
96 # define __MALLOC_P(args) () /* No prototypes. */
97 # define __MALLOC_PMT(args) ()
103 # endif /* ANSI C or C++. */
111 # define NULL ((__malloc_ptr_t) 0)
119 /* Allocate SIZE bytes of memory. */
120 extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size))
121 __attribute_malloc__ __wur;
123 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
124 extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
125 __attribute_malloc__ __wur;
127 /* Re-allocate the previously allocated block in __ptr, making the new
128 block SIZE bytes long. */
129 extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
131 __attribute_malloc__ __attribute_warn_unused_result__;
133 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
134 extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
136 /* Free a block allocated by `calloc'. */
137 extern void cfree __MALLOC_P ((__malloc_ptr_t __ptr));
139 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
140 extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size))
141 __attribute_malloc__ __wur;
143 /* Allocate SIZE bytes on a page boundary. */
144 extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size))
145 __attribute_malloc__ __wur;
147 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
148 __size to nearest pagesize. */
149 extern __malloc_ptr_t pvalloc __MALLOC_P ((size_t __size))
150 __attribute_malloc__ __wur;
152 /* Underlying allocation function; successive calls should return
153 contiguous pieces of memory. */
154 extern __malloc_ptr_t (*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
156 /* Default value of `__morecore'. */
157 extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size))
158 __attribute_malloc__;
160 /* SVID2/XPG mallinfo structure */
163 int arena; /* non-mmapped space allocated from system */
164 int ordblks; /* number of free chunks */
165 int smblks; /* number of fastbin blocks */
166 int hblks; /* number of mmapped regions */
167 int hblkhd; /* space in mmapped regions */
168 int usmblks; /* maximum total allocated space */
169 int fsmblks; /* space available in freed fastbin blocks */
170 int uordblks; /* total allocated space */
171 int fordblks; /* total free space */
172 int keepcost; /* top-most, releasable (via malloc_trim) space */
175 /* Returns a copy of the updated current mallinfo. */
176 extern struct mallinfo mallinfo __MALLOC_P ((void));
178 /* SVID2/XPG mallopt options */
180 # define M_MXFAST 1 /* maximum request size for "fastbins" */
183 # define M_NLBLKS 2 /* UNUSED in this malloc */
186 # define M_GRAIN 3 /* UNUSED in this malloc */
189 # define M_KEEP 4 /* UNUSED in this malloc */
192 /* mallopt options that actually do something */
193 #define M_TRIM_THRESHOLD -1
195 #define M_MMAP_THRESHOLD -3
196 #define M_MMAP_MAX -4
197 #define M_CHECK_ACTION -5
199 /* General SVID/XPG interface to tunable parameters. */
200 extern int mallopt __MALLOC_P ((int __param, int __val));
202 /* Release all but __pad bytes of freed top-most memory back to the
203 system. Return 1 if successful, else 0. */
204 extern int malloc_trim __MALLOC_P ((size_t __pad));
206 /* Report the number of usable allocated bytes associated with allocated
208 extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
210 /* Prints brief summary statistics on stderr. */
211 extern void malloc_stats __MALLOC_P ((void));
213 /* Record the state of all malloc variables in an opaque data structure. */
214 extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
216 /* Restore the state of all malloc variables from data obtained with
217 malloc_get_state(). */
218 extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
220 /* Called once when malloc is initialized; redefining this variable in
221 the application provides the preferred way to set up the hook
223 extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
224 /* Hooks for debugging and user-defined versions. */
225 extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
226 __const __malloc_ptr_t));
227 extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
228 __const __malloc_ptr_t));
229 extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
231 __const __malloc_ptr_t));
232 extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
234 __const __malloc_ptr_t));
235 extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
237 /* Activate a standard set of debugging hooks. */
238 extern void __malloc_check_init __MALLOC_P ((void));
242 } /* end of extern "C" */
245 #endif /* malloc.h */