Using of many memories

The example below presents how to join several memories into one. Memory blocks will be allocated in all of the specified memories.

#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();


  /* Join memory buffers to make single, cohesive memory pool */
  stMemoryInit(Buffer0, sizeof(Buffer0));
  stMemoryExpand(Buffer0, Buffer1, sizeof(Buffer1));
  stMemoryExpand(Buffer0, Buffer2, sizeof(Buffer2));
  stMemoryExpand(Buffer0, Buffer3, sizeof(Buffer3));


  /* Allocte 5 blocks each for 24 KB*/
  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