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

Detailed Description

Growth-only based heap implementation.

HeapMin is a minimal footprint heap implementation. This module is is designed for applications that only create module instances and generally only allocate memory at runtime, but never delete created instances or free memory explicitly.

When calling HeapMin_create() at runtime, the client is responsible for aligning the buffer.

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti/sysbios/knl/Queue.h>
#include <ti/sysbios/runtime/Error.h>
#include <ti/sysbios/runtime/IHeap.h>
#include <ti/sysbios/runtime/Memory.h>
Include dependency graph for HeapMin.h:

Go to the source code of this file.

Data Structures

struct  HeapMin_Struct
 
struct  HeapMin_Params
 

Macros

#define HeapMin_A_zeroSize   "heap size must be > 0"
 Assert that the heap size is non-zero on the create. More...
 
#define HeapMin_E_freeError   "free() invalid in growth-only HeapMin"
 Error raised if HeapMin_free() is called. More...
 
#define HeapMin_Handle_upCast(handle)   ((IHeap_Handle)(handle))
 cast handle to an IHeap_Handle for use by Memory_alloc, etc. More...
 

Typedefs

typedef struct HeapMin_Struct HeapMin_Object
 
typedef struct HeapMin_StructHeapMin_Handle
 

Functions

void * HeapMin_alloc (void *handle, size_t size, size_t align, Error_Block *eb)
 Allocate a block of memory from the heap. More...
 
void HeapMin_free (void *handle, void *buf, size_t size)
 Free a block of memory back to the heap. More...
 
bool HeapMin_isBlocking (void *handle)
 Can this heap block the caller. More...
 
void HeapMin_getStats (void *handle, Memory_Stats *statBuf)
 get memory stats for a HeapMin object More...
 
HeapMin_Handle HeapMin_create (const HeapMin_Params *params, Error_Block *eb)
 Create a HeapMin heap. More...
 
HeapMin_Handle HeapMin_construct (HeapMin_Struct *obj, const HeapMin_Params *params)
 Construct a HeapMin heap. More...
 
void HeapMin_delete (HeapMin_Handle *handle)
 Delete a HeapMin heap. More...
 
void HeapMin_destruct (HeapMin_Struct *obj)
 Destruct a HeapMin heap. More...
 
void HeapMin_Params_init (HeapMin_Params *prms)
 Initialize the HeapMin_Params structure with default values. More...
 
HeapMin_Handle HeapMin_Object_first (void)
 return handle of the first HeapMin on HeapMin list More...
 
HeapMin_Handle HeapMin_Object_next (HeapMin_Handle heap)
 return handle of the next HeapMin on HeapMin list More...
 

Macro Definition Documentation

§ HeapMin_A_zeroSize

#define HeapMin_A_zeroSize   "heap size must be > 0"

Assert that the heap size is non-zero on the create.

§ HeapMin_E_freeError

#define HeapMin_E_freeError   "free() invalid in growth-only HeapMin"

Error raised if HeapMin_free() is called.

This error is only raised if a HeapMin_free() is called and the HeapMin.freeError configuration parameter is set to true.

§ HeapMin_Handle_upCast

#define HeapMin_Handle_upCast (   handle)    ((IHeap_Handle)(handle))

cast handle to an IHeap_Handle for use by Memory_alloc, etc.

Parameters
handleheap handle
Return values
IHeap_Handle

Typedef Documentation

§ HeapMin_Object

§ HeapMin_Handle

typedef struct HeapMin_Struct * HeapMin_Handle

Function Documentation

§ HeapMin_alloc()

void* HeapMin_alloc ( void *  handle,
size_t  size,
size_t  align,
Error_Block eb 
)

Allocate a block of memory from the heap.

Precondition
The alignment must be a power of 2.

§ HeapMin_free()

void HeapMin_free ( void *  handle,
void *  buf,
size_t  size 
)

Free a block of memory back to the heap.

This is a growth only heap. Calling the HeapMin_free function will result in a HeapMin_E_freeError error unless the HeapMin.freeError configuration parameter is set to false.

§ HeapMin_isBlocking()

bool HeapMin_isBlocking ( void *  handle)

Can this heap block the caller.

HeapMin always returns false since it never blocks on a resource.

Parameters
handleheap handle
Return values
alwaysreturns false

§ HeapMin_getStats()

void HeapMin_getStats ( void *  handle,
Memory_Stats statBuf 
)

get memory stats for a HeapMin object

Parameters
handleheap handle
statBufpointer to a Memory_Stats object

§ HeapMin_create()

HeapMin_Handle HeapMin_create ( const HeapMin_Params params,
Error_Block eb 
)

Create a HeapMin heap.

This heap is a growth-only heap that is intended to be used by systems that never delete objects or free memory. Objects can be created at runtime based on values determined at runtime, but objects can not be deleted.

Parameters
paramsoptional parameters
eberror block
Return values
HeapMinhandle (NULL on failure)

§ HeapMin_construct()

HeapMin_Handle HeapMin_construct ( HeapMin_Struct obj,
const HeapMin_Params params 
)

Construct a HeapMin heap.

HeapMin_construct is equivalent to HeapMin_create except that the HeapMin_Struct is pre-allocated.

Parameters
objpointer to a HeapMin object
paramsoptional parameters
Return values
HeapMinhandle (NULL on failure)

§ HeapMin_delete()

void HeapMin_delete ( HeapMin_Handle handle)

Delete a HeapMin heap.

Note that HeapMin_delete takes a pointer to a HeapMin_Handle which enables HeapMin_delete to set the HeapMin handle to NULL.

Parameters
handlepointer to a HeapMin handle

§ HeapMin_destruct()

void HeapMin_destruct ( HeapMin_Struct obj)

Destruct a HeapMin heap.

Parameters
objpointer to a HeapMin objects

§ HeapMin_Params_init()

void HeapMin_Params_init ( HeapMin_Params prms)

Initialize the HeapMin_Params structure with default values.

HeapMin_Params_init initializes the HeapMin_Params structure with default values. HeapMin_Params_init should always be called before setting individual parameter fields. This allows new fields to be added in the future with compatible defaults – existing source code does not need to change when new fields are added.

Parameters
prmspointer to uninitialized params structure

§ HeapMin_Object_first()

HeapMin_Handle HeapMin_Object_first ( void  )

return handle of the first HeapMin on HeapMin list

Return the handle of the first HeapMin on the create/construct list. NULL if no HeapMins have been created or constructed.

Return values
HeapMinhandle

§ HeapMin_Object_next()

HeapMin_Handle HeapMin_Object_next ( HeapMin_Handle  heap)

return handle of the next HeapMin on HeapMin list

Return the handle of the next HeapMin on the create/construct list. NULL if no more HeapMins are on the list.

Parameters
heapHeapMin handle
Return values
HeapMinhandle
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale