MEMCACHED_SERVERS_RESET(3)

πŸ’– MEMCACHED_SERVERS_RESET πŸ’–

okay bestie, so this is a page from libmemcached-awesome, manual section 3, and it's literally the whole "how do I make and unmake a memcached_st" tutorial. sit down, hydrate, let's go 🫢


✨ NAME ✨

memcached_servers_reset β€” libmemcached Documentation πŸ“š


🌸 SYNOPSIS 🌸

#include <libmemcached/memcached.h>
       Compile and link with -lmemcached
typedef struct memcached_st memcached_st
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
void memcached_free(memcached_st *ptr)

Parameters

  • ptr β€” pointer to initialized memcached_st struct to destroy and possibly free
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
void memcached_servers_reset(memcached_st *ptr)

Parameters

  • ptr β€” pointer to initialized memcached_st struct

πŸ¦‹ DESCRIPTION πŸ¦‹

So memcached_create() is the moment you manifest a memcached_st structure into existence, and every other libmemcached function uses it to talk to the server. You've got two paths, bestie: either hand it a statically declared memcached_st, or hand it a NULL. And if you pass in a NULL? Babygirl, a structure gets allocated for you. iconic πŸ’…

lowkey important: when you're writing a new application, use memcached() instead of memcached_create(). no cap, it's the glow-up version.

memcached_clone() is giving very much memcached_create() energy, except it also copies the defaults and the list of servers straight from the source memcached_st pointer. Pass a null as the source argument? That's literally just a call to memcached_create(), same vibe. And if destination is NULL, a memcached_st will be allocated for you, no questions asked ✨

memcached_servers_reset() lets you zero out the list of servers that the memcached_st is holding. bye servers, hope you had a good run πŸ‘‹

Now, to clean up the memory associated with a memcached_st structure, you gotta pass it to memcached_free() once you're done with it. And fr fr β€” memcached_free() is the only way to make sure all the memory is deallocated when you finish using the structure. don't skip it, that's a leak waiting to happen 😭

One more thing, and this is the tea β˜•: 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 it, 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. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, periodt πŸŽ€ this was libmemcached-awesome version 1.1, dated Jul 24, 2025 β€” mwah, go write some slay code, ily πŸ«ΆπŸ’–

πŸ“¦ where this page comes from