All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kzc_object_pool.h File Reference

Object pool. More...

Classes

struct  KzcObjectPoolConfiguration
 Tells the object pool how to create, reset and delete objects. More...
 

Typedefs

typedef kzsError(* KzcObjectPoolCreateFunction )(const struct KzcMemoryManager *memoryManager, void *userData, void **out_object)
 A function that creates a new object for the pool. More...
 
typedef kzsError(* KzcObjectPoolResetFunction )(void *object, void *userData)
 A function that resets an object to a clean state, ready to be reused. More...
 
typedef kzsError(* KzcObjectPoolDeleteFunction )(void *object, void *userData)
 A function that deletes an object. More...
 

Functions

kzsError kzcObjectPoolCreate (const struct KzcMemoryManager *memoryManager, struct KzcObjectPoolConfiguration configuration, struct KzcObjectPool **out_objectPool)
 Creates an object pool for a given object type. More...
 
kzsError kzcObjectPoolDelete (struct KzcObjectPool *objectPool)
 Destroys an object pool. More...
 
kzsError kzcObjectPoolAcquire (const struct KzcObjectPool *objectPool, void **out_object)
 Acquires an object from the pool. More...
 
kzsError kzcObjectPoolRelease (const struct KzcObjectPool *objectPool, void *object)
 Releases an object back to the pool. More...
 

Detailed Description

Object pool.

Object pools can be used to reuse objects of a specified type. The object pool can grow as necessary and resets its objects when released back to the pool.

Copyright 2008-2020 by Rightware. All rights reserved.

Typedef Documentation

typedef kzsError(* KzcObjectPoolCreateFunction)(const struct KzcMemoryManager *memoryManager, void *userData, void **out_object)

A function that creates a new object for the pool.

typedef kzsError(* KzcObjectPoolResetFunction)(void *object, void *userData)

A function that resets an object to a clean state, ready to be reused.

typedef kzsError(* KzcObjectPoolDeleteFunction)(void *object, void *userData)

A function that deletes an object.

Function Documentation

kzsError kzcObjectPoolCreate ( const struct KzcMemoryManager memoryManager,
struct KzcObjectPoolConfiguration  configuration,
struct KzcObjectPool **  out_objectPool 
)

Creates an object pool for a given object type.

At destruction the object pool destroys all its currently unused objects. The user is responsible for destroying objects that have not been returned to the pool at this time.

Parameters
memoryManagerThe memory manager used for allocating the pool and its objects.
configurationDefines how objects are created, reseted and destroyed.
kzsError kzcObjectPoolDelete ( struct KzcObjectPool objectPool)

Destroys an object pool.

kzsError kzcObjectPoolAcquire ( const struct KzcObjectPool objectPool,
void **  out_object 
)

Acquires an object from the pool.

kzsError kzcObjectPoolRelease ( const struct KzcObjectPool objectPool,
void *  object 
)

Releases an object back to the pool.