Memory Bag Allocator
[Memory Allocation]

Collaboration diagram for Memory Bag Allocator:

Functions

void membag_init (unsigned int align_order)
 Initialize memory manager before use.
size_t membag_get_total (void)
 Total amount of memory in bytes.
size_t membag_get_smallest_free_block_size (void)
 Smallest free block in bytes.
size_t membag_get_largest_free_block_size (void)
 Largest free block size in bytes.
void * membag_alloc (size_t size)
 Allocate memory.
void membag_free (void *ptr)
 Free previously allocated memory.

Detailed Description

The memory bag allocator uses several bags of different size to allocate memory from. The Memory bag allocator will always allocate from the smallest available bag which is equal to or larger than the number of bytes requested. The size of each bag and number of blocks in each bag is user configurable. See membags and membag_init.

The allocator also has statistics functionality for tuning the size of bags and number of blocks within each bag to get the best memory usage for the application. See CONFIG_MEMBAG_USE_TUNING and membag_get_bag_stats

The memory bag allocator always allocates memory from a fixed size bag/pool in the same way as the Memory Pool Allocator. This helps reduce fragmentation compared to an generic allocator that gives exactly the bytes requested. (Reduces external fragmentation)

Compared to the Memory Pool Allocator, the membag allocator has the advantage of providing several bags of different sizes to allocate from which can help reduce the memory usage in applications where different size objects is allocated. (Reduces internal fragmentation)

Allocation of memory with the membag allocator has a max run time which is dependent on the number of bags that is configured.


Function Documentation

void* membag_alloc ( size_t  size  ) 

Allocate memory.

This function finds the smallest bag with available memory that is equal or larger than the number of bytes requested. Memory is then allocated from within that bag.

Parameters:
size Size of buffer to allocate
Returns:
A pointer to the memory block. NULL if no memory was available

Definition at line 270 of file membag.c.

References ARRAY_LEN, membag::block_size, mem_pool_alloc(), and membag::pool.

Referenced by app_memgame_launch(), app_tank_launch(), slide_launch_helper(), wtk_basic_frame_create(), wtk_button_create(), wtk_check_box_create(), wtk_frame_create(), wtk_label_change(), wtk_label_create(), wtk_progress_bar_create(), wtk_radio_button_create(), wtk_radio_group_create(), wtk_slider_create(), and wtk_start_drag().

void membag_free ( void *  ptr  ) 
size_t membag_get_largest_free_block_size ( void   ) 

Largest free block size in bytes.

This searches through all bags to find the largest available block

Returns:
Number of bytes for largest available block

Definition at line 246 of file membag.c.

References ARRAY_LEN, membag::block_size, mem_pool::freelist, and membag::pool.

size_t membag_get_smallest_free_block_size ( void   ) 

Smallest free block in bytes.

This searches through all bags to find the smallest available block

Returns:
Number of bytes for smallest available block

Definition at line 226 of file membag.c.

References ARRAY_LEN, membag::block_size, mem_pool::freelist, and membag::pool.

size_t membag_get_total ( void   ) 

Total amount of memory in bytes.

This function returns the total memory ie. the total number of blocks in each bag multiplied by the block size for each bag.

Returns:
Sum of total bytes in all bags

Definition at line 181 of file membag.c.

References ARRAY_LEN, membag::block_size, and membag::num_blocks.

void membag_init ( const unsigned int  align_order  ) 

Initialize memory manager before use.

This function will allocate all the memory bags using physmem_pool and Memory Pool. Memory sizes and number of blocks are defined with APP_MEMBAG_INITIALIZER defined in app/membag.h for each individual application.

Parameters:
align_order log2 of the minimum object alignment in bytes.
See also:
membags
mem_pool_init_physmem
Precondition:
Not in interrupt context.

Definition at line 163 of file membag.c.

References ARRAY_LEN, and membag_pool_init_physmem().

Generated on Thu Apr 29 14:10:00 2010 for display-demo by  doxygen 1.6.3