|
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. | |
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.
| 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.
| size | Size of buffer to allocate |
Definition at line 270 of file membag.c.
References ARRAY_LEN, membag::block_size, mem_pool_alloc(), and membag::pool.
Referenced by 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 | ) |
Free previously allocated memory.
This function returns a block of memory to the correct memory bag
Definition at line 327 of file membag.c.
References ARRAY_LEN, membag::end, mem_pool_free(), membag::pool, and membag::start.
Referenced by touch_calibrate_task_handler(), win_destroy_children(), wtk_basic_frame_create(), wtk_basic_frame_handler(), wtk_button_create(), wtk_button_handler(), wtk_check_box_create(), wtk_check_box_handler(), wtk_frame_create(), wtk_frame_handler(), wtk_label_change(), wtk_label_create(), wtk_label_handler(), wtk_progress_bar_create(), wtk_progress_bar_handler(), wtk_radio_button_create(), wtk_radio_button_handler(), wtk_slider_create(), wtk_slider_handler(), wtk_start_drag(), and wtk_stop_drag().
| 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
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
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.
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.
| align_order | log2 of the minimum object alignment in bytes. |
Definition at line 163 of file membag.c.
References ARRAY_LEN, and membag_pool_init_physmem().
1.6.3