The Bunny Pool is a fast container to store
short-live elements all of the same type.
Its inner design improve greatly creation and deletion
operations, which are faster than for list, and still,
bring the speed of arrays when it came to browsing
and random access.
Its drawback:
- It is fixed in size and cannot be resize.
- It is quite volatile, this point is detailed after.
The pool module header is lapin/container/pool.h.
typedef struct s_bunny_pool
{
 
const size_t nmemb;
 
const size_t elemsize;
 
const size_t nbr_occupied;
 
void *
const data[];
}
t_bunny_pool;
Description
  This partially abstract structure represents a pool of
pre-reserved elements.
Attributes
-
const size_t nmemb:
  The maximum size in elements of the pool.
-
const size_t elemsize:
  The size in bytes of a single element.
-
const size_t nbr_occupied:
  How many elements are currently reserved inside
the pool.
-
void * const data[]:
  An array of pointer to the stored data. You can safely
browse this field from index 0 to index nbr_occupied - 1.
INDEX
Description
  Create a Pool for nmemb elements of type.
INDEX
Description
  Delete the sent pool.
INDEX
Description
  Return the maximum size of the sent pool.
Return value
-
The maximum size of the sent pool.
INDEX
Description
  Return the current size of the sent pool, how
many elements are currently reserved.
Return value
-
The current size of the sent pool, how many
elements are currently reserved.
INDEX
Description
  Return if the sent pool is empty.
Return value
-
true if the sent pool is empty, else false.
INDEX
Description
  Return the size of a single elements stored inside the sent pool.
Return value
-
The size of a single element from the sent pool.
INDEX
Description
  Return the index of the sent element.
Caution: If the pointer is invalid, this will return an invalid
value, your program may even crash.
INDEX
Description
  Remove all elements from the pool, making it empty.
INDEX
Description
  Get a new element from the pool. The sent
type must
match the type sent when creating the pool with
bunny_new_pool.
Return value
-
The newly reserved element or NULL if there is no space left.
INDEX
Description
  Free an element from the pool, making its slot available for future
allocation.
INDEX
Description
  Execute the sent function on each element of the sent pool
Give to the executed function param as second parameter, data
from pool being the first.
Parameters
-
t_bunny_pool *pool:
  The collection that will be use.
-
t_bunny_function function:
  The function that will be called for each element of the sent
pool. Parameters will be an element from the array and param.
-
void *param:
  A data that will be sent as second parameter of function.
INDEX
Description
  Execute the sent function on each element of the sent pool
with threads from the threadpool threadpool. Give to the executed function
param as second parameter, data from pool being the first.
Return value
-
On complete success, the function returns true.
-
On failure, it returns false. Failire indicates all
datas were not treated by threads, some of them may have been
treated by the main thread because of a thread pool memory exhaustion.
Elements are always all computed.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX