]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blob - libc/include/malloc.h
auto import from //depot/cupcake/@132589
[android-sdk/platform-bionic.git] / libc / include / malloc.h
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 #ifndef _MALLOC_H_
29 #define _MALLOC_H_
31 #include <sys/cdefs.h>
32 #include <stddef.h>
34 __BEGIN_DECLS
36 extern __mallocfunc void*  malloc(size_t);
37 extern __mallocfunc void*  calloc(size_t, size_t);
38 extern __mallocfunc void*  realloc(void *, size_t);
39 extern                void   free(void *);
41 extern void*   memalign(size_t  alignment, size_t  bytesize);
42 extern void*   valloc(size_t  bytesize);
43 extern void*   pvalloc(size_t  bytesize);
44 extern int     mallopt(int  param_number, int  param_value);
45 extern size_t  malloc_footprint(void);
46 extern size_t  malloc_max_footprint(void);
48 struct mallinfo {
49     size_t arena;    /* non-mmapped space allocated from system */
50     size_t ordblks;  /* number of free chunks */
51     size_t smblks;   /* always 0 */
52     size_t hblks;    /* always 0 */
53     size_t hblkhd;   /* space in mmapped regions */
54     size_t usmblks;  /* maximum total allocated space */
55     size_t fsmblks;  /* always 0 */
56     size_t uordblks; /* total allocated space */
57     size_t fordblks; /* total free space */
58     size_t keepcost; /* releasable (via malloc_trim) space */
59 };
61 extern struct mallinfo  mallinfo(void);
64 /*
65   malloc_usable_size(void* p);
67   Returns the number of bytes you can actually use in
68   an allocated chunk, which may be more than you requested (although
69   often not) due to alignment and minimum size constraints.
70   You can use this many bytes without worrying about
71   overwriting other allocated objects. This is not a particularly great
72   programming practice. malloc_usable_size can be more useful in
73   debugging and assertions, for example:
75   p = malloc(n);
76   assert(malloc_usable_size(p) >= 256);
77 */
78 extern size_t malloc_usable_size(void*  block);
80 /*
81   malloc_stats();
82   Prints on stderr the amount of space obtained from the system (both
83   via sbrk and mmap), the maximum amount (which may be more than
84   current if malloc_trim and/or munmap got called), and the current
85   number of bytes allocated via malloc (or realloc, etc) but not yet
86   freed. Note that this is the number of bytes allocated, not the
87   number requested. It will be larger than the number requested
88   because of alignment and bookkeeping overhead. Because it includes
89   alignment wastage as being in use, this figure may be greater than
90   zero even when no user-level chunks are allocated.
92   The reported current and maximum system memory can be inaccurate if
93   a program makes other calls to system memory allocation functions
94   (normally sbrk) outside of malloc.
96   malloc_stats prints only the most commonly interesting statistics.
97   More information can be obtained by calling mallinfo.
98 */
99 extern void  malloc_stats(void);
101 __END_DECLS
103 #endif /* _MALLOC_H_ */