Using Multiple Memory Regions

The following example demonstrates how to combine multiple memory areas into a single pool. Memory blocks will be allocated across all of the specified memory regions.

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

/* Global buffers */
UINT8 Buffer0[65535];
UINT8 Buffer1[65535];
UINT8 Buffer2[65535];
UINT8 Buffer3[65535];

int main(void)
{
  ULONG TotalSize, FreeSize;

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

  /* Combine memory buffers to create a single, cohesive memory pool */
  stMemoryInit(Buffer0, sizeof(Buffer0));
  stMemoryExpand(Buffer0, Buffer1, sizeof(Buffer1));
  stMemoryExpand(Buffer0, Buffer2, sizeof(Buffer2));
  stMemoryExpand(Buffer0, Buffer3, sizeof(Buffer3));

  /* Allocate 5 blocks of 24 KB each */
  stMemoryAlloc(Buffer0, 24 * 1024);
  stMemoryAlloc(Buffer0, 24 * 1024);
  stMemoryAlloc(Buffer0, 24 * 1024);
  stMemoryAlloc(Buffer0, 24 * 1024);
  stMemoryAlloc(Buffer0, 24 * 1024);

  /* Print memory capacity information */
  stMemoryGetInfo(Buffer0, &TotalSize, &FreeSize);
  printf("Total memory size:     %i bytes\n", TotalSize);
  printf("Available memory size: %i bytes\n", FreeSize);

  /* Deinitialization */
  arDeinit();

  return 0;
}
SpaceShadow documentation