a5bc63791785689bea3a8f68b7e3036c7f37cc39
[awesomized/libmemcached] / docs / source / libmemcached / memcached_create.rst
1 Creating and destroying a memcached_st
2 ======================================
3
4 SYNOPSIS
5 --------
6
7 #include <libmemcached/memcached.h>
8 Compile and link with -lmemcached
9
10 .. type:: struct memcached_st memcached_st
11
12 .. function:: memcached_st* memcached_create(memcached_st *ptr)
13
14 .. function:: void memcached_free(memcached_st *ptr)
15
16 .. function:: memcached_st* memcached_clone(memcached_st *destination, memcached_st *source)
17
18 .. function:: void memcached_servers_reset(memcached_st)
19
20 DESCRIPTION
21 -----------
22
23 `memcached_create` is used to create a `memcached_st` structure that will then
24 be used by other `libmemcached` functions to communicate with the server. You
25 should either pass a statically declared `memcached_st` to `memcached_create` or
26 a NULL. If a NULL passed in then a structure is allocated for you.
27
28 Please note, when you write new application use `memcached` over
29 `memcached_create`.
30
31 `memcached_clone` is similar to `memcached_create` but it copies the defaults
32 and list of servers from the source `memcached_st`. If you pass a null as the
33 argument for the source to clone, it is the same as a call to
34 `memcached_create`. If the destination argument is NULL a `memcached_st` will be
35 allocated for you.
36
37 `memcached_servers_reset` allows you to zero out the list of servers that the
38 `memcached_st` has.
39
40 To clean up memory associated with a `memcached_st` structure you should pass it
41 to `memcached_free` when you are finished using it. `memcached_free` is the only
42 way to make sure all memory is deallocated when you finish using the structure.
43
44 You may wish to avoid using `memcached_create` or `memcached_clone` with a stack
45 based allocation. The most common issues related to ABI safety involve heap
46 allocated structures.
47
48 RETURN VALUE
49 ------------
50
51 `memcached_create` returns a pointer to the `memcached_st` that was created (or
52 initialized). On an allocation failure, it returns NULL.
53
54 `memcached_clone` returns a pointer to the `memcached_st` that was created (or
55 initialized). On an allocation failure, it returns NULL.
56
57 SEE ALSO
58 --------
59
60 .. only:: man
61
62 :manpage:`memcached(1)`
63 :manpage:`libmemcached(3)`
64
65 .. only:: html
66
67 * :manpage:`memcached(1)`
68 * :doc:`../libmemcached`