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_st struct or null pointer

Returns

pointer to initialized memcached_st struct

🌸 memcached_free

void memcached_free(memcached_st *ptr)

Parameters

  • ptr β€” pointer to initialized memcached_st struct to destroy and possibly free

🌸 memcached_clone

memcached_st *memcached_clone(memcached_st *destination, memcached_st *source)

Parameters

  • destination β€” pointer to user-allocated memcached_st struct or null pointer
  • source β€” pointer to initialized memcached_st struct 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_st struct

✨ 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, use memcached() instead of memcached_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 using memcached_create() or memcached_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 the memcached_st that was created (or initialized). on an allocation failure, it returns NULL. πŸ’€
  • memcached_clone() returns a pointer to the memcached_st that was created (or initialized). on an allocation failure, it returns NULL. πŸ’€

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