1 Use custom allocators for embedded usage
2 ========================================
4 Manage memory allocator functions
9 #include <libmemcached/memcached.h>
10 Compile and link with -lmemcached
12 .. function:: 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)
14 :param ptr: pointer to an initialized `memcached_st` struct
15 :param mem_malloc: pointer to a `memcached_malloc_fn` callback
16 :param mem_free: pointer to a `memcached_free_fn` callback
17 :param mem_realloc: pointer to a `memcached_realloc_fn` callback
18 :param mem_calloc: pointer to a `memcached_calloc_fn` callback
19 :param context: pointer to a user supplied context
20 :returns: `memcached_return_t` indicating success
22 .. function:: 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)
24 :param ptr: pointer to an initialized `memcached_st` struct
25 :param mem_malloc: pointer to store the address of the `memcached_malloc_fn` callback
26 :param mem_free: pointer to store the address of the `memcached_free_fn` callback
27 :param mem_realloc: pointer to store the address of the `memcached_realloc_fn` callback
28 :param mem_calloc: pointer to store the address of the `memcached_calloc_fn` callback
30 .. function:: void * memcached_get_memory_allocators_context(const memcached_st *ptr)
32 :param ptr: pointer to an initialized `memcached_st` struct
33 :returns: pointer to the user supplied context
35 .. type:: void * (*memcached_malloc_fn) (memcached_st *ptr, const size_t size, void *context)
37 :param ptr: pointer to an initialized `memcached_st` struct
38 :param size: the number of bytes to allocate
39 :param context: pointer to the user supplied context
40 :returns: pointer to at least `size` bytes of allocated memory
42 .. type:: void * (*memcached_realloc_fn) (memcached_st *ptr, void *mem, const size_t size, void *context)
44 :param ptr: pointer to an initialized `memcached_st` struct
45 :param mem: pointer to previously allocated memory
46 :param size: the number of bytes to allocate
47 :param context: pointer to the user supplied context
48 :returns: pointer to at least `size` bytes of allocated memory
50 .. type:: void (*memcached_free_fn) (memcached_st *ptr, void *mem, void *context)
52 :param ptr: pointer to an initialized `memcached_st` struct
53 :param mem: pointer to previously allocated memory
54 :param context: pointer to the user supplied context
56 .. type:: void * (*memcached_calloc_fn) (memcached_st *ptr, size_t nelem, const size_t elsize, void *context)
58 :param ptr: pointer to an initialized `memcached_st` struct
59 :param nelem: number of elements to allocate
60 :param elsize: the number of bytes to allocate per element
61 :param context: pointer to the user supplied context
62 :returns: pointer to at least `elsize` \* `nelem` bytes of allocated and zeroed memory
67 `libmemcached` allows you to specify your own memory allocators, optimized for
68 your application. This enables libmemcached to be used inside of applications
69 that have their own malloc implementation.
71 :func:`memcached_set_memory_allocators` is used to set the memory allocators
72 used by the memcached instance specified by ptr. Please note that you cannot
73 override only one of the memory allocators, you have to specify a complete new
74 set if you want to override one of them. All of the memory allocation functions
75 should behave as specified in the C99 standard. Specify NULL as all functions to
76 reset them to the default values.
78 :func:`memcached_get_memory_allocators` is used to get the currently used memory
79 allocators by a memcached handle.
81 :func:`memcached_get_memory_allocators_context` returns the void \* that was
82 passed in during the call to :func:`memcached_set_memory_allocators`.
84 The first argument to the memory allocator functions is a pointer to a memcached
85 structure, the is passed as const and you will need to clone it in order to make
86 use of any operation which would modify it.
91 In version 0.38 all functions were modified to have a context void pointer
92 passed to them. This was so that custom allocators could have their own space
98 :func:`memcached_set_memory_allocators` returns `MEMCACHED_SUCCESS` upon success,
99 and `MEMCACHED_FAILURE` if you don't pass a complete set of function pointers.
106 :manpage:`memcached(1)`
107 :manpage:`libmemcached(3)`
108 :manpage:`memcached_strerror(3)`
112 * :manpage:`memcached(1)`
113 * :doc:`../libmemcached`
114 * :doc:`memcached_strerror`