LLVM 20.0.0git
|
#include <stddef.h>
Go to the source code of this file.
Classes | |
struct | rpmalloc_global_statistics_t |
struct | rpmalloc_thread_statistics_t |
struct | rpmalloc_config_t |
Macros | |
#define | RPMALLOC_EXPORT |
#define | RPMALLOC_ALLOCATOR |
#define | RPMALLOC_ATTRIB_MALLOC |
#define | RPMALLOC_ATTRIB_ALLOC_SIZE(size) |
#define | RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size) |
#define | RPMALLOC_CDECL |
#define | RPMALLOC_CONFIGURABLE 0 |
Define RPMALLOC_CONFIGURABLE to enable configuring sizes. Will introduce. | |
#define | RPMALLOC_FIRST_CLASS_HEAPS 0 |
Define RPMALLOC_FIRST_CLASS_HEAPS to enable heap based API (rpmalloc_heap_* functions). | |
#define | RPMALLOC_NO_PRESERVE 1 |
Flag to rpaligned_realloc to not preserve content in reallocation. | |
#define | RPMALLOC_GROW_OR_FAIL 2 |
Flag to rpaligned_realloc to fail and return null pointer if grow cannot be done in-place,. | |
Typedefs | |
typedef struct rpmalloc_global_statistics_t | rpmalloc_global_statistics_t |
typedef struct rpmalloc_thread_statistics_t | rpmalloc_thread_statistics_t |
typedef struct rpmalloc_config_t | rpmalloc_config_t |
Functions | |
RPMALLOC_EXPORT int | rpmalloc_initialize (void) |
Initialize allocator with default configuration. | |
RPMALLOC_EXPORT int | rpmalloc_initialize_config (const rpmalloc_config_t *config) |
Initialize allocator with given configuration. | |
RPMALLOC_EXPORT const rpmalloc_config_t * | rpmalloc_config (void) |
Get allocator configuration. | |
RPMALLOC_EXPORT void | rpmalloc_finalize (void) |
Finalize allocator. | |
RPMALLOC_EXPORT void | rpmalloc_thread_initialize (void) |
Initialize allocator for calling thread. | |
RPMALLOC_EXPORT void | rpmalloc_thread_finalize (int release_caches) |
Finalize allocator for calling thread. | |
RPMALLOC_EXPORT void | rpmalloc_thread_collect (void) |
Perform deferred deallocations pending for the calling thread heap. | |
RPMALLOC_EXPORT int | rpmalloc_is_thread_initialized (void) |
Query if allocator is initialized for calling thread. | |
RPMALLOC_EXPORT void | rpmalloc_thread_statistics (rpmalloc_thread_statistics_t *stats) |
Get per-thread statistics. | |
RPMALLOC_EXPORT void | rpmalloc_global_statistics (rpmalloc_global_statistics_t *stats) |
Get global statistics. | |
RPMALLOC_EXPORT void | rpmalloc_dump_statistics (void *file) |
Dump all statistics in human readable format to file (should be a FILE*) | |
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. | |
RPMALLOC_EXPORT void | rpfree (void *ptr) |
Free the given memory block. | |
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. | |
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. | |
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 * | 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 int | rpposix_memalign (void **memptr, size_t alignment, size_t size) |
Allocate a memory block of at least the given size and alignment. | |
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) | |
RPMALLOC_EXPORT void | rpmalloc_linker_reference (void) |
Dummy empty function for forcing linker symbol inclusion. | |
#define RPMALLOC_ALLOCATOR |
Definition at line 46 of file rpmalloc.h.
#define RPMALLOC_ATTRIB_ALLOC_SIZE | ( | size | ) |
Definition at line 48 of file rpmalloc.h.
#define RPMALLOC_ATTRIB_ALLOC_SIZE2 | ( | count, | |
size | |||
) |
Definition at line 49 of file rpmalloc.h.
#define RPMALLOC_ATTRIB_MALLOC |
Definition at line 47 of file rpmalloc.h.
#define RPMALLOC_CDECL |
Definition at line 50 of file rpmalloc.h.
#define RPMALLOC_CONFIGURABLE 0 |
Define RPMALLOC_CONFIGURABLE to enable configuring sizes. Will introduce.
Definition at line 57 of file rpmalloc.h.
#define RPMALLOC_EXPORT |
Definition at line 45 of file rpmalloc.h.
#define RPMALLOC_FIRST_CLASS_HEAPS 0 |
Define RPMALLOC_FIRST_CLASS_HEAPS to enable heap based API (rpmalloc_heap_* functions).
Definition at line 64 of file rpmalloc.h.
#define RPMALLOC_GROW_OR_FAIL 2 |
Flag to rpaligned_realloc to fail and return null pointer if grow cannot be done in-place,.
Definition at line 73 of file rpmalloc.h.
#define RPMALLOC_NO_PRESERVE 1 |
Flag to rpaligned_realloc to not preserve content in reallocation.
Definition at line 68 of file rpmalloc.h.
typedef struct rpmalloc_config_t rpmalloc_config_t |
typedef struct rpmalloc_global_statistics_t rpmalloc_global_statistics_t |
typedef struct rpmalloc_thread_statistics_t rpmalloc_thread_statistics_t |
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpaligned_alloc | ( | size_t | alignment, |
size_t | size | ||
) |
Allocate a memory block of at least the given size and alignment.
Definition at line 3438 of file rpmalloc.c.
References _rpmalloc_aligned_allocate(), and get_thread_heap().
Referenced by rpaligned_calloc(), rpmemalign(), and rpposix_memalign().
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpaligned_calloc | ( | size_t | alignment, |
size_t | num, | ||
size_t | size | ||
) |
Allocate a memory block of at least the given size and alignment, and zero initialize it.
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpaligned_realloc | ( | void * | ptr, |
size_t | alignment, | ||
size_t | size, | ||
size_t | oldsize, | ||
unsigned int | flags | ||
) |
Reallocate the given block to at least the given size and alignment,.
Definition at line 3424 of file rpmalloc.c.
References _memory_page_size, _rpmalloc_aligned_reallocate(), and get_thread_heap().
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpcalloc | ( | size_t | num, |
size_t | size | ||
) |
Allocate a memory block of at least the given size and zero initialize it.
|
inline |
Free the given memory block.
Definition at line 3385 of file rpmalloc.c.
References _rpmalloc_deallocate().
|
inline |
Allocate a memory block of at least the given size.
Definition at line 3374 of file rpmalloc.c.
References _rpmalloc_allocate(), and get_thread_heap().
RPMALLOC_EXPORT const rpmalloc_config_t * rpmalloc_config | ( | void | ) |
RPMALLOC_EXPORT void rpmalloc_dump_statistics | ( | void * | file | ) |
Dump all statistics in human readable format to file (should be a FILE*)
Definition at line 3694 of file rpmalloc.c.
References _memory_heaps, _memory_page_size, _memory_span_size, atomic_load64(), global_cache_t::count, file(), HEAP_ARRAY_SIZE, LARGE_CLASS_COUNT, span_t::next, heap_t::next_heap, global_cache_t::overflow, rpmalloc_assert, SIZE_CLASS_COUNT, and while().
RPMALLOC_EXPORT void rpmalloc_finalize | ( | void | ) |
Finalize allocator.
Finalize allocator.
Definition at line 3293 of file rpmalloc.c.
References _memory_global_lock, _memory_global_reserve, _memory_global_reserve_count, _memory_global_reserve_master, _memory_heaps, _rpmalloc_heap_global_finalize(), _rpmalloc_initialized, atomic_add32(), atomic_store32_release(), heap_t::finalize, HEAP_ARRAY_SIZE, LARGE_CLASS_COUNT, heap_t::next_heap, span_t::remaining_spans, rpmalloc_assert, and rpmalloc_thread_finalize().
RPMALLOC_EXPORT void rpmalloc_global_statistics | ( | rpmalloc_global_statistics_t * | stats | ) |
Get global statistics.
Definition at line 3572 of file rpmalloc.c.
References _memory_page_size, _memory_span_size, _rpmalloc_spin(), atomic_cas32_acquire(), atomic_store32_release(), global_cache_t::count, LARGE_CLASS_COUNT, global_cache_t::lock, span_t::next, and global_cache_t::overflow.
|
inline |
Initialize allocator with default configuration.
Initialize allocator with default configuration.
Definition at line 3047 of file rpmalloc.c.
References _rpmalloc_initialized, rpmalloc_initialize_config(), and rpmalloc_thread_initialize().
Referenced by get_thread_heap().
RPMALLOC_EXPORT int rpmalloc_initialize_config | ( | const rpmalloc_config_t * | config | ) |
Initialize allocator with given configuration.
Definition at line 3055 of file rpmalloc.c.
References _memory_config, _memory_default_span_mask, _memory_default_span_size, _memory_default_span_size_shift, _memory_global_lock, _memory_heap_reserve_count, _memory_heaps, _memory_huge_pages, _memory_map_granularity, _memory_medium_size_limit, _memory_orphan_heaps, _memory_page_size, _memory_page_size_shift, _memory_size_class, _memory_span_map_count, _memory_span_mask, _memory_span_size, _memory_span_size_shift, _rpmalloc_adjust_size_class(), _rpmalloc_heap_release_raw_fc(), _rpmalloc_initialized, _rpmalloc_memset_const, _rpmalloc_mmap_os(), _rpmalloc_unmap_os(), atomic_store32(), atomic_store32_release(), size_class_t::block_size, DEFAULT_SPAN_MAP_COUNT, rpmalloc_config_t::enable_huge_pages, MEDIUM_CLASS_COUNT, MEDIUM_GRANULARITY, MEDIUM_SIZE_LIMIT, rpmalloc_config_t::memory_map, rpmalloc_config_t::memory_unmap, rpmalloc_config_t::page_size, rc, rpmalloc_assert, rpmalloc_linker_reference(), rpmalloc_thread_initialize(), SMALL_CLASS_COUNT, SMALL_GRANULARITY, SMALL_SIZE_LIMIT, SPAN_HEADER_SIZE, rpmalloc_config_t::span_map_count, and rpmalloc_config_t::span_size.
Referenced by rpmalloc_initialize().
RPMALLOC_EXPORT int rpmalloc_is_thread_initialized | ( | void | ) |
Query if allocator is initialized for calling thread.
Definition at line 3366 of file rpmalloc.c.
References get_thread_heap_raw().
RPMALLOC_EXPORT void rpmalloc_linker_reference | ( | void | ) |
Dummy empty function for forcing linker symbol inclusion.
Definition at line 3992 of file rpmalloc.c.
References _rpmalloc_initialized.
Referenced by rpmalloc_initialize_config().
|
inline |
Perform deferred deallocations pending for the calling thread heap.
Definition at line 3487 of file rpmalloc.c.
RPMALLOC_EXPORT void rpmalloc_thread_finalize | ( | int | release_caches | ) |
Finalize allocator for calling thread.
Finalize allocator for calling thread.
Definition at line 3356 of file rpmalloc.c.
References _rpmalloc_heap_release_raw(), get_thread_heap_raw(), and set_thread_heap().
Referenced by rpmalloc_finalize().
|
inline |
Initialize allocator for calling thread.
Initialize allocator for calling thread.
Definition at line 3342 of file rpmalloc.c.
References _rpmalloc_heap_allocate(), _rpmalloc_stat_inc, get_thread_heap_raw(), and set_thread_heap().
Referenced by rpmalloc_initialize(), and rpmalloc_initialize_config().
RPMALLOC_EXPORT void rpmalloc_thread_statistics | ( | rpmalloc_thread_statistics_t * | stats | ) |
Get per-thread statistics.
Definition at line 3489 of file rpmalloc.c.
References _memory_size_class, _memory_span_size, atomic_load64(), atomic_load_ptr(), size_class_t::block_count, size_class_t::block_size, span_cache_t::count, span_t::free_list, span_t::free_list_limit, get_thread_heap_raw(), LARGE_CLASS_COUNT, span_t::list_size, span_t::next, heap_size_class_t::partial_span, span_t::size_class, heap_t::size_class, SIZE_CLASS_COUNT, SIZE_CLASS_HUGE, span_t::span_count, heap_t::span_free_deferred, and span_t::used_count.
|
inline |
Query the usable size of the given memory block (from given pointer to the end of block)
Definition at line 3483 of file rpmalloc.c.
References _rpmalloc_usable_size().
|
inline |
Allocate a memory block of at least the given size and alignment.
Definition at line 3469 of file rpmalloc.c.
References rpaligned_alloc().
|
inline |
Allocate a memory block of at least the given size and alignment.
Definition at line 3474 of file rpmalloc.c.
References rpaligned_alloc().
|
inline |
Reallocate the given block to at least the given size.
Definition at line 3413 of file rpmalloc.c.
References _rpmalloc_reallocate(), and get_thread_heap().