2006-01-30 Alexandre Oliva <aoliva@redhat.com>
[glibc.git] / malloc / malloc.h
blob1340aa15bcf40e8efbcf738ad618b041d28dee09
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
18 02111-1307 USA. */
20 #ifndef _MALLOC_H
21 #define _MALLOC_H 1
23 #include <features.h>
24 #include <stddef.h>
25 # define __malloc_ptr_t void *
27 /* Used by GNU libc internals. */
28 #define __malloc_size_t size_t
29 #define __malloc_ptrdiff_t ptrdiff_t
31 #ifdef __GNUC__
33 # define __MALLOC_P(args) args __THROW
34 /* This macro will be used for functions which might take C++ callback
35 functions. */
36 # define __MALLOC_PMT(args) args
38 #else /* Not GCC. */
40 # define __MALLOC_P(args) args
41 # define __MALLOC_PMT(args) args
43 #endif /* GCC. */
46 __BEGIN_DECLS
48 /* Allocate SIZE bytes of memory. */
49 extern void *malloc __MALLOC_P ((size_t __size)) __attribute_malloc__ __wur;
51 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
52 extern void *calloc __MALLOC_P ((size_t __nmemb, size_t __size))
53 __attribute_malloc__ __wur;
55 /* Re-allocate the previously allocated block in __ptr, making the new
56 block SIZE bytes long. */
57 extern void *realloc __MALLOC_P ((void *__ptr, size_t __size))
58 __attribute_malloc__ __attribute_warn_unused_result__;
60 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
61 extern void free __MALLOC_P ((void *__ptr));
63 /* Free a block allocated by `calloc'. */
64 extern void cfree __MALLOC_P ((void *__ptr));
66 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
67 extern void *memalign __MALLOC_P ((size_t __alignment, size_t __size))
68 __attribute_malloc__ __wur;
70 /* Allocate SIZE bytes on a page boundary. */
71 extern void *valloc __MALLOC_P ((size_t __size))
72 __attribute_malloc__ __wur;
74 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
75 __size to nearest pagesize. */
76 extern void * pvalloc __MALLOC_P ((size_t __size))
77 __attribute_malloc__ __wur;
79 /* Underlying allocation function; successive calls should return
80 contiguous pieces of memory. */
81 extern void *(*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
83 /* Default value of `__morecore'. */
84 extern void *__default_morecore __MALLOC_P ((ptrdiff_t __size))
85 __attribute_malloc__;
87 /* SVID2/XPG mallinfo structure */
89 struct mallinfo {
90 int arena; /* non-mmapped space allocated from system */
91 int ordblks; /* number of free chunks */
92 int smblks; /* number of fastbin blocks */
93 int hblks; /* number of mmapped regions */
94 int hblkhd; /* space in mmapped regions */
95 int usmblks; /* maximum total allocated space */
96 int fsmblks; /* space available in freed fastbin blocks */
97 int uordblks; /* total allocated space */
98 int fordblks; /* total free space */
99 int keepcost; /* top-most, releasable (via malloc_trim) space */
102 /* Returns a copy of the updated current mallinfo. */
103 extern struct mallinfo mallinfo __MALLOC_P ((void));
105 /* SVID2/XPG mallopt options */
106 #ifndef M_MXFAST
107 # define M_MXFAST 1 /* maximum request size for "fastbins" */
108 #endif
109 #ifndef M_NLBLKS
110 # define M_NLBLKS 2 /* UNUSED in this malloc */
111 #endif
112 #ifndef M_GRAIN
113 # define M_GRAIN 3 /* UNUSED in this malloc */
114 #endif
115 #ifndef M_KEEP
116 # define M_KEEP 4 /* UNUSED in this malloc */
117 #endif
119 /* mallopt options that actually do something */
120 #define M_TRIM_THRESHOLD -1
121 #define M_TOP_PAD -2
122 #define M_MMAP_THRESHOLD -3
123 #define M_MMAP_MAX -4
124 #define M_CHECK_ACTION -5
125 #define M_PERTURB -6
127 /* General SVID/XPG interface to tunable parameters. */
128 extern int mallopt __MALLOC_P ((int __param, int __val));
130 /* Release all but __pad bytes of freed top-most memory back to the
131 system. Return 1 if successful, else 0. */
132 extern int malloc_trim __MALLOC_P ((size_t __pad));
134 /* Report the number of usable allocated bytes associated with allocated
135 chunk __ptr. */
136 extern size_t malloc_usable_size __MALLOC_P ((void *__ptr));
138 /* Prints brief summary statistics on stderr. */
139 extern void malloc_stats __MALLOC_P ((void));
141 /* Record the state of all malloc variables in an opaque data structure. */
142 extern void *malloc_get_state __MALLOC_P ((void));
144 /* Restore the state of all malloc variables from data obtained with
145 malloc_get_state(). */
146 extern int malloc_set_state __MALLOC_P ((void *__ptr));
148 /* Called once when malloc is initialized; redefining this variable in
149 the application provides the preferred way to set up the hook
150 pointers. */
151 extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
152 /* Hooks for debugging and user-defined versions. */
153 extern void (*__free_hook) __MALLOC_PMT ((void *__ptr,
154 __const __malloc_ptr_t));
155 extern void *(*__malloc_hook) __MALLOC_PMT ((size_t __size,
156 __const __malloc_ptr_t));
157 extern void *(*__realloc_hook) __MALLOC_PMT ((void *__ptr, size_t __size,
158 __const __malloc_ptr_t));
159 extern void *(*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
160 size_t __size,
161 __const __malloc_ptr_t));
162 extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
164 /* Activate a standard set of debugging hooks. */
165 extern void __malloc_check_init __MALLOC_P ((void));
168 __END_DECLS
170 #endif /* malloc.h */