Memory bag allocator. More...
#include <assert.h>#include <debug.h>#include <interrupt.h>#include <util.h>#include <physmem.h>#include <string.h>#include <mempool.h>#include <membag.h>#include <app/membag.h>Go to the source code of this file.
Data Structures | |
| struct | membag |
| Internal structure used by membag to keep track of memory. More... | |
Defines | |
| #define | MEMBAG(objsize, nr_objs, pool) { .block_size = objsize, .num_blocks = nr_objs, .phys_pool = pool } |
| Macro for configuring memory bag allocator. | |
Functions | |
| static void | membag_pool_init_physmem (struct membag *mb, unsigned int align_order) |
| void | membag_init (const 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. | |
Variables | |
| static struct membag | membags [] |
| Memory bag. | |
Memory bag allocator.
Copyright (C) 2009 Atmel Corporation. All rights reserved.
Definition in file membag.c.
| #define MEMBAG | ( | objsize, | |||
| nr_objs, | |||||
| pool | ) | { .block_size = objsize, .num_blocks = nr_objs, .phys_pool = pool } |
Macro for configuring memory bag allocator.
MEMBAG is used in user application to define the size and number of blocks for each bag. Please refer to description in membags.
| objsize | Size of each block in this bag | |
| nr_objs | Number of blocks in this bag | |
| pool | Pointer to physmem_pool to allocate this memory from. |
| static void membag_pool_init_physmem | ( | struct membag * | mb, | |
| unsigned int | align_order | |||
| ) | [static] |
For internal use only.
Internal function for initializing each membag
Initialize a membag by getting memory from physmem.
This function essentially does the same as the mem_pool_init_physmem function, but keeps track of start and end of the allocated memory.
| mb | Pointer to membag structure to initialize | |
| align_order | log2 of the minimum object alignment in bytes. |
Definition at line 115 of file membag.c.
References assert, membag::block_size, membag::end, mem_pool_init(), membag::num_blocks, PHYS_MAP_WRBACK, PHYS_MAP_WRBUF, membag::phys_pool, physmem_alloc(), PHYSMEM_ALLOC_ERR, physmem_map(), membag::pool, round_up, and membag::start.
Referenced by membag_init().
Memory bag.
This structure represents one or more different size bags which memory can be allocated from. The fixed size memory bags avoid internal fragmentation when memory is allocated and freed.
The APP_MEMBAG_INITIALIZER macro needs to be defined in app/membags.h in the user application using the MEMBAG macro. Here is an example:
define APP_MEMBAG_INITIALIZER \ MEMBAG(16, 2, &cpu_sram_pool), \ MEMBAG(32, 4, &cpu_sram_pool),
The definition above is used to configure membag to use one bag with 2 blocks of 16 bytes each and another bag with 4 blocks of 32 bytes each. Both bags are here allocated from the cpu_sram_pool.
1.6.3