SYS/BIOS  7.00
Data Structures | Macros | Typedefs | Functions | Variables
Memory.h File Reference

Detailed Description

Static and run-time memory manager.

All memory allocations are performed either by Memory_alloc (or its varients Memory_calloc, Memory_valloc, etc.) at run-time.

Run-time memory management is performed by modules that implement the ti/sysbios/runtime/IHeap.h interface. The Memory module itself simply provides a common interface for any variety of system and application specific memory management policies implemented by IHeap modules.

Heap instances are created statically or dynamically via heap specific create functions and these instances are then passed as an input parameter to the Memory calls that have an IHeap_Handle parameter.

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti/sysbios/runtime/Error.h>
#include <ti/sysbios/runtime/IHeap.h>
Include dependency graph for Memory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Memory_Stats
 Memory heap statistics. More...
 

Macros

#define Memory_Q_BLOCKING   (1)
 Blocking quality. More...
 

Typedefs

typedef void *(* IHeap_AllocFxn) (void *, size_t, size_t, Error_Block *)
 
typedef void(* IHeap_FreeFxn) (void *, void *, size_t)
 
typedef bool(* IHeap_IsBlockingFxn) (void *)
 
typedef void(* IHeap_GetStatsFxn) (void *, Memory_Stats *)
 

Functions

void * Memory_alloc (IHeap_Handle heap, size_t size, size_t align, Error_Block *eb)
 Allocate a block of memory from a heap. More...
 
void * Memory_calloc (IHeap_Handle heap, size_t size, size_t align, Error_Block *eb)
 Allocate a block of memory from a heap and zero out the contents. More...
 
void Memory_free (IHeap_Handle heap, void *block, size_t size)
 Frees the space if the heap manager offers such functionality. More...
 
size_t Memory_getMaxDefaultTypeAlign (void)
 Return the largest alignment required by the target. More...
 
void Memory_getStats (IHeap_Handle heap, Memory_Stats *stats)
 Obtain statistics from a heap. More...
 
bool Memory_query (IHeap_Handle heap, int qual)
 Test for a particular heap quality. More...
 
IHeap_Handle Memory_getDefaultHeap (void)
 Get the default heap handle. More...
 
void Memory_setDefaultHeap (IHeap_Handle heap)
 Set the default heap handle. More...
 
void * Memory_valloc (IHeap_Handle heap, size_t size, size_t align, char value, Error_Block *eb)
 Allocate a block of memory from a heap and initialize the contents to the value specified. More...
 

Variables

IHeap_Handle Memory_defaultHeapInstance
 The default heap. More...
 

Macro Definition Documentation

§ Memory_Q_BLOCKING

#define Memory_Q_BLOCKING   (1)

Blocking quality.

Heaps with this "quality" may cause the calling thread to block; i.e., suspend execution until another thread leaves the gate.

Typedef Documentation

§ IHeap_AllocFxn

typedef void*(* IHeap_AllocFxn) (void *, size_t, size_t, Error_Block *)

§ IHeap_FreeFxn

typedef void(* IHeap_FreeFxn) (void *, void *, size_t)

§ IHeap_IsBlockingFxn

typedef bool(* IHeap_IsBlockingFxn) (void *)

§ IHeap_GetStatsFxn

typedef void(* IHeap_GetStatsFxn) (void *, Memory_Stats *)

Function Documentation

§ Memory_alloc()

void* Memory_alloc ( IHeap_Handle  heap,
size_t  size,
size_t  align,
Error_Block eb 
)

Allocate a block of memory from a heap.

The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.

A value of 0 denotes maximum default type alignment.

If the allocation was successful, Memory_alloc() returns non-NULL pointer to the allocated and uninitialized block; otherwise it returns NULL and the error block will indicate the cause of the error.

Parameters
heapheap from which the memory is allocated
sizerequested memory block size (in MADUs)
alignalignment (in MADUs) of the block of memory
ebpointer to error block
Return values
pointerto allocated memory (NULL on failure)

§ Memory_calloc()

void* Memory_calloc ( IHeap_Handle  heap,
size_t  size,
size_t  align,
Error_Block eb 
)

Allocate a block of memory from a heap and zero out the contents.

The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.

A value of 0 denotes maximum default type alignment.

If the allocation was successful, Memory_calloc() returns non-NULL pointer to the allocated and initialized block; otherwise it returns NULL and the error block will indicate the cause of the error.

Parameters
heapheap from which the memory is allocated
sizerequested memory block size (in MADUs)
alignalignment (in MADUs) of the block of memory
ebpointer to error block
Return values
pointerto allocated memory (NULL on failure)

§ Memory_free()

void Memory_free ( IHeap_Handle  heap,
void *  block,
size_t  size 
)

Frees the space if the heap manager offers such functionality.

The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.

Parameters
heapheap that the block of memory will be freed back to.
blockblock of memory to free back to the heap
sizesize (in MADUs) of the block of memory to free.

§ Memory_getMaxDefaultTypeAlign()

size_t Memory_getMaxDefaultTypeAlign ( void  )

Return the largest alignment required by the target.

Returns the largest alignment required for all the standard base types supported by the current target

Return values
Returnstarget-specific alignment in MADUs.

§ Memory_getStats()

void Memory_getStats ( IHeap_Handle  heap,
Memory_Stats stats 
)

Obtain statistics from a heap.

The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.

Parameters
heapthe heap to get the statistics from
statsthe output buffer for the returned statistics

§ Memory_query()

bool Memory_query ( IHeap_Handle  heap,
int  qual 
)

Test for a particular heap quality.

There currently is only one quality, namely Memory_Q_BLOCKING.

The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is queried

For example: Memory_Q_BLOCKING.

If heap has the "qual" quality, this method returns true, otherwise it returns false.

Parameters
heapthe heap to query
qualquality to test
Return values
quality

§ Memory_getDefaultHeap()

IHeap_Handle Memory_getDefaultHeap ( void  )

Get the default heap handle.

When Memory_alloc(), etc. are passed 'NULL' as the heap parameter, the default heap is used. This API can be used to get the default heap handle.

§ Memory_setDefaultHeap()

void Memory_setDefaultHeap ( IHeap_Handle  heap)

Set the default heap handle.

When Memory_alloc(), etc. are passed 'NULL' as the heap parameter, the default heap is used. This API can be used to set this default handle to a user defined heap. Note that most use cases can be managed with the BIOS.heapType and BIOS.heapSize configuration parameters.

§ Memory_valloc()

void* Memory_valloc ( IHeap_Handle  heap,
size_t  size,
size_t  align,
char  value,
Error_Block eb 
)

Allocate a block of memory from a heap and initialize the contents to the value specified.

The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.

A value of 0 denotes maximum default type alignment.

If the allocation was successful, Memory_valloc() returns non-NULL pointer to the allocated and initialized block; otherwise it returns NULL and the error block will indicate the cause of the error.

Parameters
heapheap from which the memory is allocated
sizerequested memory block size (in MADUs)
alignalignment (in MADUs) of the block of memory
valuevalue to initialize the contents of the block
ebpointer to error block
Return values
pointerto allocated memory (NULL on failure)

Variable Documentation

§ Memory_defaultHeapInstance

IHeap_Handle Memory_defaultHeapInstance

The default heap.

If no heap is specified in the Memory module's methods (i.e. heap == NULL) defaultHeapInstance is used.

© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale