LLVM 19.0.0git
Classes | Macros | Typedefs | Functions
rpmalloc.h File Reference
#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_trpmalloc_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.
 

Macro Definition Documentation

◆ RPMALLOC_ALLOCATOR

#define RPMALLOC_ALLOCATOR

Definition at line 46 of file rpmalloc.h.

◆ RPMALLOC_ATTRIB_ALLOC_SIZE

#define RPMALLOC_ATTRIB_ALLOC_SIZE (   size)

Definition at line 48 of file rpmalloc.h.

◆ RPMALLOC_ATTRIB_ALLOC_SIZE2

#define RPMALLOC_ATTRIB_ALLOC_SIZE2 (   count,
  size 
)

Definition at line 49 of file rpmalloc.h.

◆ RPMALLOC_ATTRIB_MALLOC

#define RPMALLOC_ATTRIB_MALLOC

Definition at line 47 of file rpmalloc.h.

◆ RPMALLOC_CDECL

#define RPMALLOC_CDECL

Definition at line 50 of file rpmalloc.h.

◆ RPMALLOC_CONFIGURABLE

#define RPMALLOC_CONFIGURABLE   0

Define RPMALLOC_CONFIGURABLE to enable configuring sizes. Will introduce.

Definition at line 57 of file rpmalloc.h.

◆ RPMALLOC_EXPORT

#define RPMALLOC_EXPORT

Definition at line 45 of file rpmalloc.h.

◆ RPMALLOC_FIRST_CLASS_HEAPS

#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.

◆ RPMALLOC_GROW_OR_FAIL

#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.

◆ RPMALLOC_NO_PRESERVE

#define RPMALLOC_NO_PRESERVE   1

Flag to rpaligned_realloc to not preserve content in reallocation.

Definition at line 68 of file rpmalloc.h.

Typedef Documentation

◆ rpmalloc_config_t

◆ rpmalloc_global_statistics_t

◆ rpmalloc_thread_statistics_t

Function Documentation

◆ rpaligned_alloc()

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().

◆ rpaligned_calloc()

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.

◆ rpaligned_realloc()

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().

◆ rpcalloc()

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.

◆ rpfree()

RPMALLOC_EXPORT void rpfree ( void *  ptr)
inline

Free the given memory block.

Definition at line 3385 of file rpmalloc.c.

References _rpmalloc_deallocate().

◆ rpmalloc()

RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpmalloc ( size_t  size)
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_config()

RPMALLOC_EXPORT const rpmalloc_config_t * rpmalloc_config ( void  )

Get allocator configuration.

Definition at line 3370 of file rpmalloc.c.

References _memory_config.

◆ rpmalloc_dump_statistics()

RPMALLOC_EXPORT void rpmalloc_dump_statistics ( void *  file)

◆ rpmalloc_finalize()

RPMALLOC_EXPORT void rpmalloc_finalize ( void  )

◆ rpmalloc_global_statistics()

RPMALLOC_EXPORT void rpmalloc_global_statistics ( rpmalloc_global_statistics_t stats)

◆ rpmalloc_initialize()

RPMALLOC_EXPORT int rpmalloc_initialize ( void  )
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_initialize_config()

RPMALLOC_EXPORT int rpmalloc_initialize_config ( const rpmalloc_config_t config)

◆ rpmalloc_is_thread_initialized()

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_linker_reference()

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().

◆ rpmalloc_thread_collect()

RPMALLOC_EXPORT void rpmalloc_thread_collect ( void  )
inline

Perform deferred deallocations pending for the calling thread heap.

Definition at line 3487 of file rpmalloc.c.

◆ rpmalloc_thread_finalize()

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().

◆ rpmalloc_thread_initialize()

RPMALLOC_EXPORT void rpmalloc_thread_initialize ( void  )
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_thread_statistics()

RPMALLOC_EXPORT void rpmalloc_thread_statistics ( rpmalloc_thread_statistics_t stats)

◆ rpmalloc_usable_size()

RPMALLOC_EXPORT size_t rpmalloc_usable_size ( void *  ptr)
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().

◆ rpmemalign()

RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rpmemalign ( size_t  alignment,
size_t  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().

◆ rpposix_memalign()

RPMALLOC_EXPORT int rpposix_memalign ( void **  memptr,
size_t  alignment,
size_t  size 
)
inline

Allocate a memory block of at least the given size and alignment.

Definition at line 3474 of file rpmalloc.c.

References rpaligned_alloc().

◆ rprealloc()

RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void * rprealloc ( void *  ptr,
size_t  size 
)
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().