Back to index

glibc  2.9
malloc.h
Go to the documentation of this file.
00001 /* Prototypes and definition for malloc implementation.
00002    Copyright (C) 1996, 1997, 1999, 2000, 2002-2004, 2005, 2007
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _MALLOC_H
00022 #define _MALLOC_H 1
00023 
00024 #include <features.h>
00025 #include <stddef.h>
00026 # define __malloc_ptr_t  void *
00027 
00028 /* Used by GNU libc internals. */
00029 #define __malloc_size_t size_t
00030 #define __malloc_ptrdiff_t ptrdiff_t
00031 
00032 #ifdef __GNUC__
00033 
00034 # define __MALLOC_P(args)   args __THROW
00035 /* This macro will be used for functions which might take C++ callback
00036    functions.  */
00037 # define __MALLOC_PMT(args) args
00038 
00039 #else  /* Not GCC.  */
00040 
00041 # define __MALLOC_P(args)   args
00042 # define __MALLOC_PMT(args) args
00043 
00044 #endif /* GCC.  */
00045 
00046 
00047 __BEGIN_DECLS
00048 
00049 /* Allocate SIZE bytes of memory.  */
00050 extern void *malloc __MALLOC_P ((size_t __size)) __attribute_malloc__ __wur;
00051 
00052 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
00053 extern void *calloc __MALLOC_P ((size_t __nmemb, size_t __size))
00054        __attribute_malloc__ __wur;
00055 
00056 /* Re-allocate the previously allocated block in __ptr, making the new
00057    block SIZE bytes long.  */
00058 /* __attribute_malloc__ is not used, because if realloc returns
00059    the same pointer that was passed to it, aliasing needs to be allowed
00060    between objects pointed by the old and new pointers.  */
00061 extern void *realloc __MALLOC_P ((void *__ptr, size_t __size))
00062        __attribute_warn_unused_result__;
00063 
00064 /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
00065 extern void free __MALLOC_P ((void *__ptr));
00066 
00067 /* Free a block allocated by `calloc'. */
00068 extern void cfree __MALLOC_P ((void *__ptr));
00069 
00070 /* Allocate SIZE bytes allocated to ALIGNMENT bytes.  */
00071 extern void *memalign __MALLOC_P ((size_t __alignment, size_t __size))
00072        __attribute_malloc__ __wur;
00073 
00074 /* Allocate SIZE bytes on a page boundary.  */
00075 extern void *valloc __MALLOC_P ((size_t __size))
00076        __attribute_malloc__ __wur;
00077 
00078 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
00079    __size to nearest pagesize. */
00080 extern void * pvalloc __MALLOC_P ((size_t __size))
00081        __attribute_malloc__ __wur;
00082 
00083 /* Underlying allocation function; successive calls should return
00084    contiguous pieces of memory.  */
00085 extern void *(*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
00086 
00087 /* Default value of `__morecore'.  */
00088 extern void *__default_morecore __MALLOC_P ((ptrdiff_t __size))
00089        __attribute_malloc__;
00090 
00091 /* SVID2/XPG mallinfo structure */
00092 
00093 struct mallinfo {
00094   int arena;    /* non-mmapped space allocated from system */
00095   int ordblks;  /* number of free chunks */
00096   int smblks;   /* number of fastbin blocks */
00097   int hblks;    /* number of mmapped regions */
00098   int hblkhd;   /* space in mmapped regions */
00099   int usmblks;  /* maximum total allocated space */
00100   int fsmblks;  /* space available in freed fastbin blocks */
00101   int uordblks; /* total allocated space */
00102   int fordblks; /* total free space */
00103   int keepcost; /* top-most, releasable (via malloc_trim) space */
00104 };
00105 
00106 /* Returns a copy of the updated current mallinfo. */
00107 extern struct mallinfo mallinfo __MALLOC_P ((void));
00108 
00109 /* SVID2/XPG mallopt options */
00110 #ifndef M_MXFAST
00111 # define M_MXFAST  1 /* maximum request size for "fastbins" */
00112 #endif
00113 #ifndef M_NLBLKS
00114 # define M_NLBLKS  2 /* UNUSED in this malloc */
00115 #endif
00116 #ifndef M_GRAIN
00117 # define M_GRAIN   3 /* UNUSED in this malloc */
00118 #endif
00119 #ifndef M_KEEP
00120 # define M_KEEP    4 /* UNUSED in this malloc */
00121 #endif
00122 
00123 /* mallopt options that actually do something */
00124 #define M_TRIM_THRESHOLD    -1
00125 #define M_TOP_PAD           -2
00126 #define M_MMAP_THRESHOLD    -3
00127 #define M_MMAP_MAX          -4
00128 #define M_CHECK_ACTION      -5
00129 #define M_PERTURB        -6
00130 
00131 /* General SVID/XPG interface to tunable parameters. */
00132 extern int mallopt __MALLOC_P ((int __param, int __val));
00133 
00134 /* Release all but __pad bytes of freed top-most memory back to the
00135    system. Return 1 if successful, else 0. */
00136 extern int malloc_trim __MALLOC_P ((size_t __pad));
00137 
00138 /* Report the number of usable allocated bytes associated with allocated
00139    chunk __ptr. */
00140 extern size_t malloc_usable_size __MALLOC_P ((void *__ptr));
00141 
00142 /* Prints brief summary statistics on stderr. */
00143 extern void malloc_stats __MALLOC_P ((void));
00144 
00145 /* Record the state of all malloc variables in an opaque data structure. */
00146 extern void *malloc_get_state __MALLOC_P ((void));
00147 
00148 /* Restore the state of all malloc variables from data obtained with
00149    malloc_get_state(). */
00150 extern int malloc_set_state __MALLOC_P ((void *__ptr));
00151 
00152 /* Called once when malloc is initialized; redefining this variable in
00153    the application provides the preferred way to set up the hook
00154    pointers. */
00155 extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
00156 /* Hooks for debugging and user-defined versions. */
00157 extern void (*__free_hook) __MALLOC_PMT ((void *__ptr,
00158                                    __const __malloc_ptr_t));
00159 extern void *(*__malloc_hook) __MALLOC_PMT ((size_t __size,
00160                                         __const __malloc_ptr_t));
00161 extern void *(*__realloc_hook) __MALLOC_PMT ((void *__ptr, size_t __size,
00162                                          __const __malloc_ptr_t));
00163 extern void *(*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
00164                                           size_t __size,
00165                                           __const __malloc_ptr_t));
00166 extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
00167 
00168 /* Activate a standard set of debugging hooks. */
00169 extern void __malloc_check_init __MALLOC_P ((void));
00170 
00171 
00172 __END_DECLS
00173 
00174 #endif /* malloc.h */