Data Structures | Macros | Typedefs | Functions

This group provides a generic container. More...

Data Structures

struct  _Eina_Trash
 The structure type for a generic container of an unused allocated pointer. More...
 

Macros

#define EINA_TRASH_CLEAN(trash, data)   while ((data = eina_trash_pop(trash)))
 Definition for a macro to remove all the pointers from the trash. More...
 

Typedefs

typedef struct _Eina_Trash Eina_Trash
 The type for structure _Eina_Trash.
 

Functions

static void eina_trash_init (Eina_Trash **trash)
 Initializes a trash before using it. More...
 
static void eina_trash_push (Eina_Trash **trash, void *data)
 Pushes an unused pointer in the trash instead of freeing it. More...
 
static void * eina_trash_pop (Eina_Trash **trash)
 Pops an available pointer from the trash if possible. More...
 

Detailed Description

This group provides a generic container.

Macro Definition Documentation

◆ EINA_TRASH_CLEAN

#define EINA_TRASH_CLEAN (   trash,
  data 
)    while ((data = eina_trash_pop(trash)))

Definition for a macro to remove all the pointers from the trash.

This macro allows the cleaning of trash in an easy way. It removes all the pointers from trash until it's empty.

Parameters
[in,out]trashThe trash to clean
[out]dataThe pointer extracted from the trash
Note
This macro can be used for freeing the data in the trash, like in the following example:
Eina_Trash *trash = NULL;
char *data;
// trash is filled with a pointer to some duped strings.
EINA_TRASH_CLEAN(&trash, data)
free(data);
#define EINA_TRASH_CLEAN(trash, data)
Definition for a macro to remove all the pointers from the trash.
Definition: eina_trash.h:111
The structure type for a generic container of an unused allocated pointer.
Definition: eina_trash.h:41
Note
This macro is useful when you implement some memory pool.

Function Documentation

◆ eina_trash_init()

static void eina_trash_init ( Eina_Trash **  trash)
inlinestatic

Initializes a trash before using it.

This function just set to zero the trash to correctly initialize it.

Parameters
[in]trashThe trash
Note
You can just set *trash to NULL and you will have the same result.

◆ eina_trash_push()

static void eina_trash_push ( Eina_Trash **  trash,
void *  data 
)
inlinestatic

Pushes an unused pointer in the trash instead of freeing it.

Instead of freeing a pointer and put pressure on malloc/free you can push it in a trash for a later use. This function just provide a fast way to push a now unused pointer into a trash.

Parameters
[in,out]trashA pointer to an Eina_Trash
[in]dataAn unused pointer big enough to put a (void*)
Note
Do not use the pointer after insertion or bad things will happens.
This trash will not resize, nor do anything with the size of the region pointed by data, so it's your duty to manage the size.

Referenced by eina_quadtree_del(), eina_rectangle_free(), eina_rectangle_pool_release(), and eina_safepointer_unregister().

◆ eina_trash_pop()

static void * eina_trash_pop ( Eina_Trash **  trash)
inlinestatic

Pops an available pointer from the trash if possible.

Instead of calling malloc, and putting pressure on malloc/free you can recycle the content of the trash, if it's not empty.

Parameters
[in]trashA Eina_Trash handle
Note
This trash will not resize, nor do anything with the size of the region pointed by pointer inside the trash, so it's your duty to manage the size of the returned pointer.

Referenced by eina_quadtree_add(), eina_quadtree_free(), eina_rectangle_new(), eina_rectangle_pool_free(), and eina_rectangle_pool_request().