malloc.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _MALLOC_H
  17. #define _MALLOC_H 1
  18. #include <features.h>
  19. /*
  20. `ptmalloc', a malloc implementation for multiple threads without
  21. lock contention, by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>.
  22. See the files `ptmalloc.c' or `COPYRIGHT' for copying conditions.
  23. VERSION 2.6.4-pt Wed Dec 4 00:35:54 MET 1996
  24. This work is mainly derived from malloc-2.6.4 by Doug Lea
  25. <dl@cs.oswego.edu>, which is available from:
  26. ftp://g.oswego.edu/pub/misc/malloc.c
  27. This trimmed-down header file only provides function prototypes and
  28. the exported data structures. For more detailed function
  29. descriptions and compile-time options, see the source file
  30. `ptmalloc.c'.
  31. */
  32. #if defined(__STDC__) || defined (__cplusplus)
  33. # include <stddef.h>
  34. # define __malloc_ptr_t void *
  35. #else
  36. # undef size_t
  37. # define size_t unsigned int
  38. # undef ptrdiff_t
  39. # define ptrdiff_t int
  40. # define __malloc_ptr_t char *
  41. #endif
  42. #ifdef _LIBC
  43. /* Used by GNU libc internals. */
  44. # define __malloc_size_t size_t
  45. # define __malloc_ptrdiff_t ptrdiff_t
  46. #elif !defined __attribute_malloc__
  47. # define __attribute_malloc__
  48. #endif
  49. #ifdef __GNUC__
  50. /* GCC can always grok prototypes. For C++ programs we add throw()
  51. to help it optimize the function calls. But this works only with
  52. gcc 2.8.x and egcs. */
  53. # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
  54. # define __THROW throw ()
  55. # else
  56. # define __THROW
  57. # endif
  58. # define __MALLOC_P(args) args __THROW
  59. /* This macro will be used for functions which might take C++ callback
  60. functions. */
  61. # define __MALLOC_PMT(args) args
  62. #else /* Not GCC. */
  63. # define __THROW
  64. # if (defined __STDC__ && __STDC__) || defined __cplusplus
  65. # define __MALLOC_P(args) args
  66. # define __MALLOC_PMT(args) args
  67. # else /* Not ANSI C or C++. */
  68. # define __MALLOC_P(args) () /* No prototypes. */
  69. # define __MALLOC_PMT(args) ()
  70. # endif /* ANSI C or C++. */
  71. #endif /* GCC. */
  72. #ifndef NULL
  73. # ifdef __cplusplus
  74. # define NULL 0
  75. # else
  76. # define NULL ((__malloc_ptr_t) 0)
  77. # endif
  78. #endif
  79. #ifdef __cplusplus
  80. extern "C" {
  81. #endif
  82. /* Nonzero if the malloc is already initialized. */
  83. #ifdef _LIBC
  84. /* In the GNU libc we rename the global variable
  85. `__malloc_initialized' to `__libc_malloc_initialized'. */
  86. # define __malloc_initialized __libc_malloc_initialized
  87. #endif
  88. extern int __malloc_initialized;
  89. /* Initialize global configuration. Not needed with GNU libc. */
  90. #ifndef __GLIBC__
  91. extern void ptmalloc_init __MALLOC_P ((void));
  92. #endif
  93. /* Allocate SIZE bytes of memory. */
  94. extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  95. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  96. extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
  97. __attribute_malloc__;
  98. /* Re-allocate the previously allocated block in __ptr, making the new
  99. block SIZE bytes long. */
  100. extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
  101. size_t __size))
  102. __attribute_malloc__;
  103. /* Free a block allocated by `malloc', `realloc' or `calloc'. */
  104. extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
  105. /* Free a block allocated by `calloc'. */
  106. extern void cfree __MALLOC_P ((__malloc_ptr_t __ptr));
  107. /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
  108. extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
  109. /* Allocate SIZE bytes on a page boundary. */
  110. extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  111. /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
  112. __size to nearest pagesize. */
  113. extern __malloc_ptr_t pvalloc __MALLOC_P ((size_t __size))
  114. __attribute_malloc__;
  115. /* Underlying allocation function; successive calls should return
  116. contiguous pieces of memory. */
  117. extern __malloc_ptr_t (*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
  118. /* Default value of `__morecore'. */
  119. extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size))
  120. __attribute_malloc__;
  121. /* SVID2/XPG mallinfo structure */
  122. struct mallinfo {
  123. int arena; /* total space allocated from system */
  124. int ordblks; /* number of non-inuse chunks */
  125. int smblks; /* unused -- always zero */
  126. int hblks; /* number of mmapped regions */
  127. int hblkhd; /* total space in mmapped regions */
  128. int usmblks; /* unused -- always zero */
  129. int fsmblks; /* unused -- always zero */
  130. int uordblks; /* total allocated space */
  131. int fordblks; /* total non-inuse space */
  132. int keepcost; /* top-most, releasable (via malloc_trim) space */
  133. };
  134. /* Returns a copy of the updated current mallinfo. */
  135. extern struct mallinfo mallinfo __MALLOC_P ((void));
  136. /* SVID2/XPG mallopt options */
  137. #ifndef M_MXFAST
  138. # define M_MXFAST 1 /* UNUSED in this malloc */
  139. #endif
  140. #ifndef M_NLBLKS
  141. # define M_NLBLKS 2 /* UNUSED in this malloc */
  142. #endif
  143. #ifndef M_GRAIN
  144. # define M_GRAIN 3 /* UNUSED in this malloc */
  145. #endif
  146. #ifndef M_KEEP
  147. # define M_KEEP 4 /* UNUSED in this malloc */
  148. #endif
  149. /* mallopt options that actually do something */
  150. #define M_TRIM_THRESHOLD -1
  151. #define M_TOP_PAD -2
  152. #define M_MMAP_THRESHOLD -3
  153. #define M_MMAP_MAX -4
  154. #define M_CHECK_ACTION -5
  155. /* General SVID/XPG interface to tunable parameters. */
  156. extern int mallopt __MALLOC_P ((int __param, int __val));
  157. /* Release all but __pad bytes of freed top-most memory back to the
  158. system. Return 1 if successful, else 0. */
  159. extern int malloc_trim __MALLOC_P ((size_t __pad));
  160. /* Report the number of usable allocated bytes associated with allocated
  161. chunk __ptr. */
  162. extern size_t malloc_usable_size __MALLOC_P ((__malloc_ptr_t __ptr));
  163. /* Prints brief summary statistics on stderr. */
  164. extern void malloc_stats __MALLOC_P ((void));
  165. /* Record the state of all malloc variables in an opaque data structure. */
  166. extern __malloc_ptr_t malloc_get_state __MALLOC_P ((void));
  167. /* Restore the state of all malloc variables from data obtained with
  168. malloc_get_state(). */
  169. extern int malloc_set_state __MALLOC_P ((__malloc_ptr_t __ptr));
  170. #if defined __GLIBC__ || defined MALLOC_HOOKS
  171. /* Called once when malloc is initialized; redefining this variable in
  172. the application provides the preferred way to set up the hook
  173. pointers. */
  174. extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
  175. /* Hooks for debugging and user-defined versions. */
  176. extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
  177. __const __malloc_ptr_t));
  178. extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
  179. __const __malloc_ptr_t));
  180. extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
  181. size_t __size,
  182. __const __malloc_ptr_t));
  183. extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
  184. size_t __size,
  185. __const __malloc_ptr_t));
  186. extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
  187. /* Activate a standard set of debugging hooks. */
  188. extern void __malloc_check_init __MALLOC_P ((void));
  189. #endif
  190. #ifdef __cplusplus
  191. }; /* end of extern "C" */
  192. #endif
  193. #endif /* malloc.h */