MEMCACHED_CREATE(3)
π MEMCACHED_CREATE(3) π
okay bestie, sit down, hydrate, because we're about to get intimate with libmemcached-awesome. this is the manual page for memcached_create, and yes, it's giving "I'm the reason your whole app talks to memcached in the first place." main character energy fr fr π
β¨ NAME β¨
memcached_create β libmemcached Documentation π¦
like. that's it. that's the name. iconic of it honestly.
β¨ SYNOPSIS β¨
first things first, you gotta pull in the header, and then you gotta link the library or nothing works and you'll be sad:
#include <libmemcached/memcached.h>
Compile and link with -lmemcached
and here's the whole squad of function signatures, look at them, they're beautiful:
typedef struct memcached_st memcached_st
memcached_st *memcached_create(memcached_st *ptr)
void memcached_free(memcached_st *ptr)
memcached_st *memcached_clone(memcached_st *destination, memcached_st *source)
void memcached_servers_reset(memcached_st *ptr)
πΈ memcached_create
memcached_st *memcached_create(memcached_st *ptr)
Parameters
- ptr β pointer to user-allocated
memcached_ststruct or null pointer
Returns
pointer to initialized memcached_st struct
πΈ memcached_free
void memcached_free(memcached_st *ptr)
Parameters
- ptr β pointer to initialized
memcached_ststruct to destroy and possibly free
πΈ memcached_clone
memcached_st *memcached_clone(memcached_st *destination, memcached_st *source)
Parameters
- destination β pointer to user-allocated
memcached_ststruct or null pointer - source β pointer to initialized
memcached_ststruct to copy from
Returns
pointer to newly initialized destination, copied from source
πΈ memcached_servers_reset
void memcached_servers_reset(memcached_st *ptr)
Parameters
- ptr β pointer to initialized
memcached_ststruct
β¨ DESCRIPTION β¨
so memcached_create() is literally the origin story. it builds you a memcached_st structure, and that structure is what every other libmemcached function uses to go talk to the server. no struct, no chat. π
the way you use it: you either hand it a statically declared memcached_st, or you hand it NULL. and if you pass a NULL in, then boom, a structure gets allocated for you. that's the deal. either way you're getting a struct, bestie π«Ά
ok so real talk, listen up: when you write a new application, usememcached()instead ofmemcached_create(). that's not me being dramatic, that's the docs. periodt.
memcached_clone() is basically memcached_create()'s twin, except it also copies the defaults and the list of servers from the source memcached_st pointer. copying the whole vibe, not just the struct. β¨
and here's the cute part: if you pass a null as the argument for the source to clone, it's the exact same thing as just calling memcached_create(). if the destination argument is NULL, then a memcached_st will be allocated for you. it's giving "I'll handle it, don't worry." π
memcached_servers_reset() lets you zero out the list of servers that the memcached_st has. bye servers! poof π
and then when you're done, when you're finished using it, you gotta pass that memcached_st structure to memcached_free() to clean up the memory associated with it. memcached_free() is the only way to make sure all memory is deallocated when you finish using the structure. like, the only way. no shortcuts. π
β οΈ oh and you may wish 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. be safe. don't be messy with the stack, bestie. π
β¨ 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. π
like yes, they both say the same thing, that's because they both do the same thing. twins. slay. π
β¨ SEE ALSO β¨
go read these next, they're the whole friend group:
and that's the whole page, bestie!! you understood it, I know you did, you're so smart, you ate that π this was MEMCACHED_CREATE(3) from the libmemcached-awesome collection, version 1.1, dated Jul 24, 2025. mwah. go write some C. πβ¨πΈπ¦
π¦ 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