MEMCACHED_GET_MEMORY_ALLOCATORS(3)
π NAME π
memcached_get_memory_allocators β the libmemcached documentation, bestie π
Managing memory allocator functions β¨ (this whole page is a libmemcached manual page, so like, yes, it's from that family π)
π 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_st struct
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_st struct
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_st struct
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_st struct
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 here's the tea, bestie: libmemcached lets you bring your own memory allocators, tuned specifically for your application. That's the whole vibe β it means libmemcached can live happily inside apps that already have their own malloc implementation. Lowkey iconic. π
memcached_set_memory_allocators() is the one you call to set the memory allocators used by the memcached instance that ptr points at. But heads up, and this part matters: you can't override just one of the memory allocators β nope β you have to hand over a complete new set if you want to override even one of them. No mix-and-match, periodt. π
Every one of those memory allocation functions should behave exactly as specified in the C99 standard. And if you want to reset them back to the default values, pass NULL as all the functions. π
memcached_get_memory_allocators() is how you get the currently used memory allocators out of a memcached handle. π
memcached_get_memory_allocators_context() returns the void * that got passed in during the call to memcached_set_memory_allocators(). π«Ά
And the first argument to the memory allocator functions? That's a pointer to a memcached structure, and it's passed as const, so you'll need to clone it if you want to make use of any operation that would modify it. No cap. π
β NOTES β
In version 0.38, all functions were modified to have a context void pointer passed to them. Why, you ask? So that custom allocators could have their own space for memory. Main character energy fr fr. β¨
π₯ RETURN VALUE π₯
memcached_set_memory_allocators() returns MEMCACHED_SUCCESS when it goes well, and MEMCACHED_FAILURE if you don't pass a complete set of function pointers. That's it, that's the rule. π
π SEE ALSO π
Okay that's the whole page, mwah π β this was libmemcached-awesome, version 1.1, dated Jul 24, 2025, and the original title up top was MEMCACHED_G...Y_ALLOCATORS(3). Slay, go write some allocators bestie πβ¨π
π¦ 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