1 /* Prototypes and definition for malloc implementation.
2 Copyright (C) 1996, 1997, 1999 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
24 `ptmalloc', a malloc implementation for multiple threads without
25 lock contention, by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>.
26 See the files `ptmalloc.c' or `COPYRIGHT' for copying conditions.
28 VERSION 2.6.4-pt Wed Dec 4 00:35:54 MET 1996
30 This work is mainly derived from malloc-2.6.4 by Doug Lea
31 <dl@cs.oswego.edu>, which is available from:
33 ftp://g.oswego.edu/pub/misc/malloc.c
35 This trimmed-down header file only provides function prototypes and
36 the exported data structures. For more detailed function
37 descriptions and compile-time options, see the source file
41 #if defined(__STDC__) || defined (__cplusplus)
43 # define __malloc_ptr_t void *
46 # define size_t unsigned int
48 # define ptrdiff_t int
49 # define __malloc_ptr_t char *
53 /* Used by GNU libc internals. */
54 # define __malloc_size_t size_t
55 # define __malloc_ptrdiff_t ptrdiff_t
60 /* GCC can always grok prototypes. For C++ programs we add throw()
61 to help it optimize the function calls. But this works only with
62 gcc 2.8.x and egcs. */
63 # if defined __cplusplus && __GNUC_MINOR__ >= 8
64 # define __THROW throw ()
68 # define __MALLOC_P(args) args __THROW
69 /* This macro will be used for functions which might take C++ callback
71 # define __MALLOC_PMT(args) args
75 # if (defined __STDC__ && __STDC__) || defined __cplusplus
77 # define __MALLOC_P(args) args
78 # define __MALLOC_PMT(args) args
80 # else /* Not ANSI C or C++. */
82 # define __MALLOC_P(args) () /* No prototypes. */
83 # define __MALLOC_PMT(args) ()
85 # endif /* ANSI C or C++. */
93 # define NULL ((__malloc_ptr_t) 0)
101 /* Nonzero if the malloc is already initialized. */
103 /* In the GNU libc we rename the global variable
104 `__malloc_initialized' to `__libc_malloc_initialized'. */
105 # define __malloc_initialized __libc_malloc_initialized
107 extern int __malloc_initialized;
109 /* Initialize global configuration. Not needed with GNU libc. */
111 extern void ptmalloc_init __MALLOC_P ((void));
114 /* Allocate SIZE bytes of memory. */
115 extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size));
117 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
118 extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size));
120 /* Re-allocate the previously allocated block in __ptr, making the new
121 block SIZE bytes long. */
122 extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr, size_t __size));
124 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
125 extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
127 /* Free a block allocated by `calloc'. */
128 extern void cfree __MALLOC_P ((__malloc_ptr_t __ptr));
130 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
131 extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
133 /* Allocate SIZE bytes on a page boundary. */
134 extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size));
136 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
137 __size to nearest pagesize. */
138 extern __malloc_ptr_t pvalloc __MALLOC_P ((size_t __size));
140 /* Underlying allocation function; successive calls should return
141 contiguous pieces of memory. */
142 extern __malloc_ptr_t (*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
144 /* Default value of `__morecore'. */
145 extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size));
147 /* SVID2/XPG mallinfo structure */
149 int arena; /* total space allocated from system */
150 int ordblks; /* number of non-inuse chunks */
151 int smblks; /* unused -- always zero */
152 int hblks; /* number of mmapped regions */
153 int hblkhd; /* total space in mmapped regions */
154 int usmblks; /* unused -- always zero */
155 int fsmblks; /* unused -- always zero */
156 int uordblks; /* total allocated space */
157 int fordblks; /* total non-inuse space */
158 int keepcost; /* top-most, releasable (via malloc_trim) space */
161 /* Returns a copy of the updated current mallinfo. */
162 extern struct mallinfo mallinfo __MALLOC_P ((void));
164 /* SVID2/XPG mallopt options */
166 # define M_MXFAST 1 /* UNUSED in this malloc */
169 # define M_NLBLKS 2 /* UNUSED in this malloc */
172 # define M_GRAIN 3 /* UNUSED in this malloc */
175 # define M_KEEP 4 /* UNUSED in this malloc */
178 /* mallopt options that actually do something */
179 #define M_TRIM_THRESHOLD -1
181 #define M_MMAP_THRESHOLD -3
182 #define M_MMAP_MAX -4
183 #define M_CHECK_ACTION -5
185 /* General SVID/XPG interface to tunable parameters. */
186 extern int mallopt __MALLOC_P ((int __param, int __val));
188 /* Release all but __pad bytes of freed top-most memory back to the
189 system. Return 1 if successful, else 0. */
190 extern int malloc_trim __MALLOC_P ((size_t __pad));
192 /* Report the number of usable allocated bytes associated with allocated
194 extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
196 /* Prints brief summary statistics on stderr. */
197 extern void malloc_stats __MALLOC_P ((void));
199 /* Record the state of all malloc variables in an opaque data structure. */
200 extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
202 /* Restore the state of all malloc variables from data obtained with
203 malloc_get_state(). */
204 extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
206 #if defined __GLIBC__ || defined MALLOC_HOOKS
207 /* Hooks for debugging versions. */
208 extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
209 extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
210 __const __malloc_ptr_t));
211 extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
212 __const __malloc_ptr_t));
213 extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
215 __const __malloc_ptr_t));
216 extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __size,
218 __const __malloc_ptr_t));
219 extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
221 /* Activate a standard set of debugging hooks. */
222 extern void __malloc_check_init __MALLOC_P ((void));
226 }; /* end of extern "C" */
229 #endif /* malloc.h */