Advertisement
bhushan23

memory3.c

Jul 7th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include<unistd.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4.  
  5. #define A_MEGABYTE (1024*1024)
  6. #define PHY_MEM_MEGS 1024
  7.  
  8. int main()
  9. {
  10.   char *s_mem;
  11.   size_t size_to_allocate=A_MEGABYTE;
  12.   int megs_obtained=0;
  13.  
  14.     while(1)
  15.     {
  16.     s_mem=(char *)malloc(size_to_allocate);
  17.     if(s_mem!=NULL)
  18. {
  19. megs_obtained++;
  20. sprintf(s_mem,"hello");
  21. printf("\n%s -now allocated %d mb",s_mem,megs_obtained);
  22. //sleep(1);
  23. }
  24. else
  25. {
  26. printf("\nno more memory to allocate");
  27. exit(EXIT_FAILURE);
  28. }
  29.  
  30.     }
  31. exit(EXIT_SUCCESS);
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement