Add generic C.UTF-8 locale (Bug 17318)
[glibc.git] / malloc / malloc.h
blob2df0b380506ec063e7fccc58bd2aeab2fa9f100c
1 /* Prototypes and definition for malloc implementation.
2 Copyright (C) 1996-2021 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, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _MALLOC_H
20 #define _MALLOC_H 1
22 #include <features.h>
23 #include <stddef.h>
24 #include <stdio.h>
26 #ifdef _LIBC
27 # define __MALLOC_HOOK_VOLATILE
28 # define __MALLOC_DEPRECATED
29 #else
30 # define __MALLOC_HOOK_VOLATILE volatile
31 # define __MALLOC_DEPRECATED __attribute_deprecated__
32 #endif
35 __BEGIN_DECLS
37 /* Allocate SIZE bytes of memory. */
38 extern void *malloc (size_t __size) __THROW __attribute_malloc__
39 __attribute_alloc_size__ ((1)) __wur;
41 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
42 extern void *calloc (size_t __nmemb, size_t __size)
43 __THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
45 /* Re-allocate the previously allocated block in __ptr, making the new
46 block SIZE bytes long. */
47 /* __attribute_malloc__ is not used, because if realloc returns
48 the same pointer that was passed to it, aliasing needs to be allowed
49 between objects pointed by the old and new pointers. */
50 extern void *realloc (void *__ptr, size_t __size)
51 __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));
53 /* Re-allocate the previously allocated block in PTR, making the new
54 block large enough for NMEMB elements of SIZE bytes each. */
55 /* __attribute_malloc__ is not used, because if reallocarray returns
56 the same pointer that was passed to it, aliasing needs to be allowed
57 between objects pointed by the old and new pointers. */
58 extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
59 __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2, 3))
60 __attr_dealloc_free;
62 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
63 extern void free (void *__ptr) __THROW;
65 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
66 extern void *memalign (size_t __alignment, size_t __size)
67 __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur
68 __attr_dealloc_free;
70 /* Allocate SIZE bytes on a page boundary. */
71 extern void *valloc (size_t __size) __THROW __attribute_malloc__
72 __attribute_alloc_size__ ((1)) __wur __attr_dealloc_free;
74 /* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
75 __size to nearest pagesize. */
76 extern void *pvalloc (size_t __size) __THROW __attribute_malloc__
77 __wur __attr_dealloc_free;
79 /* SVID2/XPG mallinfo structure */
81 struct mallinfo
83 int arena; /* non-mmapped space allocated from system */
84 int ordblks; /* number of free chunks */
85 int smblks; /* number of fastbin blocks */
86 int hblks; /* number of mmapped regions */
87 int hblkhd; /* space in mmapped regions */
88 int usmblks; /* always 0, preserved for backwards compatibility */
89 int fsmblks; /* space available in freed fastbin blocks */
90 int uordblks; /* total allocated space */
91 int fordblks; /* total free space */
92 int keepcost; /* top-most, releasable (via malloc_trim) space */
95 /* SVID2/XPG mallinfo2 structure which can handle allocations
96 bigger than 4GB. */
98 struct mallinfo2
100 size_t arena; /* non-mmapped space allocated from system */
101 size_t ordblks; /* number of free chunks */
102 size_t smblks; /* number of fastbin blocks */
103 size_t hblks; /* number of mmapped regions */
104 size_t hblkhd; /* space in mmapped regions */
105 size_t usmblks; /* always 0, preserved for backwards compatibility */
106 size_t fsmblks; /* space available in freed fastbin blocks */
107 size_t uordblks; /* total allocated space */
108 size_t fordblks; /* total free space */
109 size_t keepcost; /* top-most, releasable (via malloc_trim) space */
112 /* Returns a copy of the updated current mallinfo. */
113 extern struct mallinfo mallinfo (void) __THROW __MALLOC_DEPRECATED;
115 /* Returns a copy of the updated current mallinfo. */
116 extern struct mallinfo2 mallinfo2 (void) __THROW;
118 /* SVID2/XPG mallopt options */
119 #ifndef M_MXFAST
120 # define M_MXFAST 1 /* maximum request size for "fastbins" */
121 #endif
122 #ifndef M_NLBLKS
123 # define M_NLBLKS 2 /* UNUSED in this malloc */
124 #endif
125 #ifndef M_GRAIN
126 # define M_GRAIN 3 /* UNUSED in this malloc */
127 #endif
128 #ifndef M_KEEP
129 # define M_KEEP 4 /* UNUSED in this malloc */
130 #endif
132 /* mallopt options that actually do something */
133 #define M_TRIM_THRESHOLD -1
134 #define M_TOP_PAD -2
135 #define M_MMAP_THRESHOLD -3
136 #define M_MMAP_MAX -4
137 #define M_CHECK_ACTION -5
138 #define M_PERTURB -6
139 #define M_ARENA_TEST -7
140 #define M_ARENA_MAX -8
142 /* General SVID/XPG interface to tunable parameters. */
143 extern int mallopt (int __param, int __val) __THROW;
145 /* Release all but __pad bytes of freed top-most memory back to the
146 system. Return 1 if successful, else 0. */
147 extern int malloc_trim (size_t __pad) __THROW;
149 /* Report the number of usable allocated bytes associated with allocated
150 chunk __ptr. */
151 extern size_t malloc_usable_size (void *__ptr) __THROW;
153 /* Prints brief summary statistics on stderr. */
154 extern void malloc_stats (void) __THROW;
156 /* Output information about state of allocator to stream FP. */
157 extern int malloc_info (int __options, FILE *__fp) __THROW;
159 __END_DECLS
160 #endif /* malloc.h */