1MEMCACHED_SET_MEMORY_ALLOCATORlSi_bCmOeNmTcEaMXcEThM(eC3dA)-CaHwEeDs_oSmEeT_MEMORY_ALLOCATORS_CONTEXT(3)
2
3
4
6 memcached_set_memory_allocators_context - libmemcached Documentation
7
8 Manage memory allocator functions
9
11 #include <libmemcached/memcached.h>
12 Compile and link with -lmemcached
13
14 memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
15 memcached_malloc_fn mem_malloc, memcached_free_fn mem_free,
16 memcached_realloc_fn mem_realloc, memcached_calloc_fn mem_calloc, void
17 *context)
18
19 Parameters
20
21 • ptr -- pointer to an initialized memcached_st struct
22
23 • mem_malloc -- pointer to a memcached_malloc_fn callback
24
25 • mem_free -- pointer to a memcached_free_fn callback
26
27 • mem_realloc -- pointer to a memcached_realloc_fn call‐
28 back
29
30 • mem_calloc -- pointer to a memcached_calloc_fn callback
31
32 • context -- pointer to a user supplied context
33
34 Returns
35 memcached_return_t indicating success
36
37 void memcached_get_memory_allocators(memcached_st *ptr,
38 memcached_malloc_fn *mem_malloc, memcached_free_fn *mem_free,
39 memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc)
40
41 Parameters
42
43 • ptr -- pointer to an initialized memcached_st struct
44
45 • mem_malloc -- pointer to store the address of the
46 memcached_malloc_fn callback
47
48 • mem_free -- pointer to store the address of the
49 memcached_free_fn callback
50
51 • mem_realloc -- pointer to store the address of the
52 memcached_realloc_fn callback
53
54 • mem_calloc -- pointer to store the address of the
55 memcached_calloc_fn callback
56
57 void *memcached_get_memory_allocators_context(const memcached_st *ptr)
58
59 Parameters
60 ptr -- pointer to an initialized memcached_st struct
61
62 Returns
63 pointer to the user supplied context
64
65 typedef void *(*memcached_malloc_fn)(memcached_st *ptr, const size_t
66 size, void *context)
67
68 Parameters
69
70 • ptr -- pointer to an initialized memcached_st struct
71
72 • size -- the number of bytes to allocate
73
74 • context -- pointer to the user supplied context
75
76 Returns
77 pointer to at least size bytes of allocated memory
78
79 typedef void *(*memcached_realloc_fn)(memcached_st *ptr, void *mem,
80 const size_t size, void *context)
81
82 Parameters
83
84 • ptr -- pointer to an initialized memcached_st struct
85
86 • mem -- pointer to previously allocated memory
87
88 • size -- the number of bytes to allocate
89
90 • context -- pointer to the user supplied context
91
92 Returns
93 pointer to at least size bytes of allocated memory
94
95 typedef void (*memcached_free_fn)(memcached_st *ptr, void *mem, void
96 *context)
97
98 Parameters
99
100 • ptr -- pointer to an initialized memcached_st struct
101
102 • mem -- pointer to previously allocated memory
103
104 • context -- pointer to the user supplied context
105
106 typedef void *(*memcached_calloc_fn)(memcached_st *ptr, size_t nelem,
107 const size_t elsize, void *context)
108
109 Parameters
110
111 • ptr -- pointer to an initialized memcached_st struct
112
113 • nelem -- number of elements to allocate
114
115 • elsize -- the number of bytes to allocate per element
116
117 • context -- pointer to the user supplied context
118
119 Returns
120 pointer to at least elsize * nelem bytes of allocated
121 and zeroed memory
122
124 libmemcached allows you to specify your own memory allocators, opti‐
125 mized for your application. This enables libmemcached to be used inside
126 of applications that have their own malloc implementation.
127
128 memcached_set_memory_allocators() is used to set the memory allocators
129 used by the memcached instance specified by ptr. Please note that you
130 cannot override only one of the memory allocators, you have to specify
131 a complete new set if you want to override one of them. All of the mem‐
132 ory allocation functions should behave as specified in the C99 stan‐
133 dard. Specify NULL as all functions to reset them to the default val‐
134 ues.
135
136 memcached_get_memory_allocators() is used to get the currently used
137 memory allocators by a memcached handle.
138
139 memcached_get_memory_allocators_context() returns the void * that was
140 passed in during the call to memcached_set_memory_allocators().
141
142 The first argument to the memory allocator functions is a pointer to a
143 memcached structure, the is passed as const and you will need to clone
144 it in order to make use of any operation which would modify it.
145
147 In version 0.38 all functions were modified to have a context void
148 pointer passed to them. This was so that custom allocators could have
149 their own space for memory.
150
152 memcached_set_memory_allocators() returns MEMCACHED_SUCCESS upon suc‐
153 cess, and MEMCACHED_FAILURE if you don't pass a complete set of func‐
154 tion pointers.
155
157 memcached(1) libmemcached(3) memcached_strerror(3)
158
159
160
161
1621.1 SepM2E0M,CA2C0H2E1D_SET_MEMORY_ALLOCATORS_CONTEXT(3)