Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: rewrite chapter for static heap memory allocation

This GOAL core module provides functions to allocate memory. However GOAL considers the inability of embedded systems to manage memory fragmentation, thus memory allocation is limited to the initialization phase, i.e. it is not possible to allocate or free memory during normal operation by this module. The functions of the Memory Allocator are only allowed in the state GOAL_FSA_INIT.

Info

GOAL memory allocation is limited to startup of the application. This originates in the inability to handle memory fragmentation in embedded systems.

The memory allocator uses a statically defined HEAP, which size is configurable. The memory specified memory block as static heap, which size is configurable by GOAL_CONFIG_HEAP_SIZE. This memory block is either be part of the OS heap or provided by GOAL directly, if the target is an embedded system.

Image AddedImage Added

Memory blocks, which are allocated by goal_mem* functions, are placed in static heap, which is a part of the (dynamic) OS/ GOAL heap.

Static Memory Allocator is initialized by GOAL automatically in stage GOAL_STAGE_MEM_PRE. In consequence, there is no static memory allocation available prior stage GOAL_STAGE_MEM!

The size of the static heap is specified by GOAL_CONFIG_HEAP_SIZE.
The memory block is allocated on base of the alignment specified by the compiler-define GOAL_TARGET_MEM_ALIGN_NET. If a special alignment is required, the Memory Allocator supplies special functions to set the desired alignment for the allocation of memory. The name of these functions have the postfix "Align", e.g. goal_memAllocAlign().
The Memory Allocator allows to check, that only the allocated memory range is in use by a boundary checker. The boundary checker adds bytes around the allocated memory range and fills the bytes with special patterns. The application can check that the patterns are unchanged by calling the function goal_memCheck(). The boundary checker can be activated or deactivated by the compiler-define GOAL_CONFIG_DEBUG_MEM_FENCES and shall only be used during development.
This GOAL core module provides no CM-variables and no command line interface.

  • GOAL files:

    • goal_alloc.[h,c]

  • example:

    • not available

Configuration

The following compiler-defines are available to configure the Memory Allocator:

InfoUsing the stdlib memory allocator is a debugging features and may lead to additional code being linked to the application, thus requiring more resources.

  •  GOAL_CONFIG_MM_EXT (preconfigured by target):

    • 0: use goal memory alocator (default)allocator

    • 1: use stdlib alloc functionality (only for debugging)external (OS) allocation functionality

  • GOAL_TARGET_MEM_ALIGN_NET:

  • GOAL_CONFIG_HEAP_SIZE:

The following compiler-defines are available for debug purposes:

  • GOAL_CONFIG_DEBUG_MEM_FENCES:

    • 0: memory boundary checker is disabled (default)

    • 1: memory boundary checker is enabled

  • GOAL_CONFIG_DEBUG_HEAP_USAGE:

    • 0: debug feature disabled

    • 1: log actual heap usage per component

Implementation guidelines

Allocate a memory range

Create a handle, which is directed to the allocated memory and allocate memory. Static Memory Allocator is initialized by GOAL automatically in stage GOAL_STAGE_MEM_PRE. In consequence, there is no static memory allocation available prior stage GOAL_STAGE_MEM!

Code: create a handle

Code Block
languagec
void *pMem = NULL;    /* memory pointer */
GOAL_STATUS_T res;    /* GOAL return value */
res = goal_memCalloc(&pMem, 2048);
Warning

It is important to utilize the function as shown. Creating a pointer pointer variable (void **ppMem) and passing this to the function as an argument (goal_memCalloc(ppMem, …) will fail.

Table of Contents