4 <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
5 <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
9 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0">
11 <title>Use custom allocators for embedded usage
— libmemcached
1.0.99 documentation
</title>
20 <script type=
"text/javascript" src=
"../_static/js/modernizr.min.js"></script>
23 <script type=
"text/javascript" id=
"documentation_options" data-url_root=
"../" src=
"../_static/documentation_options.js"></script>
24 <script src=
"../_static/jquery.js"></script>
25 <script src=
"../_static/underscore.js"></script>
26 <script src=
"../_static/doctools.js"></script>
27 <script src=
"../_static/language_data.js"></script>
29 <script type=
"text/javascript" src=
"../_static/js/theme.js"></script>
34 <link rel=
"stylesheet" href=
"../_static/css/theme.css" type=
"text/css" />
35 <link rel=
"stylesheet" href=
"../_static/pygments.css" type=
"text/css" />
36 <link rel=
"index" title=
"Index" href=
"../genindex.html" />
37 <link rel=
"search" title=
"Search" href=
"../search.html" />
38 <link rel=
"copyright" title=
"Copyright" href=
"../copyright.html" />
39 <link rel=
"next" title=
"Storing custom user information in the client." href=
"memcached_user_data.html" />
40 <link rel=
"prev" title=
"Setting callbacks" href=
"memcached_callback.html" />
43 <body class=
"wy-body-for-nav">
46 <div class=
"wy-grid-for-nav">
48 <nav data-toggle=
"wy-nav-shift" class=
"wy-nav-side">
49 <div class=
"wy-side-scroll">
50 <div class=
"wy-side-nav-search" >
54 <a href=
"../index.html" class=
"icon icon-home"> libmemcached
71 <form id=
"rtd-search-form" class=
"wy-form" action=
"../search.html" method=
"get">
72 <input type=
"text" name=
"q" placeholder=
"Search docs" />
73 <input type=
"hidden" name=
"check_keywords" value=
"yes" />
74 <input type=
"hidden" name=
"area" value=
"default" />
81 <div class=
"wy-menu wy-menu-vertical" data-spy=
"affix" role=
"navigation" aria-label=
"main navigation">
88 <p class=
"caption"><span class=
"caption-text">libmemcached
</span></p>
90 <li class=
"toctree-l1"><a class=
"reference internal" href=
"../libmemcached.html">Introduction
</a></li>
91 <li class=
"toctree-l1 current"><a class=
"reference internal" href=
"index.html">libmemcached API
</a><ul class=
"current">
92 <li class=
"toctree-l2"><a class=
"reference internal" href=
"index_basics.html">Basics
</a></li>
93 <li class=
"toctree-l2"><a class=
"reference internal" href=
"index_data.html">Working with Data
</a></li>
94 <li class=
"toctree-l2"><a class=
"reference internal" href=
"index_errors.html">Messages and Errors
</a></li>
95 <li class=
"toctree-l2 current"><a class=
"reference internal" href=
"index_advanced.html">Advanced Topics
</a></li>
96 <li class=
"toctree-l2"><a class=
"reference internal" href=
"index_deprecated.html">Deprecated Functionality
</a></li>
99 <li class=
"toctree-l1"><a class=
"reference internal" href=
"index_misc.html">Misc
</a><ul>
100 <li class=
"toctree-l2"><a class=
"reference internal" href=
"configuration.html">Configuration
</a></li>
101 <li class=
"toctree-l2"><a class=
"reference internal" href=
"constants.html">Constants
</a></li>
102 <li class=
"toctree-l2"><a class=
"reference internal" href=
"examples.html">Examples
</a></li>
103 <li class=
"toctree-l2"><a class=
"reference internal" href=
"versioning.html">Versioning
</a></li>
107 <p class=
"caption"><span class=
"caption-text">libmemcachedutil
</span></p>
109 <li class=
"toctree-l1"><a class=
"reference internal" href=
"../libmemcachedutil.html">Introduction
</a></li>
110 <li class=
"toctree-l1"><a class=
"reference internal" href=
"../libmemcachedutil/index.html">libmemcachedutil API
</a><ul>
111 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../libmemcachedutil/memcached_pool.html">Working with memcached pools
</a></li>
115 <p class=
"caption"><span class=
"caption-text">libhashkit
</span></p>
117 <li class=
"toctree-l1"><a class=
"reference internal" href=
"../libhashkit.html">Introduction
</a></li>
118 <li class=
"toctree-l1"><a class=
"reference internal" href=
"../libhashkit/index.html">libhashkit API
</a><ul>
119 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../libhashkit/hashkit_create.html">Creating a hashkit structure
</a></li>
120 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../libhashkit/hashkit_function.html">Set Hash Function
</a></li>
121 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../libhashkit/hashkit_functions.html">Available Hashes
</a></li>
122 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../libhashkit/hashkit_value.html">Generate hash value
</a></li>
126 <p class=
"caption"><span class=
"caption-text">Client Applications
</span></p>
128 <li class=
"toctree-l1"><a class=
"reference internal" href=
"../bin/index.html">Client Applications
</a><ul>
129 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memcapable.html">memcapable - Checking a Memcached server capabilities and compatibility
</a></li>
130 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memcat.html">memcat - “cat” data from a server
</a></li>
131 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memcp.html">memcp - Copy data to a server
</a></li>
132 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memdump.html">memdump - Dumping your server
</a></li>
133 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memerror.html">memerror - translate an error code to a string
</a></li>
134 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memflush.html">memflush - flush all data from a server
</a></li>
135 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memrm.html">memrm - Remove data from a server
</a></li>
136 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memslap.html">memslap - Load testing and benchmarking a server
</a></li>
137 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memaslap.html">memaslap - Load testing and benchmarking a server
</a></li>
138 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memstat.html">memstat - Gather statistics from a server
</a></li>
139 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memexist.html">memexist - Check for the existence of a key
</a></li>
140 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memparse.html">memparse - Parse an option string
</a></li>
141 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memping.html">memping - Test to see if a server is available.
</a></li>
142 <li class=
"toctree-l2"><a class=
"reference internal" href=
"../bin/memtouch.html">memtouch - Touches a key.
</a></li>
153 <section data-toggle=
"wy-nav-shift" class=
"wy-nav-content-wrap">
156 <nav class=
"wy-nav-top" aria-label=
"top navigation">
158 <i data-toggle=
"wy-nav-top" class=
"fa fa-bars"></i>
159 <a href=
"../index.html">libmemcached
</a>
164 <div class=
"wy-nav-content">
166 <div class=
"rst-content">
184 <div role=
"navigation" aria-label=
"breadcrumbs navigation">
186 <ul class=
"wy-breadcrumbs">
188 <li><a href=
"../index.html">Docs
</a> »</li>
190 <li><a href=
"index.html">libmemcached API
</a> »</li>
192 <li><a href=
"index_advanced.html">Advanced Topics
</a> »</li>
194 <li><a href=
"index_advanced_internals.html">Internal Behavior
</a> »</li>
196 <li>Use custom allocators for embedded usage
</li>
199 <li class=
"wy-breadcrumbs-aside">
210 <div role=
"main" class=
"document" itemscope=
"itemscope" itemtype=
"http://schema.org/Article">
211 <div itemprop=
"articleBody">
213 <div class=
"section" id=
"use-custom-allocators-for-embedded-usage">
214 <h1>Use custom allocators for embedded usage
<a class=
"headerlink" href=
"#use-custom-allocators-for-embedded-usage" title=
"Permalink to this headline">¶
</a></h1>
215 <p>Manage memory allocator functions
</p>
216 <div class=
"section" id=
"synopsis">
217 <h2>SYNOPSIS
<a class=
"headerlink" href=
"#synopsis" title=
"Permalink to this headline">¶
</a></h2>
219 <dt>#include
<libmemcached/memcached.h
></dt><dd><p>Compile and link with -lmemcached
</p>
222 <dl class=
"function">
223 <dt id=
"_CPPv431memcached_set_memory_allocatorsP12memcached_st19memcached_malloc_fn17memcached_free_fn20memcached_realloc_fn19memcached_calloc_fnPv">
224 <span id=
"_CPPv331memcached_set_memory_allocatorsP12memcached_st19memcached_malloc_fn17memcached_free_fn20memcached_realloc_fn19memcached_calloc_fnPv"></span><span id=
"_CPPv231memcached_set_memory_allocatorsP12memcached_st19memcached_malloc_fn17memcached_free_fn20memcached_realloc_fn19memcached_calloc_fnPv"></span><span id=
"memcached_set_memory_allocators__memcached_stP.memcached_malloc_fn.memcached_free_fn.memcached_realloc_fn.memcached_calloc_fn.voidP"></span><a class=
"reference internal" href=
"memcached_return_t.html#_CPPv418memcached_return_t" title=
"memcached_return_t">memcached_return_t
</a> <code class=
"sig-name descname">memcached_set_memory_allocators
</code><span class=
"sig-paren">(
</span><a class=
"reference internal" href=
"memcached_create.html#_CPPv412memcached_st" title=
"memcached_st">memcached_st
</a> *
<em>ptr
</em>,
<a class=
"reference internal" href=
"#_CPPv419memcached_malloc_fn" title=
"memcached_malloc_fn">memcached_malloc_fn
</a> <em>mem_malloc
</em>,
<a class=
"reference internal" href=
"#_CPPv417memcached_free_fn" title=
"memcached_free_fn">memcached_free_fn
</a> <em>mem_free
</em>,
<a class=
"reference internal" href=
"#_CPPv420memcached_realloc_fn" title=
"memcached_realloc_fn">memcached_realloc_fn
</a> <em>mem_realloc
</em>,
<a class=
"reference internal" href=
"#_CPPv419memcached_calloc_fn" title=
"memcached_calloc_fn">memcached_calloc_fn
</a> <em>mem_calloc
</em>, void *
<em>context
</em><span class=
"sig-paren">)
</span><a class=
"headerlink" href=
"#_CPPv431memcached_set_memory_allocatorsP12memcached_st19memcached_malloc_fn17memcached_free_fn20memcached_realloc_fn19memcached_calloc_fnPv" title=
"Permalink to this definition">¶
</a><br /></dt>
227 <dl class=
"function">
228 <dt id=
"_CPPv431memcached_get_memory_allocatorsP12memcached_stP19memcached_malloc_fnP17memcached_free_fnP20memcached_realloc_fnP19memcached_calloc_fn">
229 <span id=
"_CPPv331memcached_get_memory_allocatorsP12memcached_stP19memcached_malloc_fnP17memcached_free_fnP20memcached_realloc_fnP19memcached_calloc_fn"></span><span id=
"_CPPv231memcached_get_memory_allocatorsP12memcached_stP19memcached_malloc_fnP17memcached_free_fnP20memcached_realloc_fnP19memcached_calloc_fn"></span><span id=
"memcached_get_memory_allocators__memcached_stP.memcached_malloc_fnP.memcached_free_fnP.memcached_realloc_fnP.memcached_calloc_fnP"></span>void
<code class=
"sig-name descname">memcached_get_memory_allocators
</code><span class=
"sig-paren">(
</span><a class=
"reference internal" href=
"memcached_create.html#_CPPv412memcached_st" title=
"memcached_st">memcached_st
</a> *
<em>ptr
</em>,
<a class=
"reference internal" href=
"#_CPPv419memcached_malloc_fn" title=
"memcached_malloc_fn">memcached_malloc_fn
</a> *
<em>mem_malloc
</em>,
<a class=
"reference internal" href=
"#_CPPv417memcached_free_fn" title=
"memcached_free_fn">memcached_free_fn
</a> *
<em>mem_free
</em>,
<a class=
"reference internal" href=
"#_CPPv420memcached_realloc_fn" title=
"memcached_realloc_fn">memcached_realloc_fn
</a> *
<em>mem_realloc
</em>,
<a class=
"reference internal" href=
"#_CPPv419memcached_calloc_fn" title=
"memcached_calloc_fn">memcached_calloc_fn
</a> *
<em>mem_calloc
</em><span class=
"sig-paren">)
</span><a class=
"headerlink" href=
"#_CPPv431memcached_get_memory_allocatorsP12memcached_stP19memcached_malloc_fnP17memcached_free_fnP20memcached_realloc_fnP19memcached_calloc_fn" title=
"Permalink to this definition">¶
</a><br /></dt>
232 <dl class=
"function">
233 <dt id=
"_CPPv439memcached_get_memory_allocators_contextPK12memcached_st">
234 <span id=
"_CPPv339memcached_get_memory_allocators_contextPK12memcached_st"></span><span id=
"_CPPv239memcached_get_memory_allocators_contextPK12memcached_st"></span><span id=
"memcached_get_memory_allocators_context__memcached_stCP"></span>void *
<code class=
"sig-name descname">memcached_get_memory_allocators_context
</code><span class=
"sig-paren">(
</span><em class=
"property">const
</em> <a class=
"reference internal" href=
"memcached_create.html#_CPPv412memcached_st" title=
"memcached_st">memcached_st
</a> *
<em>ptr
</em><span class=
"sig-paren">)
</span><a class=
"headerlink" href=
"#_CPPv439memcached_get_memory_allocators_contextPK12memcached_st" title=
"Permalink to this definition">¶
</a><br /></dt>
238 <dt id=
"_CPPv419memcached_malloc_fn">
239 <span id=
"_CPPv319memcached_malloc_fn"></span><span id=
"_CPPv219memcached_malloc_fn"></span><span id=
"memcached_malloc_fn"></span><em class=
"property">typedef
</em>void *(*
<code class=
"sig-name descname">memcached_malloc_fn
</code>)
<span class=
"sig-paren">(
</span><a class=
"reference internal" href=
"memcached_create.html#_CPPv412memcached_st" title=
"memcached_st">memcached_st
</a> *ptr,
<em class=
"property">const
</em> size_t size, void *context
<span class=
"sig-paren">)
</span><a class=
"headerlink" href=
"#_CPPv419memcached_malloc_fn" title=
"Permalink to this definition">¶
</a><br /></dt>
243 <dt id=
"_CPPv420memcached_realloc_fn">
244 <span id=
"_CPPv320memcached_realloc_fn"></span><span id=
"_CPPv220memcached_realloc_fn"></span><span id=
"memcached_realloc_fn"></span><em class=
"property">typedef
</em>void *(*
<code class=
"sig-name descname">memcached_realloc_fn
</code>)
<span class=
"sig-paren">(
</span><a class=
"reference internal" href=
"memcached_create.html#_CPPv412memcached_st" title=
"memcached_st">memcached_st
</a> *ptr, void *mem,
<em class=
"property">const
</em> size_t size, void *context
<span class=
"sig-paren">)
</span><a class=
"headerlink" href=
"#_CPPv420memcached_realloc_fn" title=
"Permalink to this definition">¶
</a><br /></dt>
248 <dt id=
"_CPPv417memcached_free_fn">
249 <span id=
"_CPPv317memcached_free_fn"></span><span id=
"_CPPv217memcached_free_fn"></span><span id=
"memcached_free_fn"></span><em class=
"property">typedef
</em>void (*
<code class=
"sig-name descname">memcached_free_fn
</code>)
<span class=
"sig-paren">(
</span><a class=
"reference internal" href=
"memcached_create.html#_CPPv412memcached_st" title=
"memcached_st">memcached_st
</a> *ptr, void *mem, void *context
<span class=
"sig-paren">)
</span><a class=
"headerlink" href=
"#_CPPv417memcached_free_fn" title=
"Permalink to this definition">¶
</a><br /></dt>
253 <dt id=
"_CPPv419memcached_calloc_fn">
254 <span id=
"_CPPv319memcached_calloc_fn"></span><span id=
"_CPPv219memcached_calloc_fn"></span><span id=
"memcached_calloc_fn"></span><em class=
"property">typedef
</em>void *(*
<code class=
"sig-name descname">memcached_calloc_fn
</code>)
<span class=
"sig-paren">(
</span><a class=
"reference internal" href=
"memcached_create.html#_CPPv412memcached_st" title=
"memcached_st">memcached_st
</a> *ptr, size_t nelem,
<em class=
"property">const
</em> size_t elsize, void *context
<span class=
"sig-paren">)
</span><a class=
"headerlink" href=
"#_CPPv419memcached_calloc_fn" title=
"Permalink to this definition">¶
</a><br /></dt>
258 <div class=
"section" id=
"description">
259 <h2>DESCRIPTION
<a class=
"headerlink" href=
"#description" title=
"Permalink to this headline">¶
</a></h2>
260 <p><code class=
"xref cpp cpp-any docutils literal notranslate"><span class=
"pre">libmemcached
</span></code> allows you to specify your own memory allocators, optimized for
261 your application. This enables libmemcached to be used inside of applications
262 that have their own malloc implementation.
</p>
263 <p><a class=
"reference internal" href=
"#_CPPv431memcached_set_memory_allocatorsP12memcached_st19memcached_malloc_fn17memcached_free_fn20memcached_realloc_fn19memcached_calloc_fnPv" title=
"memcached_set_memory_allocators"><code class=
"xref cpp cpp-func docutils literal notranslate"><span class=
"pre">memcached_set_memory_allocators()
</span></code></a> is used to set the memory allocators
264 used by the memcached instance specified by ptr. Please note that you cannot
265 override only one of the memory allocators, you have to specify a complete new
266 set if you want to override one of them. All of the memory allocation functions
267 should behave as specified in the C99 standard. Specify NULL as all functions to
268 reset them to the default values.
</p>
269 <p><a class=
"reference internal" href=
"#_CPPv431memcached_get_memory_allocatorsP12memcached_stP19memcached_malloc_fnP17memcached_free_fnP20memcached_realloc_fnP19memcached_calloc_fn" title=
"memcached_get_memory_allocators"><code class=
"xref cpp cpp-func docutils literal notranslate"><span class=
"pre">memcached_get_memory_allocators()
</span></code></a> is used to get the currently used memory
270 allocators by a memcached handle.
</p>
271 <p><a class=
"reference internal" href=
"#_CPPv439memcached_get_memory_allocators_contextPK12memcached_st" title=
"memcached_get_memory_allocators_context"><code class=
"xref cpp cpp-func docutils literal notranslate"><span class=
"pre">memcached_get_memory_allocators_context()
</span></code></a> returns the void * that was
272 passed in during the call to
<a class=
"reference internal" href=
"#_CPPv431memcached_set_memory_allocatorsP12memcached_st19memcached_malloc_fn17memcached_free_fn20memcached_realloc_fn19memcached_calloc_fnPv" title=
"memcached_set_memory_allocators"><code class=
"xref cpp cpp-func docutils literal notranslate"><span class=
"pre">memcached_set_memory_allocators()
</span></code></a>.
</p>
273 <p>The first argument to the memory allocator functions is a pointer to a memcached
274 structure, the is passed as const and you will need to clone it in order to make
275 use of any operation which would modify it.
</p>
277 <div class=
"section" id=
"notes">
278 <h2>NOTES
<a class=
"headerlink" href=
"#notes" title=
"Permalink to this headline">¶
</a></h2>
279 <p>In version
0.38 all functions were modified to have a context void pointer
280 passed to them. This was so that customer allocators could have their own space
283 <div class=
"section" id=
"return">
284 <h2>RETURN
<a class=
"headerlink" href=
"#return" title=
"Permalink to this headline">¶
</a></h2>
285 <p><a class=
"reference internal" href=
"#_CPPv431memcached_set_memory_allocatorsP12memcached_st19memcached_malloc_fn17memcached_free_fn20memcached_realloc_fn19memcached_calloc_fnPv" title=
"memcached_set_memory_allocators"><code class=
"xref cpp cpp-func docutils literal notranslate"><span class=
"pre">memcached_set_memory_allocators()
</span></code></a> return
<a class=
"reference internal" href=
"memcached_return_t.html#_CPPv4N18memcached_return_t17MEMCACHED_SUCCESSE" title=
"MEMCACHED_SUCCESS"><code class=
"xref cpp cpp-any docutils literal notranslate"><span class=
"pre">MEMCACHED_SUCCESS
</span></code></a> upon success,
286 and
<a class=
"reference internal" href=
"memcached_return_t.html#_CPPv4N18memcached_return_t17MEMCACHED_FAILUREE" title=
"MEMCACHED_FAILURE"><code class=
"xref cpp cpp-any docutils literal notranslate"><span class=
"pre">MEMCACHED_FAILURE
</span></code></a> if you don’t pass a complete set of function pointers.
</p>
288 <div class=
"section" id=
"see-also">
289 <h2>SEE ALSO
<a class=
"headerlink" href=
"#see-also" title=
"Permalink to this headline">¶
</a></h2>
291 <li><p><em class=
"manpage"><a class=
"manpage reference external" href=
"http://man7.org/linux/man-pages/man1/memcached.1.html">memcached(
1)
</a></em></p></li>
292 <li><p><a class=
"reference internal" href=
"../libmemcached.html"><span class=
"doc">C/C++ Client Library for memcached
</span></a></p></li>
293 <li><p><a class=
"reference internal" href=
"memcached_strerror.html"><span class=
"doc">Converting Error Codes to Messages
</span></a></p></li>
304 <div class=
"rst-footer-buttons" role=
"navigation" aria-label=
"footer navigation">
306 <a href=
"memcached_user_data.html" class=
"btn btn-neutral float-right" title=
"Storing custom user information in the client." accesskey=
"n" rel=
"next">Next
<span class=
"fa fa-arrow-circle-right"></span></a>
309 <a href=
"memcached_callback.html" class=
"btn btn-neutral float-left" title=
"Setting callbacks" accesskey=
"p" rel=
"prev"><span class=
"fa fa-arrow-circle-left"></span> Previous
</a>
316 <div role=
"contentinfo">
318 © <a href=
"../copyright.html">Copyright
</a>
322 Built with
<a href=
"http://sphinx-doc.org/">Sphinx
</a> using a
<a href=
"https://github.com/rtfd/sphinx_rtd_theme">theme
</a> provided by
<a href=
"https://readthedocs.org">Read the Docs
</a>.
335 <script type=
"text/javascript">
337 SphinxRtdTheme.Navigation.enable(true);