Obtaining Memory Information

The example below demonstrates how to retrieve memory capacity information using functions from the alternative C library.

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

#define TEST_COUNT 8

int test(void)
{
  ULONG TotalSize, FreeSize;

  int i;
  PVOID Buffers[TEST_COUNT];

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

  /* Print memory capacity information */
  stMemoryGetInfo(stMemoryPool, &TotalSize, &FreeSize);
  printf("Memory size before allocation: %i/%i\n", FreeSize, TotalSize);

  /* Allocate 8 buffers, 128 bytes each */
  for(i = 0; i < TEST_COUNT; i++)
    Buffers[i] = stMemAlloc(128);

  /* Print memory capacity information */
  stMemoryGetInfo(stMemoryPool, &TotalSize, &FreeSize);
  printf("Memory size after allocation:  %i/%i\n", FreeSize, TotalSize);

  /* Release allocated memory buffers */
  for(i = 0; i < TEST_COUNT; i++)
    stMemFree(Buffers[i]);

  /* Print memory capacity information */
  stMemoryGetInfo(stMemoryPool, &TotalSize, &FreeSize);
  printf("Memory size after release:     %i/%i\n", FreeSize, TotalSize);

  /* Deinitialization */
  arDeinit();

  return 0;
}
SpaceShadow documentation