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 Param ptr
69 pointer to an initialized memcached_st struct
70
71 Param size
72 the number of bytes to allocate
73
74 Param context
75 pointer to the user supplied context
76
77 Returns
78 pointer to at least size bytes of allocated memory
79
80 typedef void *(*memcached_realloc_fn)(memcached_st *ptr, void *mem,
81 const size_t size, void *context)
82
83 Param ptr
84 pointer to an initialized memcached_st struct
85
86 Param mem
87 pointer to previously allocated memory
88
89 Param size
90 the number of bytes to allocate
91
92 Param context
93 pointer to the user supplied context
94
95 Returns
96 pointer to at least size bytes of allocated memory
97
98 typedef void (*memcached_free_fn)(memcached_st *ptr, void *mem, void
99 *context)
100
101 Param ptr
102 pointer to an initialized memcached_st struct
103
104 Param mem
105 pointer to previously allocated memory
106
107 Param context
108 pointer to the user supplied context
109
110 typedef void *(*memcached_calloc_fn)(memcached_st *ptr, size_t nelem,
111 const size_t elsize, void *context)
112
113 Param ptr
114 pointer to an initialized memcached_st struct
115
116 Param nelem
117 number of elements to allocate
118
119 Param elsize
120 the number of bytes to allocate per element
121
122 Param context
123 pointer to the user supplied context
124
125 Returns
126 pointer to at least elsize * nelem bytes of allocated
127 and zeroed memory
128
130 libmemcached allows you to specify your own memory allocators, opti‐
131 mized for your application. This enables libmemcached to be used inside
132 of applications that have their own malloc implementation.
133
134 memcached_set_memory_allocators() is used to set the memory allocators
135 used by the memcached instance specified by ptr. Please note that you
136 cannot override only one of the memory allocators, you have to specify
137 a complete new set if you want to override one of them. All of the mem‐
138 ory allocation functions should behave as specified in the C99 stan‐
139 dard. Specify NULL as all functions to reset them to the default val‐
140 ues.
141
142 memcached_get_memory_allocators() is used to get the currently used
143 memory allocators by a memcached handle.
144
145 memcached_get_memory_allocators_context() returns the void * that was
146 passed in during the call to memcached_set_memory_allocators().
147
148 The first argument to the memory allocator functions is a pointer to a
149 memcached structure, the is passed as const and you will need to clone
150 it in order to make use of any operation which would modify it.
151
153 In version 0.38 all functions were modified to have a context void
154 pointer passed to them. This was so that custom allocators could have
155 their own space for memory.
156
158 memcached_set_memory_allocators() returns MEMCACHED_SUCCESS upon suc‐
159 cess, and MEMCACHED_FAILURE if you don't pass a complete set of func‐
160 tion pointers.
161
163 memcached(1) libmemcached(3) memcached_strerror(3)
164
165
166
167
1681.1 MarM0E6M,CA2C0H2E3D_SET_MEMORY_ALLOCATORS_CONTEXT(3)