Atmel Software Framework

membag.c File Reference

Memory bag allocator.

Copyright (C) 2012-2015 Atmel Corporation. All rights reserved.

#include <compiler.h>
#include <membag.h>
#include "conf_membag.h"

Data Structures

struct  membag
 Internal structure used by membag to keep track of memory, with maximum 32 blocks per membag. More...
 

Macros

#define ARRAY_LEN(a)   (sizeof(a) / sizeof((a)[0]))
 

Functions

void * membag_alloc (const size_t size)
 Allocate a memory block via a block from the Membag pool. More...
 
void membag_free (const void *ptr)
 Free a previously allocated memory block from the Membag pool. More...
 
size_t membag_get_largest_free_block_size (void)
 Determine the largest available block size. More...
 
size_t membag_get_smallest_free_block_size (void)
 Determine the smallest available block size. More...
 
size_t membag_get_total (void)
 Determine the total memory from all membags. More...
 
size_t membag_get_total_free (void)
 Determine the total remaining free memory from all membags. More...
 
void membag_init (void)
 Initialize the membag system. More...
 

Variables

static struct membag membag_list []
 Array of available membags, provided by the user in the applications conf_membag.h header file. More...
 
static uint8_t membag_pool [CONF_MEMBAG_POOL_SIZE]
 Static address space which is split up into usable chunks by membag. More...
 

#define ARRAY_LEN (   a)    (sizeof(a) / sizeof((a)[0]))

struct membag membag_list[]
static
Initial value:
= {
}
#define CONF_MEMBAG_ARRAY
Definition: services/wtk/example2_icon/conf_membag.h:51

Array of available membags, provided by the user in the applications conf_membag.h header file.

Example:

#define CONF_MEMBAG_ARRAY \
MEMBAG(32, 4), \
MEMBAG(16, 2),
#define CONF_MEMBAG_POOL_SIZE \
MEMBAG_SIZE(32, 4) + \
MEMBAG_SIZE(16, 2)
uint8_t membag_pool[CONF_MEMBAG_POOL_SIZE]
static

Static address space which is split up into usable chunks by membag.

For configuration details, see membag_list.

Referenced by membag_init().