Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

nsdynmemLIB.h File Reference

nsdynmemLIB.h File Reference

Dynamical Memory API for library model nsdynmemlib provides access to one default heap, along with the ability to use extra user heaps. More...

Go to the source code of this file.

Data Structures

struct  mem_stat_t
 /struct mem_stat_t /brief Struct for Memory stats Buffer structure More...

Typedefs

typedef struct mem_stat_t mem_stat_t
 /struct mem_stat_t /brief Struct for Memory stats Buffer structure

Enumerations

enum  heap_fail_t {
  NS_DYN_MEM_NULL_FREE, NS_DYN_MEM_DOUBLE_FREE, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID, NS_DYN_MEM_POINTER_NOT_VALID,
  NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED
}
 

Dynamically heap system failure call back event types.

More...

Functions

void ns_dyn_mem_init (void *heap_ptr, ns_mem_heap_size_t h_size, void(*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr)
 Init and set Dynamical heap pointer and length.
int ns_dyn_mem_region_add (void *region_ptr, ns_mem_heap_size_t region_size)
 Add memory region to initialized heap.
void ns_dyn_mem_free (void *heap_ptr)
 Free allocated memory.
void * ns_dyn_mem_temporary_alloc (ns_mem_block_size_t alloc_size)
 Allocate temporary data.
void * ns_dyn_mem_alloc (ns_mem_block_size_t alloc_size)
 Allocate long period data.
const mem_stat_tns_dyn_mem_get_mem_stat (void)
 Get pointer to the current mem_stat_t set via ns_dyn_mem_init.
int ns_dyn_mem_set_temporary_alloc_free_heap_threshold (uint8_t free_heap_percentage, ns_mem_heap_size_t free_heap_amount)
 Set amount of free heap that must be available for temporary memory allocation to succeed.
ns_mem_book_t * ns_mem_init (void *heap_ptr, ns_mem_heap_size_t h_size, void(*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr)
 Init and set Dynamical heap pointer and length.
int ns_mem_region_add (ns_mem_book_t *book, void *region_ptr, ns_mem_heap_size_t region_size)
 Add memory region to initialized heap.
void ns_mem_free (ns_mem_book_t *book, void *heap_ptr)
 Free allocated memory.
void * ns_mem_temporary_alloc (ns_mem_book_t *book, ns_mem_block_size_t alloc_size)
 Allocate temporary data.
void * ns_mem_alloc (ns_mem_book_t *book, ns_mem_block_size_t alloc_size)
 Allocate long period data.
const mem_stat_tns_mem_get_mem_stat (ns_mem_book_t *book)
 Get pointer to the current mem_stat_t set via ns_mem_init.
int ns_mem_set_temporary_alloc_free_heap_threshold (ns_mem_book_t *book, uint8_t free_heap_percentage, ns_mem_heap_size_t free_heap_amount)
 Set amount of free heap that must be available for temporary memory allocation to succeed.

Detailed Description

Dynamical Memory API for library model nsdynmemlib provides access to one default heap, along with the ability to use extra user heaps.

ns_dyn_mem_alloc/free always access the default heap initialised by ns_dyn_mem_init. ns_mem_alloc/free access a user heap initialised by ns_mem_init. User heaps are identified by a book-keeping pointer.

Definition in file nsdynmemLIB.h.


Typedef Documentation

typedef struct mem_stat_t mem_stat_t

/struct mem_stat_t /brief Struct for Memory stats Buffer structure


Enumeration Type Documentation

Dynamically heap system failure call back event types.

Enumerator:
NS_DYN_MEM_NULL_FREE 

ns_dyn_mem_free(), NULL pointer free [obsolete - no longer faulted]

NS_DYN_MEM_DOUBLE_FREE 

ns_dyn_mem_free(), Possible double pointer free

NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID 

Allocate size is 0 or smaller or size is bigger than max heap size.

NS_DYN_MEM_POINTER_NOT_VALID 

ns_dyn_mem_free(), try to free pointer which not at heap sector

NS_DYN_MEM_HEAP_SECTOR_CORRUPTED 

Heap system detect sector corruption.

NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED 

ns_dyn_mem_free(), ns_dyn_mem_temporary_alloc() or ns_dyn_mem_alloc() called before ns_dyn_mem_init()

Definition at line 44 of file nsdynmemLIB.h.


Function Documentation

void* ns_dyn_mem_alloc ( ns_mem_block_size_t  alloc_size )

Allocate long period data.

Space allocate started from end of the heap sector

Parameters:
alloc_sizeAllocated data size
Returns:
0, Allocate Fail
>0, Pointer to allocated data sector.

Definition at line 477 of file nsdynmemLIB.c.

void ns_dyn_mem_free ( void *  heap_ptr )

Free allocated memory.

Parameters:
heap_ptrPointer to allocated memory
Returns:
0, Free OK
<0, Free Fail

Definition at line 637 of file nsdynmemLIB.c.

const mem_stat_t* ns_dyn_mem_get_mem_stat ( void   )

Get pointer to the current mem_stat_t set via ns_dyn_mem_init.

Get pointer to the statistics information, if one is set during the initialization. This may be useful for statistics collection purposes.

Note: the caller may not modify the returned structure.

Returns:
NULL, no mem_stat_t was given on initialization
Pointer to mem_stat_t or NULL.

Definition at line 117 of file nsdynmemLIB.c.

void ns_dyn_mem_init ( void *  heap_ptr,
ns_mem_heap_size_t  h_size,
void(*)(heap_fail_t passed_fptr,
mem_stat_t info_ptr 
)

Init and set Dynamical heap pointer and length.

Parameters:
heap_ptrPointer to dynamically heap buffer
h_sizesize of the heap buffer
passed_fptrpointer to heap error callback function
info_ptrPointer to mem_stat_t for memory statistics. Can be NULL.
Returns:
None

Definition at line 106 of file nsdynmemLIB.c.

int ns_dyn_mem_region_add ( void *  region_ptr,
ns_mem_heap_size_t  region_size 
)

Add memory region to initialized heap.

This method adds memory region to already initialized heap. Method will reset temporary heap threshold to the default value.

Parameters:
region_ptrPointer to memory region to be added
region_sizesize of the region buffer
Returns:
0 on success, <0 in case of errors.

Definition at line 112 of file nsdynmemLIB.c.

int ns_dyn_mem_set_temporary_alloc_free_heap_threshold ( uint8_t  free_heap_percentage,
ns_mem_heap_size_t  free_heap_amount 
)

Set amount of free heap that must be available for temporary memory allocation to succeed.

Temporary memory allocation will fail if system does not have defined amount of heap free.

Note: the caller must set mem_stat_t structure in initialization.

Parameters:
free_heap_percentagepercentage of total heap that must be free for temporary memory allocation. Set free_heap_amount to 0 when this percentage value.
free_heap_amountAmount of free heap that must be free for temporary memory allocation. This value takes preference over percentage parameter value.
Returns:
0 on success, <0 otherwise

Definition at line 299 of file nsdynmemLIB.c.

void* ns_dyn_mem_temporary_alloc ( ns_mem_block_size_t  alloc_size )

Allocate temporary data.

Space allocate started from beginning of the heap sector

Parameters:
alloc_sizeAllocated data size
Returns:
0, Allocate Fail
>0, Pointer to allocated data sector.

Definition at line 482 of file nsdynmemLIB.c.

void* ns_mem_alloc ( ns_mem_book_t *  book,
ns_mem_block_size_t  alloc_size 
)

Allocate long period data.

Space allocate started from end of the heap sector

Parameters:
bookAddress of book keeping structure
alloc_sizeAllocated data size
Returns:
0, Allocate Fail
>0, Pointer to allocated data sector.

Definition at line 467 of file nsdynmemLIB.c.

void ns_mem_free ( ns_mem_book_t *  book,
void *  heap_ptr 
)

Free allocated memory.

Parameters:
bookAddress of book keeping structure
heap_ptrPointer to allocated memory
Returns:
0, Free OK
<0, Free Fail

Definition at line 598 of file nsdynmemLIB.c.

const mem_stat_t* ns_mem_get_mem_stat ( ns_mem_book_t *  book )

Get pointer to the current mem_stat_t set via ns_mem_init.

Get pointer to the statistics information, if one is set during the initialization. This may be useful for statistics collection purposes.

Note: the caller may not modify the returned structure.

Parameters:
bookAddress of book keeping structure
Returns:
NULL, no mem_stat_t was given on initialization
!=0, Pointer to mem_stat_t.

Definition at line 254 of file nsdynmemLIB.c.

ns_mem_book_t* ns_mem_init ( void *  heap_ptr,
ns_mem_heap_size_t  h_size,
void(*)(heap_fail_t passed_fptr,
mem_stat_t info_ptr 
)

Init and set Dynamical heap pointer and length.

Parameters:
heap_ptrPointer to dynamically heap buffer.
h_sizesize of the heap buffer.
passed_fptrpointer to heap error callback function.
info_ptrPointer to mem_stat_t for memory statistics. Can be NULL.
Returns:
Pointer to ns_mem_book_t.

Definition at line 126 of file nsdynmemLIB.c.

int ns_mem_region_add ( ns_mem_book_t *  book,
void *  region_ptr,
ns_mem_heap_size_t  region_size 
)

Add memory region to initialized heap.

This method adds memory region to already initialized heap. Method will reset temporary heap threshold to the default value.

Parameters:
bookAddress of book keeping structure.
region_ptrPointer to memory region buffer.
region_sizesize of the memory region to add
Returns:
0 on success, <0 in case of errors.

Definition at line 179 of file nsdynmemLIB.c.

int ns_mem_set_temporary_alloc_free_heap_threshold ( ns_mem_book_t *  book,
uint8_t  free_heap_percentage,
ns_mem_heap_size_t  free_heap_amount 
)

Set amount of free heap that must be available for temporary memory allocation to succeed.

Temporary memory allocation will fail if system does not have defined amount of heap free.

Note: the caller must set mem_stat_t structure in initialization.

Parameters:
bookAddress of book keeping structure
free_heap_percentagepercentage of total heap that must be free for temporary memory allocation. Set free_heap_amount to 0 when using percentage value.
free_heap_amountAmount of free heap that must be free for temporary memory allocation. This value takes preference over the percentage parameter value.
Returns:
0 on success, <0 otherwise

Definition at line 263 of file nsdynmemLIB.c.

void* ns_mem_temporary_alloc ( ns_mem_book_t *  book,
ns_mem_block_size_t  alloc_size 
)

Allocate temporary data.

Space allocate started from beginning of the heap sector

Parameters:
bookAddress of book keeping structure
alloc_sizeAllocated data size
Returns:
0, Allocate Fail
>0, Pointer to allocated data sector.

Definition at line 472 of file nsdynmemLIB.c.