Go to the documentation of this file.
20 #if defined(__clang__) || defined(__GNUC__)
21 # define RPMALLOC_EXPORT __attribute__((visibility("default")))
22 # define RPMALLOC_ALLOCATOR
23 # if (defined(__clang_major__) && (__clang_major__ < 4)) || (defined(__GNUC__) && defined(ENABLE_PRELOAD) && ENABLE_PRELOAD)
24 # define RPMALLOC_ATTRIB_MALLOC
25 # define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
26 # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size)
28 # define RPMALLOC_ATTRIB_MALLOC __attribute__((__malloc__))
29 # define RPMALLOC_ATTRIB_ALLOC_SIZE(size) __attribute__((alloc_size(size)))
30 # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size) __attribute__((alloc_size(count, size)))
32 # define RPMALLOC_CDECL
33 #elif defined(_MSC_VER)
34 # define RPMALLOC_EXPORT
35 # define RPMALLOC_ALLOCATOR __declspec(allocator) __declspec(restrict)
36 # define RPMALLOC_ATTRIB_MALLOC
37 # define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
38 # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size)
39 # define RPMALLOC_CDECL __cdecl
41 # define RPMALLOC_EXPORT
42 # define RPMALLOC_ALLOCATOR
43 # define RPMALLOC_ATTRIB_MALLOC
44 # define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
45 # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size)
46 # define RPMALLOC_CDECL
51 #ifndef RPMALLOC_CONFIGURABLE
52 #define RPMALLOC_CONFIGURABLE 0
57 #ifndef RPMALLOC_FIRST_CLASS_HEAPS
58 #define RPMALLOC_FIRST_CLASS_HEAPS 0
62 #define RPMALLOC_NO_PRESERVE 1
66 #define RPMALLOC_GROW_OR_FAIL 2
147 void *(*memory_map)(
size_t size,
size_t *offset);
155 void (*
memory_unmap)(
void *address,
size_t size,
size_t offset,
size_t release);
281 #if RPMALLOC_FIRST_CLASS_HEAPS
284 typedef struct heap_t rpmalloc_heap_t;
290 rpmalloc_heap_acquire(
void);
295 rpmalloc_heap_release(rpmalloc_heap_t *heap);
306 rpmalloc_heap_aligned_alloc(rpmalloc_heap_t *heap,
size_t alignment,
318 rpmalloc_heap_aligned_calloc(rpmalloc_heap_t *heap,
size_t alignment,
size_t num,
324 rpmalloc_heap_realloc(rpmalloc_heap_t *heap,
void *ptr,
size_t size,
333 rpmalloc_heap_aligned_realloc(rpmalloc_heap_t *heap,
void *ptr,
size_t alignment,
size_t size,
339 rpmalloc_heap_free(rpmalloc_heap_t *heap,
void *ptr);
343 rpmalloc_heap_free_all(rpmalloc_heap_t *heap);
349 rpmalloc_heap_thread_set_current(rpmalloc_heap_t *heap);
RPMALLOC_EXPORT void rpmalloc_thread_finalize(void)
Finalize allocator for calling thread.
RPMALLOC_EXPORT int rpposix_memalign(void **memptr, size_t alignment, size_t size)
Allocate a memory block of at least the given size and alignment.
size_t spans_to_cache
Number of spans transitioned to cache.
RPMALLOC_EXPORT void rpfree(void *ptr)
Free the given memory block.
RPMALLOC_EXPORT int rpmalloc_initialize(void)
Initialize allocator with default configuration.
RPMALLOC_EXPORT void rpmalloc_finalize(void)
Finalize allocator.
RPMALLOC_EXPORT void rpmalloc_global_statistics(rpmalloc_global_statistics_t *stats)
Get global statistics.
size_t free_total
Total number of frees.
size_t mapped_peak
Peak amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STAT...
size_t from_global
Number of spans transitioned from global cache.
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpmalloc(size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1)
Allocate a memory block of at least the given size.
size_t unmapped_total
Total amount of memory unmapped since initialization (only if ENABLE_STATISTICS=1)
size_t to_reserved
Number of spans transitioned to reserved state.
size_t global_to_thread
Total number of bytes transitioned from global cache to thread cache (only if ENABLE_STATISTICS=1)
struct rpmalloc_thread_statistics_t::@0 span_use[32]
Per span count statistics (only if ENABLE_STATISTICS=1)
RPMALLOC_EXPORT const rpmalloc_config_t * rpmalloc_config(void)
Get allocator configuration.
size_t current
Currently used number of spans.
size_t map_calls
Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls)
size_t spans_from_reserved
Number of spans transitioned from reserved state.
size_t page_size
Size of memory pages. The page size MUST be a power of two. All memory mapping.
size_t sizecache
Current number of bytes available in thread size class caches for small and medium sizes (<32KiB)
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpaligned_calloc(size_t alignment, size_t num, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE2(2
Allocate a memory block of at least the given size and alignment, and zero initialize it.
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpmemalign(size_t alignment, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2)
Allocate a memory block of at least the given size and alignment.
RPMALLOC_EXPORT void rpmalloc_thread_statistics(rpmalloc_thread_statistics_t *stats)
Get per-thread statistics.
size_t huge_alloc
Current amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2Mi...
#define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
size_t spancache
Current number of bytes available in thread span caches for small and medium sizes (<32KiB)
int enable_huge_pages
Enable use of large/huge pages. If this flag is set to non-zero and page size is.
size_t alloc_peak
Peak number of allocations.
size_t huge_alloc_peak
Peak amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB b...
RPMALLOC_EXPORT int rpmalloc_is_thread_initialized(void)
Query if allocator is initialized for calling thread.
size_t spans_from_cache
Number of spans transitioned from cache.
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpaligned_realloc(void *ptr, size_t alignment, size_t size, size_t oldsize, unsigned int flags) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(3)
Reallocate the given block to at least the given size and alignment,.
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpaligned_alloc(size_t alignment, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2)
Allocate a memory block of at least the given size and alignment.
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rprealloc(void *ptr, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2)
Reallocate the given block to at least the given size.
size_t mapped_total
Total amount of memory mapped since initialization (only if ENABLE_STATISTICS=1)
RPMALLOC_EXPORT size_t rpmalloc_usable_size(void *ptr)
Query the usable size of the given memory block (from given pointer to the end of block)
size_t from_cache
Number of spans transitioned from thread cache.
size_t span_map_count
Number of spans to map at each request to map new virtual memory blocks. This can.
#define RPMALLOC_ALLOCATOR
size_t thread_to_global
Total number of bytes transitioned from thread cache to global cache (only if ENABLE_STATISTICS=1)
void(* memory_unmap)(void *address, size_t size, size_t offset, size_t release)
Unmap the memory pages starting at address and spanning the given number of bytes.
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpcalloc(size_t num, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE2(1
Allocate a memory block of at least the given size and zero initialize it.
size_t from_reserved
Number of spans transitioned from reserved state.
struct rpmalloc_thread_statistics_t::@1 size_use[128]
Per size class statistics (only if ENABLE_STATISTICS=1)
size_t to_cache
Number of spans transitioned to thread cache.
RPMALLOC_EXPORT void rpmalloc_dump_statistics(void *file)
Dump all statistics in human readable format to file (should be a FILE*)
size_t mapped
Current amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_S...
size_t alloc_total
Total number of allocations.
size_t to_global
Number of spans transitioned to global cache.
size_t span_size
Size of a span of memory blocks. MUST be a power of two, and in [4096,262144].
#define RPMALLOC_ATTRIB_MALLOC
size_t peak
High water mark of spans used.
size_t cached
Current amount of memory in global caches for small and medium sizes (<32KiB)
RPMALLOC_EXPORT void rpmalloc_thread_collect(void)
Perform deferred deallocations pending for the calling thread heap.
RPMALLOC_EXPORT int rpmalloc_initialize_config(const rpmalloc_config_t *config)
Initialize allocator with given configuration.
RPMALLOC_EXPORT void rpmalloc_thread_initialize(void)
Initialize allocator for calling thread.
size_t alloc_current
Current number of allocations.
#define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size)