akmalloc
 All Data Structures Files Functions Variables Typedefs Macros Pages
malloc.h
Go to the documentation of this file.
1 /*
2 This is free and unencumbered software released into the public domain.
3 
4 Anyone is free to copy, modify, publish, use, compile, sell, or
5 distribute this software, either in source code form or as a compiled
6 binary, for any purpose, commercial or non-commercial, and by any
7 means.
8 
9 In jurisdictions that recognize copyright laws, the author or authors
10 of this software dedicate any and all copyright interest in the
11 software to the public domain. We make this dedication for the benefit
12 of the public at large and to the detriment of our heirs and
13 successors. We intend this dedication to be an overt act of
14 relinquishment in perpetuity of all present and future rights to this
15 software under copyright law.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24 
25 For more information, please refer to <http://unlicense.org/>
26 */
27 
33 #ifndef AKMALLOC_MALLOC_H
34 #define AKMALLOC_MALLOC_H
35 
36 /* We only include this to get size_t */
37 #include <stddef.h>
38 
39 #if !defined(AKMALLOC_USE_PREFIX) || !AKMALLOC_USE_PREFIX
40 # define ak_malloc malloc
41 # define ak_calloc calloc
42 # define ak_free free
43 # define ak_aligned_alloc aligned_alloc
44 # define ak_posix_memalign posix_memalign
45 # define ak_memalign memalign
46 # define ak_realloc realloc
47 # define ak_malloc_usable_size malloc_usable_size
48 # define ak_malloc_for_each_segment malloc_for_each_segment
49 #endif
50 
51 #if !defined(AKMALLOC_EXPORT)
52 # define AKMALLOC_EXPORT extern
53 #endif
54 
62 typedef int(*ak_seg_cbk)(const void* p, size_t sz);
63 #define AK_SEG_CBK_DEFINED
64 
65 #if defined(__cplusplus)
66 # define AK_EXTERN_C_BEGIN extern "C" {
67 # define AK_EXTERN_C_END }/*extern C*/
68 #else
69 # define AK_EXTERN_C_BEGIN
70 # define AK_EXTERN_C_END
71 #endif
72 
73 AK_EXTERN_C_BEGIN
74 
81 AKMALLOC_EXPORT void* ak_malloc(size_t n);
82 
90 AKMALLOC_EXPORT void* ak_calloc(size_t n, size_t s);
91 
96 AKMALLOC_EXPORT void ak_free(void* p);
97 
104 AKMALLOC_EXPORT size_t ak_malloc_usable_size(const void* p);
105 
117 AKMALLOC_EXPORT void* ak_realloc(void* p, size_t newsz);
118 
127 AKMALLOC_EXPORT void* ak_memalign(size_t aln, size_t sz);
128 
137 AKMALLOC_EXPORT void* ak_aligned_alloc(size_t aln, size_t sz);
138 
150 AKMALLOC_EXPORT int ak_posix_memalign(void** pptr, size_t aln, size_t sz);
151 
156 AKMALLOC_EXPORT void ak_malloc_for_each_segment(ak_seg_cbk cbk);
157 
158 AK_EXTERN_C_END
159 
160 #if defined(AKMALLOC_INCLUDE_ONLY)
161 # include "akmalloc/malloc.c"
162 #endif
163 
164 #endif/*AKMALLOC_MALLOC_H*/
void ak_malloc_for_each_segment(ak_seg_cbk cbk)
Definition: malloc.c:3059
int ak_posix_memalign(void **pptr, size_t aln, size_t sz)
Definition: malloc.c:3030
int(* ak_seg_cbk)(const void *p, size_t sz)
Definition: malloc.h:62
void * ak_malloc(size_t n)
Definition: malloc.c:3005
void * ak_aligned_alloc(size_t aln, size_t sz)
Definition: malloc.c:3024
void ak_free(void *p)
Definition: malloc.c:3018
void * ak_realloc(void *p, size_t newsz)
Definition: malloc.c:3047
void * ak_memalign(size_t aln, size_t sz)
Definition: malloc.c:3036
void * ak_calloc(size_t n, size_t s)
Definition: malloc.c:3011
size_t ak_malloc_usable_size(const void *p)
Definition: malloc.c:3042