Fixed Size Memory Pool Initialization

The following example demonstrates how to initialize a memory pool for fixed-size memory block 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 block allocation.
     The size of each memory block is set to 16 bytes. */
  if(!stFixedMemInit(MemoryPool, sizeof(MemoryPool), 16))
  {
    printf("Failure during memory pool initialization.\n");
    return 0;
  }

  /* Allocate a 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