malloc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /* Allocate SIZE bytes of memory. */
  83. extern __malloc_ptr_t malloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  84. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  85. extern __malloc_ptr_t calloc __MALLOC_P ((size_t __nmemb, size_t __size))
  86. __attribute_malloc__;
  87. /* Re-allocate the previously allocated block in __ptr, making the new
  88. block SIZE bytes long. */
  89. extern __malloc_ptr_t realloc __MALLOC_P ((__malloc_ptr_t __ptr,
  90. size_t __size))
  91. __attribute_malloc__;
  92. /* Free a block allocated by `malloc', `realloc' or `calloc'. */
  93. extern void free __MALLOC_P ((__malloc_ptr_t __ptr));
  94. /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
  95. extern __malloc_ptr_t memalign __MALLOC_P ((size_t __alignment, size_t __size));
  96. /* Allocate SIZE bytes on a page boundary. */
  97. extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__;
  98. #ifdef __MALLOC_STANDARD__
  99. /* SVID2/XPG mallinfo structure */
  100. struct mallinfo {
  101. int arena; /* total space allocated from system */
  102. int ordblks; /* number of non-inuse chunks */
  103. int smblks; /* unused -- always zero */
  104. int hblks; /* number of mmapped regions */
  105. int hblkhd; /* total space in mmapped regions */
  106. int usmblks; /* unused -- always zero */
  107. int fsmblks; /* unused -- always zero */
  108. int uordblks; /* total allocated space */
  109. int fordblks; /* total non-inuse space */
  110. int keepcost; /* top-most, releasable (via malloc_trim) space */
  111. };
  112. /* Returns a copy of the updated current mallinfo. */
  113. extern struct mallinfo mallinfo __MALLOC_P ((void));
  114. /* Release all but __pad bytes of freed top-most memory back to the
  115. system. Return 1 if successful, else 0. */
  116. extern int malloc_trim(size_t pad);
  117. #include <stdio.h>
  118. /* Prints brief summary statistics to the specified file.
  119. * Writes to stderr if file is NULL. */
  120. extern void malloc_stats(FILE *file);
  121. /* SVID2/XPG mallopt options */
  122. #ifndef M_MXFAST
  123. # define M_MXFAST 1 /* UNUSED in this malloc */
  124. #endif
  125. #ifndef M_NLBLKS
  126. # define M_NLBLKS 2 /* UNUSED in this malloc */
  127. #endif
  128. #ifndef M_GRAIN
  129. # define M_GRAIN 3 /* UNUSED in this malloc */
  130. #endif
  131. #ifndef M_KEEP
  132. # define M_KEEP 4 /* UNUSED in this malloc */
  133. #endif
  134. /* mallopt options that actually do something */
  135. #define M_TRIM_THRESHOLD -1
  136. #define M_TOP_PAD -2
  137. #define M_MMAP_THRESHOLD -3
  138. #define M_MMAP_MAX -4
  139. #define M_CHECK_ACTION -5
  140. #define M_PERTURB -6
  141. /* General SVID/XPG interface to tunable parameters. */
  142. extern int mallopt __MALLOC_P ((int __param, int __val));
  143. #endif /* __MALLOC_STANDARD__ */
  144. #ifdef __cplusplus
  145. } /* end of extern "C" */
  146. #endif
  147. #endif /* malloc.h */