docs: sanitize
[awesomized/libmemcached] / docs / source / libmemcached / memcached_memory_allocators.rst
1 Use custom allocators for embedded usage
2 ========================================
3
4 Manage memory allocator functions
5
6 SYNOPSIS
7 --------
8
9 #include <libmemcached/memcached.h>
10 Compile and link with -lmemcached
11
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)
13
14 .. 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)
15
16 .. function:: void * memcached_get_memory_allocators_context(const memcached_st *ptr)
17
18 .. type:: void * (*memcached_malloc_fn) (memcached_st *ptr, const size_t size, void *context)
19
20 .. type:: void * (*memcached_realloc_fn) (memcached_st *ptr, void *mem, const size_t size, void *context)
21
22 .. type:: void (*memcached_free_fn) (memcached_st *ptr, void *mem, void *context)
23
24 .. type:: void * (*memcached_calloc_fn) (memcached_st *ptr, size_t nelem, const size_t elsize, void *context)
25
26 DESCRIPTION
27 -----------
28
29 `libmemcached` allows you to specify your own memory allocators, optimized for
30 your application. This enables libmemcached to be used inside of applications
31 that have their own malloc implementation.
32
33 :func:`memcached_set_memory_allocators` is used to set the memory allocators
34 used by the memcached instance specified by ptr. Please note that you cannot
35 override only one of the memory allocators, you have to specify a complete new
36 set if you want to override one of them. All of the memory allocation functions
37 should behave as specified in the C99 standard. Specify NULL as all functions to
38 reset them to the default values.
39
40 :func:`memcached_get_memory_allocators` is used to get the currently used memory
41 allocators by a memcached handle.
42
43 :func:`memcached_get_memory_allocators_context` returns the void \* that was
44 passed in during the call to :func:`memcached_set_memory_allocators`.
45
46 The first argument to the memory allocator functions is a pointer to a memcached
47 structure, the is passed as const and you will need to clone it in order to make
48 use of any operation which would modify it.
49
50 NOTES
51 -----
52
53 In version 0.38 all functions were modified to have a context void pointer
54 passed to them. This was so that customer allocators could have their own space
55 for memory.
56
57 RETURN
58 ------
59
60 :func:`memcached_set_memory_allocators` return `MEMCACHED_SUCCESS` upon success,
61 and `MEMCACHED_FAILURE` if you don't pass a complete set of function pointers.
62
63 SEE ALSO
64 --------
65
66 .. only:: man
67
68 :manpage:`memcached(1)`
69 :manpage:`libmemcached(3)`
70 :manpage:`memcached_strerror(3)`
71
72 .. only:: html
73
74 * :manpage:`memcached(1)`
75 * :doc:`../libmemcached`
76 * :doc:`memcached_strerror`