cache.h File Reference

#include <pthread.h>

Include dependency graph for cache.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cache_t
 Definition of the structure to keep track of the internal details of the cache allocator. More...

Typedefs

typedef int cache_constructor_t (void *obj, void *notused1, int notused2)
 Constructor used to initialize allocated objects.
typedef void cache_destructor_t (void *obj, void *notused)
 Destructor used to clean up allocated objects before they are returned to the operating system.

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 *handle)
 Destroy an object cache.
void * cache_alloc (cache_t *handle)
 Allocate an object from the cache.
void cache_free (cache_t *handle, void *ptr)
 Return an object back to the cache.

Variables

int cache_error


Typedef Documentation

typedef int cache_constructor_t(void *obj, void *notused1, int notused2)

Constructor used to initialize allocated objects.

Parameters:
obj pointer to the object to initialized.
notused1 This parameter is currently not used.
notused2 This parameter is currently not used.
Returns:
you should return 0, but currently this is not checked

typedef void cache_destructor_t(void *obj, void *notused)

Destructor used to clean up allocated objects before they are returned to the operating system.

Parameters:
obj pointer to the object to initialized.
notused1 This parameter is currently not used.
notused2 This parameter is currently not used.
Returns:
you should return 0, but currently this is not checked


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


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