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