cache.c File Reference

#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <signal.h>
#include "cache.h"

Include dependency graph for cache.c:


Functions

cache_tcache_create (const char *name, size_t bufsize, size_t align, cache_constructor_t *constructor, cache_destructor_t *destructor)
 Create an object cache.
void cache_destroy (cache_t *cache)
 Destroy an object cache.
void * cache_alloc (cache_t *cache)
 Allocate an object from the cache.
void cache_free (cache_t *cache, void *ptr)
 Return an object back to the cache.

Variables

const uint64_t redzone_pattern = 0xdeadbeefcafebabe
int cache_error = 0
const int initial_pool_size = 64

Function Documentation

void* cache_alloc ( cache_t handle  ) 

Allocate an object from the cache.

Parameters:
handle the handle to the object cache to allocate from
Returns:
a pointer to an initialized object from the cache, or NULL if the allocation cannot be satisfied.

cache_t* cache_create ( const char *  name,
size_t  bufsize,
size_t  align,
cache_constructor_t constructor,
cache_destructor_t destructor 
)

Create an object cache.

The object cache will let you allocate objects of the same size. It is fully MT safe, so you may allocate objects from multiple threads without having to do any syncrhonization in the application code.

Parameters:
name the name of the object cache. This name may be used for debug purposes and may help you track down what kind of object you have problems with (buffer overruns, leakage etc)
bufsize the size of each object in the cache
align the alignment requirements of the objects in the cache.
constructor the function to be called to initialize memory when we need to allocate more memory from the os.
destructor the function to be called before we release the memory back to the os.
Returns:
a handle to an object cache if successful, NULL otherwise.

void cache_destroy ( cache_t handle  ) 

Destroy an object cache.

Destroy and invalidate an object cache. You should return all buffers allocated with cache_alloc by using cache_free before calling this function. Not doing so results in undefined behavior (the buffers may or may not be invalidated)

Parameters:
handle the handle to the object cache to destroy.

void cache_free ( cache_t handle,
void *  ptr 
)

Return an object back to the cache.

The caller should return the object in an initialized state so that the object may be returned in an expected state from cache_alloc.

Parameters:
handle handle to the object cache to return the object to
ptr pointer to the object to return.


Variable Documentation

int cache_error = 0

const int initial_pool_size = 64

const uint64_t redzone_pattern = 0xdeadbeefcafebabe


Generated on Fri Apr 17 16:28:09 2009 for memcached by  doxygen 1.5.8