Get the current system free memory : Memory Allocation « Memory « C / ANSI-C






Get the current system free memory

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  char *p;
  long l;

  l = 0;
  do {
    p = malloc(1000);
    if(p) 
        l += 1000;
  } while(p);

  printf("Approximately %ld bytes of free memory.", l);

  return 0;
}


           
       








Related examples in the same category

1.Find out the address after mallocFind out the address after malloc
2.Allocate memory
3.Store string in allocated memory
4.Allocate memory and reallocateAllocate memory and reallocate
5.Allocate space for a string dynamically, request user input, and then print the string backwardsAllocate space for a string dynamically, request user
   input, and then print the string backwards
6. Allocate memory block: how to use malloc Allocate memory block: how to use malloc
7. Allocate array in memory: how to use calloc Allocate array in memory: how to use calloc
8.Use malloc to allocate memory
9. Reallocate memory block: how to use realloc