MEMCACHED_CLONE(3)
π MEMCACHED_CLONE π
okay bestie, sit down, we're talking libmemcached and specifically the whole clone / create / free situation. this is memcached_clone(3) from libmemcached-awesome, and yes it's giving β¨foundational library loreβ¨. if you're writing C that talks to memcached, this is your girl. let's go π«Ά
πΈ SYNOPSIS πΈ
#include <libmemcached/memcached.h>
Compile and link with -lmemcached (no cap, that's the whole vibe).
typedef struct memcached_st memcached_st
β¨ memcached_create
memcached_st *memcached_create(memcached_st *ptr)
- Parameters
- ptr β pointer to a user-allocated
memcached_ststruct, or a null pointer
- ptr β pointer to a user-allocated
- Returns β pointer to the initialized
memcached_ststruct
β¨ memcached_free
void memcached_free(memcached_st *ptr)
- Parameters
- ptr β pointer to an initialized
memcached_ststruct that you want destroyed and possibly freed
- ptr β pointer to an initialized
β¨ memcached_clone
memcached_st *memcached_clone(memcached_st *destination, memcached_st *source)
- Parameters
- destination β pointer to a user-allocated
memcached_ststruct, or a null pointer - source β pointer to an initialized
memcached_ststruct to copy from
- destination β pointer to a user-allocated
- Returns β pointer to the newly initialized destination, copied from source
β¨ memcached_servers_reset
void memcached_servers_reset(memcached_st *ptr)
- Parameters
- ptr β pointer to an initialized
memcached_ststruct
- ptr β pointer to an initialized
π¦ DESCRIPTION π¦
so memcached_create() is the one that makes you a memcached_st structure β that's the lil object every other libmemcached function uses to actually talk to the server. you've got two options, and honestly both are valid: hand it a statically declared memcached_st, or hand it a NULL. and if you pass that NULL? it just allocates a whole structure for you. main character energy, honestly π
not me about to say this: when you write a new application, usememcached()overmemcached_create(). that's literally what the docs say. iykyk.
now memcached_clone() is like memcached_create()'s cooler sibling β same energy, but it also copies the defaults and the list of servers from the source memcached_st pointer. and here's the cute part: if you pass a null as the argument for the source to clone, it's literally the same as calling memcached_create(). if the destination argument is NULL, a memcached_st will be allocated for you. easy β¨
memcached_servers_reset() lets you zero out the list of servers that the memcached_st has. bye servers, it's not you it's me π
and to clean up the memory tied to a memcached_st structure, you pass it to memcached_free() when you're done with it. important: memcached_free() is the only way to make sure all the memory is deallocated when you finish using the structure. don't skip it, bestie, that's a leak π
real talk: you may want to avoid usingmemcached_create()ormemcached_clone()with a stack based allocation. the most common issues related to ABI safety involve heap allocated structures. so like, heap it. please. π
π RETURN VALUE π
memcached_create()returns a pointer to thememcached_stthat was created (or initialized). on an allocation failure, it returnsNULL.memcached_clone()returns a pointer to thememcached_stthat was created (or initialized). on an allocation failure, it returnsNULL.
so yeah, check for NULL before you go using the thing. no cap.
π SEE ALSO π
and that's the whole page, bestie π this was version 1.1, dated Jul 24, 2025, courtesy of libmemcached-awesome. go forth and memcached_free() your structs, mwah πβ¨
π¦ where this page comes from
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms