Bienvenue sur le site de la LibLapin.
Jetez un coup d'oeil en bas de la page pour choisir votre niveau de documentation en fonction de votre niveau avec la LibLapin.
Pour l'instant, c'est réglé sur 'Manuel complet'. Si c'est votre première fois avec la LibLapin, il vaudrait mieux choisir 'Débutant'.
De même, n'oubliez pas de préciser une version de la bibliothèque.

LibLapin's logo

LibLapin

Pool





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:

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‌_‌b‌u‌n‌n‌y‌_‌p‌o‌o‌l;

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.

Return value

Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:
    Out of memory.

Additional informations

This macro wraps a call to a real function, which is:

t‌_‌b‌u‌n‌n‌y‌_‌p‌o‌o‌l *_b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌p‌o‌o‌l( size_t nmemb, size_t size );




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.

Return value



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 b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌p‌o‌o‌l.

Return value

  • The newly reserved element or NULL if there is no space left.

Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:
    Out of memory.

Additional informations

This macro wraps a call to a real function, which is:

void *_b‌u‌n‌n‌y‌_‌p‌o‌o‌l‌_‌g‌e‌t‌v( t‌_‌b‌u‌n‌n‌y‌_‌p‌o‌o‌l *pool, size_t *id );




INDEX


Description

     Free an element from the pool, making its slot available for future allocation.



INDEX

typedef void (*t‌_‌b‌u‌n‌n‌y‌_‌f‌u‌n‌c‌t‌i‌o‌n)( void *data, void *add_ptr );

Description

     This function pointer is used by b‌u‌n‌n‌y‌_‌p‌o‌o‌l‌_‌f‌o‌r‌e‌a‌c‌h and b‌u‌n‌n‌y‌_‌p‌o‌o‌l‌_‌f‌a‌s‌t‌_‌f‌o‌r‌e‌a‌c‌h as target function single or multi-threaded pool computation.




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




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.

Parameters


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, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


Logs written by this function are tagged with the "container" label.




INDEX