Tizen Native API  5.0
Free Queue Group

This provides a mechanism to defer actual freeing of memory data at some time in the future. The main free queue will be driven by the EFL main loop and ensure data is eventually freed.

For debugging and tuning you may set the following environment variables, applicable only to free queues of the default type:

EINA_FREEQ_BYPASS=1/0

Set this environment variable to 1 to immediately bypass the free queue and have all items submitted free with their free function immediately. Set it to 0 to force the free queue to work and delay freeing of items. Note that you can override this by setting count or mem max by eina_freeq_count_max_set() or eina_freeq_mem_max_set() which will disable bypass for that specific free queue. Once bypass is disabled it cannot be re-enabled.

EINA_FREEQ_FILL_MAX=N

This sets the maximum number of bytes to N an item in the free queue may be in size for the free queue to fill it with debugging values like 0x55 in every byte, to ensure you can see what memory has been freed or not when debugging in tools like gdb. Note that this value is actually one greater than the actual maximum, so if this is set to 100 a memory blob of 100 bytes will not be filled but one of 99 bytes in size will be.

EINA_FREEQ_TOTAL_MAX=N

This sets the maximum number of items allowed to N on a free queue by default before it starts emptying the free queue out to make room.

EINA_FREEQ_MEM_MAX=N

This sets the maximum total number of Kb (Kilobytes) of memory allowed on a free queue by default to N Kb worth of data.

EINA_FREEQ_FILL=N

This sets the byte value to write to every byte of an allocation that is added to the free queue when it is added to mark the data as invalid. The default value is 0x55 (85). Memory is only filled if the size of the allocation is less than the max that you can adjust with EINA_FREEQ_FILL_MAX.

EINA_FREEQ_FILL_FREED=N

Memory just before it is actually passed to the free function to be freed will be filled with this pattern value in every byte. The default value is 0x77 (119). Memory is only filled if the size of the allocation is less than the max that you can adjust with EINA_FREEQ_FILL_MAX.

Since (EFL) :
1.19

Functions

Eina_FreeQeina_freeq_main_get (void)
 Get the main loop free queue.
void eina_freeq_ptr_add (Eina_FreeQ *fq, void *ptr, void(*free_func)(void *ptr), size_t size)
 Add a pointer with free function and size to the free queue.
static void eina_freeq_ptr_main_add (void *ptr, void(*free_func)(void *ptr), size_t size)
 Add a pointer to the main free queue.

Typedefs

typedef struct _Eina_FreeQ Eina_FreeQ
typedef enum _Eina_FreeQ_Type Eina_FreeQ_Type
 Type of free queues.

Defines

#define EINA_FREEQ_FREE(ptr)   eina_freeq_ptr_main_add(ptr, NULL, sizeof(*(ptr)))
 Convenience macro for well known structures and types.
#define EINA_FREEQ_N_FREE(ptr, n)   eina_freeq_ptr_main_add(ptr, NULL, sizeof(*(ptr)) * n)
 Convenience macro for well known structures and types.

Define Documentation

#define EINA_FREEQ_FREE (   ptr)    eina_freeq_ptr_main_add(ptr, NULL, sizeof(*(ptr)))

Convenience macro for well known structures and types.

Parameters:
[in]ptrThe pointer to free

This is the same as eina_freeq_ptr_main_add() but the free function is assumed to be the libc free() function, and size is provided by sizeof(*ptr), so it will not work on void pointers or will be inaccurate for pointers to arrays. For arrays please use EINA_FREEQ_ARRAY_FREE()

Since (EFL) :
1.19
#define EINA_FREEQ_N_FREE (   ptr,
 
)    eina_freeq_ptr_main_add(ptr, NULL, sizeof(*(ptr)) * n)

Convenience macro for well known structures and types.

Parameters:
[in]ptrThe pointer to free

This is the same as eina_freeq_ptr_main_add() but the free function is assumed to be the libc free() function, and size is provided by sizeof(*ptr), so it will not work on void pointers. Total size is multiplied by the count n so it should work well for arrays of types.

Since (EFL) :
1.19

Typedef Documentation

A queue of pointers to free in the future. You may create custom free queues of your own to defer freeing, use the main free queue where the mainloop will free things as it iterates, or eina will free everything on shut down.

Type of free queues.

Since (EFL) :
1.19

Enumeration Type Documentation

Type of free queues.

Since (EFL) :
1.19
Enumerator:
EINA_FREEQ_DEFAULT 

Default type of free queue.

Default free queue, any object added to it should be considered freed immediately. Use this kind of freeq for debugging and additional memory safety purposes only.

As this type of free queue is thread-safe, the free functions used must also be thread-safe (e.g.. libc free()).

Since (EFL) :
1.19
EINA_FREEQ_POSTPONED 

Postponed type of free queue.

Postponed free queues behave differently in that objects added to it are not to be considered freed immediately, but rather they are short-lived. Use this to return temporary objects that may be used only in the local scope. The queued objects lifetime ends as soon as the execution comes back to the loop. Objects added to this kind of free queue should be accessed exclusively from the same thread that adds them.

If a thread does not have a loop attached, the application may leak all those objects. At the moment of writing this means only the main loop should use such a free queue.

By default those queues have no memory limit, and will be entirely flushed when the execution comes back to the loop.

This type of free queue is not thread-safe and should be considered local to a single thread.

Since (EFL) :
1.19

Function Documentation

Get the main loop free queue.

Returns:
The main loop free queue.
Since (EFL) :
1.19
void eina_freeq_ptr_add ( Eina_FreeQ fq,
void *  ptr,
void(*)(void *ptr)  free_func,
size_t  size 
)

Add a pointer with free function and size to the free queue.

Parameters:
[in,out]fqThe free queue to add the pointer to
[in]ptrThe pointer to free
[in]free_funcThe function used to free the pointer with
[in]sizeThe size of the data the pointer points to

This adds the given ptr pointer to the queue to be freed later on. The function free_func will be used, or if this is NULL, it is assumed the libc free() function will be used then instead. The size parameter determines the size of the data pointed to, but if this is 0 then no assumptions are made about size and the pointer is considered opaque. A zero sized pointer will not contribute to the total memory usage of items in the queue as well. If size is supplied it must be correct as the memory may be written to for debugging purposes or otherwise inspected or checksummed. Once a pointer is added to the free queue with this API the memory should be considered freed as if the real free_func was called immediately (and it may actually be called immediately if certain environment variables are set). A free queue exists to move the cost of freeing to another point in time when it is more convenient to do so as well as provide some robustness for badly written code that may access memory after freeing. Note that when using tools like valgrind, eina detects this and will also immediately free the data so valgrind's own memory checkers can detect use after free as normal.

Note: The free function must not access the CONTENT of the memory to be freed, or at least consider it invalid and full of garbage. It is already invalid at the moment it is added to the free queue. Just the actual free function may be delayed. The free function may also not access other memory already freed before being added to the free queue. They may do tricks like use memory headers that are outside the memory region to be freed (pass in pointer char *x, then char *header_address = x - 16 to get header information) as this header is not considered part of the free data. This note does not apply if you use a size of 0 for the pointer, but then you lose canary debugging ability when using 0 sized pointers on the free queue.

Since (EFL) :
1.19
static void eina_freeq_ptr_main_add ( void *  ptr,
void(*)(void *ptr)  free_func,
size_t  size 
) [static]

Add a pointer to the main free queue.

Parameters:
[in]ptrThe pointer to free
[in]free_funcThe function used to free the pointer with
[in]sizeThe size of the data the pointer points to

This is the same as eina_freeq_ptr_add() but the main free queue is fetched by eina_freeq_main_get().

Since (EFL) :
1.19