---
name: "memcached_clone"
section: "3"
platform: "linux"
package: "libmemcached-awesome"
version: "1.1.4-4"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/memcached_clone"
---

# memcached\_clone(3)

libmemcached Documentation

## NAME

memcached\_clone - 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

**memcached\_create()** is used to create a **memcached\_st** structure that will then be used by other **libmemcached** functions to communicate with the server. You should either pass a statically declared **memcached\_st** to **memcached\_create()** or a NULL. If a NULL passed in then a structure is allocated for you.

Please note, when you write new application use **memcached()** \<#\_CPPv49memcachedPKc6size\_t\> over **memcached\_create()**.

**memcached\_clone()** is similar to **memcached\_create()** but it copies the defaults and list of servers from the source **memcached\_st** pointer. If you pass a null as the argument for the source to clone, it is the same as a call to **memcached\_create()**. If the destination argument is NULL a **memcached\_st** will be allocated for you.

**memcached\_servers\_reset()** allows you to zero out the list of servers that the **memcached\_st** has.

To clean up memory associated with a **memcached\_st** structure you should pass it to **memcached\_free()** when you are finished using it. **memcached\_free()** is the only way to make sure all memory is deallocated when you finish using the structure.

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.

## 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

**[memcached(1)](/memcached/1.md) \<https://linux.die.net/man/1/memcached\>** **[libmemcached(3)](/libmemcached/3.md) \<https://linux.die.net/man/3/libmemcached\>**
