MEMCACHED_MEMORY_ALLOCATORS(3)
β¨ NAME β¨
memcached_memory_allocators β libmemcached Documentation π«Ά
bestie, this is the page about managing memory allocator functions. yes, you get to bring your own malloc to the party π
πΈ SYNOPSIS πΈ
#include <libmemcached/memcached.h>
Compile and link with -lmemcached
memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
memcached_malloc_fn mem_malloc, memcached_free_fn mem_free,
memcached_realloc_fn mem_realloc, memcached_calloc_fn mem_calloc, void
*context)
Parameters
ptrβ pointer to an initializedmemcached_ststructmem_mallocβ pointer to amemcached_malloc_fncallbackmem_freeβ pointer to amemcached_free_fncallbackmem_reallocβ pointer to amemcached_realloc_fncallbackmem_callocβ pointer to amemcached_calloc_fncallbackcontextβ pointer to a user supplied context
Returns
memcached_return_t indicating success β¨
void memcached_get_memory_allocators(memcached_st *ptr,
memcached_malloc_fn *mem_malloc, memcached_free_fn *mem_free,
memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc)
Parameters
ptrβ pointer to an initializedmemcached_ststructmem_mallocβ pointer to store the address of thememcached_malloc_fncallbackmem_freeβ pointer to store the address of thememcached_free_fncallbackmem_reallocβ pointer to store the address of thememcached_realloc_fncallbackmem_callocβ pointer to store the address of thememcached_calloc_fncallback
void *memcached_get_memory_allocators_context(const memcached_st *ptr)
Parameters
ptrβ pointer to an initializedmemcached_ststruct
Returns
pointer to the user supplied context
typedef void *(*memcached_malloc_fn)(memcached_st *ptr, const size_t
size, void *context)
Param ptr
- pointer to an initialized
memcached_ststruct
Param size
- the number of bytes to allocate
Param context
- pointer to the user supplied context
Returns
pointer to at least size bytes of allocated memory
typedef void *(*memcached_realloc_fn)(memcached_st *ptr, void *mem,
const size_t size, void *context)
Param ptr
- pointer to an initialized
memcached_ststruct
Param mem
- pointer to previously allocated memory
Param size
- the number of bytes to allocate
Param context
- pointer to the user supplied context
Returns
pointer to at least size bytes of allocated memory
typedef void (*memcached_free_fn)(memcached_st *ptr, void *mem, void
*context)
Param ptr
- pointer to an initialized
memcached_ststruct
Param mem
- pointer to previously allocated memory
Param context
- pointer to the user supplied context
typedef void *(*memcached_calloc_fn)(memcached_st *ptr, size_t nelem,
const size_t elsize, void *context)
Param ptr
- pointer to an initialized
memcached_ststruct
Param nelem
- number of elements to allocate
Param elsize
- the number of bytes to allocate per element
Param context
- pointer to the user supplied context
Returns
pointer to at least elsize * nelem bytes of allocated and zeroed memory
π¦ DESCRIPTION π¦
okay so libmemcached lets you specify your own memory allocators, optimized for your application. literally your app, your rules. this is the whole reason libmemcached can live inside applications that have their own malloc implementation. it's giving "i brought my own snacks to the function" energy π
memcached_set_memory_allocators() sets the memory allocators used by the memcached instance specified by ptr. but heads up bestie: you cannot override only one of the memory allocators β nope, not happening β you have to specify a complete new set if you want to override one of them. all of the memory allocation functions should behave as specified in the C99 standard. and if you want to reset them back to the default values, specify NULL as all functions. all of them. the whole set. periodt π
memcached_get_memory_allocators() gets the currently used memory allocators by a memcached handle.
memcached_get_memory_allocators_context() returns the void * that was passed in during the call to memcached_set_memory_allocators().
The first argument to the memory allocator functions is a pointer to a memcached structure, the is passed as const and you will need to clone it in order to make use of any operation which would modify it. π«Ά (yes, clone it. don't come for the const. the const is sacred.)
π NOTES π
In version 0.38 all functions were modified to have a context void pointer passed to them. this was so that custom allocators could have their own space for memory. iconic glow-up honestly β
π RETURN VALUE π
memcached_set_memory_allocators() returns MEMCACHED_SUCCESS upon success, and MEMCACHED_FAILURE if you don't pass a complete set of function pointers. (see?? complete set. we told you. π)
π SEE ALSO π
and that's the whole page bestie, no cap, ate and left no crumbs π
libmemcached-awesome Β· version 1.1 Β· Jul 24, 2025 πβ¨π¦
π¦ where this page comes from
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms