Memcac...cators(3pm)

πŸ’– memcached_set_memory_allocators, memcached_get_memory_allocators, memcached_set_memory_allocators_context πŸ’–

okay bestie so this is the manager page for the memory allocator functions β€” three lil functions that let you boss your memory around, all from the User Contributed Perl Documentation corner of the universe. ✨


🌈 LIBRARY

C Client Library for memcached (libmemcached, -lmemcached) 🫢


✨ SYNOPSIS

#include <memcached.h>

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);

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);

void *
  memcached_get_memory_allocators_context(const memcached_st *ptr);

void *
  (*memcached_malloc_fn) (memcached_st *ptr, const size_t size,
                          void *context);

void *
  (*memcached_realloc_fn) (memcached_st *ptr, void *mem,
                           const size_t size,
                           void *context);

void
  (*memcached_free_fn) (memcached_st *ptr, void *mem,
                        void *context);

void *
(*memcached_calloc_fn) (memcached_st *ptr,
                        size_t nelem,
                        const size_t elsize,
                        void *context);

no cap, that's a whole lot of function pointers. but they're cute, I promise. πŸŽ€


πŸ’… DESCRIPTION

libmemcached(3) lets you plug in your own memory allocators, tuned specifically for your application. main character energy for your heap, fr fr.

memcached_set_memory_allocators() β€” this is the one that actually sets the memory allocators used by the memcached instance you point to with ptr. 🫢

⚠️ big important thing bestie: you can NOT override just one of the allocators. nope. it's all-or-nothing. if you wanna swap out even one of them, you have to hand over a complete new set. no half-sending the roster. πŸ’€

All of the memory allocation functions should behave exactly as specified in the C99 standard. and if you pass NULL as all the functions, it resets them right back to the default values. iconic. reset era. ✨

memcached_get_memory_allocators() β€” reads back the memory allocators that a memcached handle is currently using. the little "so what are we working with rn" check. πŸ”

memcached_get_memory_allocators_context() β€” returns the void * that you passed in earlier during the call to memcached_set_memory_allocators(). it's giving "here's your stuff back, bestie". 🎁

The first argument to the memory allocator functions is a pointer to a memcached structure, and it's passed as const β€” meaning if you want to do any operation that would modify it, you're gonna have to clone it first. read-only vibes only. πŸ™ˆ


πŸ“ NOTES

In version 0.38, all of these functions got modified so they have a context void pointer passed to them. why? so that custom allocators could have their own lil space for memory. your allocator, your room, your rules. πŸ’œ


πŸ”₯ RETURN

memcached_set_memory_allocators() returns MEMCACHED_SUCCESS when it goes right πŸŽ‰ β€” and MEMCACHED_FAILURE if you don't pass a complete set of function pointers. (told you. complete set. every single time.) 😭


🏠 HOME

wanna find out more? go check:

<https://launchpad.net/libmemcached>


πŸ‘‘ AUTHOR

Trond Norbye, <trond.norbye@gmail.com> Brian Aker, <brian@tangent.orf<gt>


πŸ¦‹ SEE ALSO

memcached(1) libmemcached(3) memcached_get_user_data(3) memcached_set_user_data(3)


okay that's the whole page, bestie, you ate that πŸ“ this lil gem is living in perl v5.42.3 and it was dated 2026-08-19 β€” so go forth, allocate responsibly, and remember: complete set or nothing. periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from