malloc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #ifndef __THROW
  54. # if defined __cplusplus && (__GNUC__ >= 3 || __GNUC_MINOR__ >= 8)
  55. # define __THROW throw ()
  56. # else
  57. # define __THROW
  58. # endif
  59. #endif
  60. # define __MALLOC_P(args) args __THROW
  61. /* This macro will be used for functions which might take C++ callback
  62. functions. */
  63. # define __MALLOC_PMT(args) args
  64. #else /* Not GCC. */
  65. # define __THROW
  66. # if (defined __STDC__ && __STDC__) || defined __cplusplus
  67. # define __MALLOC_P(args) args
  68. # define __MALLOC_PMT(args) args
  69. # else /* Not ANSI C or C++. */
  70. # define __MALLOC_P(args) () /* No prototypes. */
  71. # define __MALLOC_PMT(args) ()
  72. # endif /* ANSI C or C++. */
  73. #endif /* GCC. */
  74. #ifndef NULL
  75. # ifdef __cplusplus
  76. # define NULL 0
  77. # else
  78. # define NULL ((__malloc_ptr_t) 0)
  79. # endif
  80. #endif
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif
  84. /* Allocate SIZE bytes of memory. */
  85. extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  86. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  87. extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
  88. __attribute_malloc__;
  89. /* Re-allocate the previously allocated block in __ptr, making the new
  90. block SIZE bytes long. */
  91. extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
  92. size_t __size))
  93. __attribute_malloc__;
  94. /* Free a block allocated by `malloc', `realloc' or `calloc'. */
  95. extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
  96. /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
  97. extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
  98. /* Allocate SIZE bytes on a page boundary. */
  99. extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  100. #ifdef __MALLOC_STANDARD__
  101. /* SVID2/XPG mallinfo structure */
  102. struct mallinfo {
  103. int arena; /* total space allocated from system */
  104. int ordblks; /* number of non-inuse chunks */
  105. int smblks; /* unused -- always zero */
  106. int hblks; /* number of mmapped regions */
  107. int hblkhd; /* total space in mmapped regions */
  108. int usmblks; /* unused -- always zero */
  109. int fsmblks; /* unused -- always zero */
  110. int uordblks; /* total allocated space */
  111. int fordblks; /* total non-inuse space */
  112. int keepcost; /* top-most, releasable (via malloc_trim) space */
  113. };
  114. /* Returns a copy of the updated current mallinfo. */
  115. extern struct mallinfo mallinfo __MALLOC_P ((void));
  116. /* Release all but __pad bytes of freed top-most memory back to the
  117. system. Return 1 if successful, else 0. */
  118. extern int malloc_trim(size_t pad);
  119. #include <stdio.h>
  120. /* Prints brief summary statistics to the specified file.
  121. * Writes to stderr if file is NULL. */
  122. extern void malloc_stats(FILE *file);
  123. /* SVID2/XPG mallopt options */
  124. #ifndef M_MXFAST
  125. # define M_MXFAST 1 /* UNUSED in this malloc */
  126. #endif
  127. #ifndef M_NLBLKS
  128. # define M_NLBLKS 2 /* UNUSED in this malloc */
  129. #endif
  130. #ifndef M_GRAIN
  131. # define M_GRAIN 3 /* UNUSED in this malloc */
  132. #endif
  133. #ifndef M_KEEP
  134. # define M_KEEP 4 /* UNUSED in this malloc */
  135. #endif
  136. /* mallopt options that actually do something */
  137. #define M_TRIM_THRESHOLD -1
  138. #define M_TOP_PAD -2
  139. #define M_MMAP_THRESHOLD -3
  140. #define M_MMAP_MAX -4
  141. #define M_CHECK_ACTION -5
  142. #define M_PERTURB -6
  143. /* General SVID/XPG interface to tunable parameters. */
  144. extern int mallopt __MALLOC_P ((int __param, int __val));
  145. #endif /* __MALLOC_STANDARD__ */
  146. #ifdef __cplusplus
  147. } /* end of extern "C" */
  148. #endif
  149. #endif /* malloc.h */