Fixed size memory pool initialization

The example below presents how to initialize memory pool for fixed size memory blocks allocation.

#include <stdio.h>
#include "ST_API.h"

UINT8 MemoryPool[1024];

int main(void)
{
  PVOID Block;

  /* Initialization */
  arInit();
  stInit();

  /* Initialize memory pool for fixed-size memory blocks allocation.
     Size of the memory block is set to to 16 bytes */
  if(!stFixedMemInit(MemoryPool, sizeof(MemoryPool), 16))
  {
    printf("Failure during memory pool initialization.\n");
    return 0;
  }

  /* Allocate single block */
  Block = stFixedMemAlloc(MemoryPool);
  if(!Block)
  {
    printf("Failure during memory block allocation.\n");
    return 0;
  }

  /* ... */

  /* Free memory block */
  stFixedMemFree(MemoryPool, Block);

  /* ... */

  /* Deinitialization */
  arDeinit();

  return 0;
}
SpaceShadow documentation