Update.
[glibc.git] / malloc / malloc.h
blob8accd64699da52fa5a661c52410e3d44f0f7b4d3
1 /* Prototypes and definition for malloc implementation.
2 Copyright (C) 1996, 1997, 1999, 2000 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
18 02111-1307 USA. */
20 #ifndef _MALLOC_H
21 #define _MALLOC_H 1
23 #include <features.h>
26 `ptmalloc', a malloc implementation for multiple threads without
27 lock contention, by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>.
28 See the files `ptmalloc.c' or `COPYRIGHT' for copying conditions.
30 VERSION 2.6.4-pt Wed Dec 4 00:35:54 MET 1996
32 This work is mainly derived from malloc-2.6.4 by Doug Lea
33 <dl@cs.oswego.edu>, which is available from:
35 ftp://g.oswego.edu/pub/misc/malloc.c
37 This trimmed-down header file only provides function prototypes and
38 the exported data structures. For more detailed function
39 descriptions and compile-time options, see the source file
40 `ptmalloc.c'.
43 #if defined(__STDC__) || defined (__cplusplus)
44 # include <stddef.h>
45 # define __malloc_ptr_t void *
46 #else
47 # undef size_t
48 # define size_t unsigned int
49 # undef ptrdiff_t
50 # define ptrdiff_t int
51 # define __malloc_ptr_t char *
52 #endif
54 #ifdef _LIBC
55 /* Used by GNU libc internals. */
56 # define __malloc_size_t size_t
57 # define __malloc_ptrdiff_t ptrdiff_t
58 #elif !defined __attribute_malloc__
59 # define __attribute_malloc__
60 #endif
62 #ifdef __GNUC__
64 /* GCC can always grok prototypes. For C++ programs we add throw()
65 to help it optimize the function calls. But this works only with
66 gcc 2.8.x and egcs. */
67 # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
68 # define __THROW throw ()
69 # else
70 # define __THROW
71 # endif
72 # define __MALLOC_P(args) args __THROW
73 /* This macro will be used for functions which might take C++ callback
74 functions. */
75 # define __MALLOC_PMT(args) args
77 #else /* Not GCC. */
79 # define __THROW
81 # if (defined __STDC__ && __STDC__) || defined __cplusplus
83 # define __MALLOC_P(args) args
84 # define __MALLOC_PMT(args) args
86 # else /* Not ANSI C or C++. */
88 # define __MALLOC_P(args) () /* No prototypes. */
89 # define __MALLOC_PMT(args) ()
91 # endif /* ANSI C or C++. */
93 #endif /* GCC. */
95 #ifndef NULL
96 # ifdef __cplusplus
97 # define NULL 0
98 # else
99 # define NULL ((__malloc_ptr_t) 0)
100 # endif
101 #endif
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
107 /* Nonzero if the malloc is already initialized. */
108 #ifdef _LIBC
109 /* In the GNU libc we rename the global variable
110 `__malloc_initialized' to `__libc_malloc_initialized'. */
111 # define __malloc_initialized __libc_malloc_initialized
112 #endif
113 extern int __malloc_initialized;
115 /* Initialize global configuration. Not needed with GNU libc. */
116 #ifndef __GLIBC__
117 extern void ptmalloc_init __MALLOC_P ((void));
118 #endif
120 /* Allocate SIZE bytes of memory. */
121 extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
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__;
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,
130 size_t __size))
131 __attribute_malloc__;
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));
142 /* Allocate SIZE bytes on a page boundary. */
143 extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
145 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
146 __size to nearest pagesize. */
147 extern __malloc_ptr_t pvalloc __MALLOC_P ((size_t __size))
148 __attribute_malloc__;
150 /* Underlying allocation function; successive calls should return
151 contiguous pieces of memory. */
152 extern __malloc_ptr_t (*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
154 /* Default value of `__morecore'. */
155 extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size))
156 __attribute_malloc__;
158 /* SVID2/XPG mallinfo structure */
159 struct mallinfo {
160 int arena; /* total space allocated from system */
161 int ordblks; /* number of non-inuse chunks */
162 int smblks; /* unused -- always zero */
163 int hblks; /* number of mmapped regions */
164 int hblkhd; /* total space in mmapped regions */
165 int usmblks; /* unused -- always zero */
166 int fsmblks; /* unused -- always zero */
167 int uordblks; /* total allocated space */
168 int fordblks; /* total non-inuse space */
169 int keepcost; /* top-most, releasable (via malloc_trim) space */
172 /* Returns a copy of the updated current mallinfo. */
173 extern struct mallinfo mallinfo __MALLOC_P ((void));
175 /* SVID2/XPG mallopt options */
176 #ifndef M_MXFAST
177 # define M_MXFAST 1 /* UNUSED in this malloc */
178 #endif
179 #ifndef M_NLBLKS
180 # define M_NLBLKS 2 /* UNUSED in this malloc */
181 #endif
182 #ifndef M_GRAIN
183 # define M_GRAIN 3 /* UNUSED in this malloc */
184 #endif
185 #ifndef M_KEEP
186 # define M_KEEP 4 /* UNUSED in this malloc */
187 #endif
189 /* mallopt options that actually do something */
190 #define M_TRIM_THRESHOLD -1
191 #define M_TOP_PAD -2
192 #define M_MMAP_THRESHOLD -3
193 #define M_MMAP_MAX -4
194 #define M_CHECK_ACTION -5
196 /* General SVID/XPG interface to tunable parameters. */
197 extern int mallopt __MALLOC_P ((int __param, int __val));
199 /* Release all but __pad bytes of freed top-most memory back to the
200 system. Return 1 if successful, else 0. */
201 extern int malloc_trim __MALLOC_P ((size_t __pad));
203 /* Report the number of usable allocated bytes associated with allocated
204 chunk __ptr. */
205 extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
207 /* Prints brief summary statistics on stderr. */
208 extern void malloc_stats __MALLOC_P ((void));
210 /* Record the state of all malloc variables in an opaque data structure. */
211 extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
213 /* Restore the state of all malloc variables from data obtained with
214 malloc_get_state(). */
215 extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
217 #if defined __GLIBC__ || defined MALLOC_HOOKS
218 /* Called once when malloc is initialized; redefining this variable in
219 the application provides the preferred way to set up the hook
220 pointers. */
221 extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
222 /* Hooks for debugging and user-defined versions. */
223 extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
224 __const __malloc_ptr_t));
225 extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
226 __const __malloc_ptr_t));
227 extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
228 size_t __size,
229 __const __malloc_ptr_t));
230 extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
231 size_t __size,
232 __const __malloc_ptr_t));
233 extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
235 /* Activate a standard set of debugging hooks. */
236 extern void __malloc_check_init __MALLOC_P ((void));
237 #endif
239 #ifdef __cplusplus
240 }; /* end of extern "C" */
241 #endif
243 #endif /* malloc.h */