-4

We need to write a C/C++ code that will check whether the memory allocated to the program at the initial and the memory returned to the system is the same or not.

My idea is to find the memory usage at beginning and at ending and subtract.

But how to find the memory usage?

Any other idea please.

Francesco Boi
  • 5,497
  • 8
  • 54
  • 83
kamal
  • 2,358
  • 2
  • 26
  • 35

2 Answers2

1

If you are using the Linux/Unix based OS , you can involve the top utility ans see the difference.no need to reinvent the wheel.

use this in your c code :

uint find_memory_usage()
{

  sprintf(cmd, "/bin/top");
  system(cmd);
}

You can use exec family functions or system call as well for this. This link on SO may also help. or this one.

Community
  • 1
  • 1
Raulp
  • 6,261
  • 11
  • 73
  • 129
-1

I think this code will help you to find size of your c code:

#include<stdio.h>
#include<bios.h>
int main(void)
{
printf("memory size %d kbite\n", biosmemory());
return 0;
}
Malarkodi
  • 326
  • 4
  • 20
  • int main(void) { printf("memory size %d kbite\n", biosmemory()); int *a= new int[10000]; printf("memory size %d kbite\n", biosmemory()); } – kamal May 04 '12 at 07:23
  • 1
    What in the world is `bios.h`? I've never seen that header. – Cody Gray May 04 '12 at 07:45