calculating the memory acquired by the code submitted

Hi Guys! I just want to know that how codechef calculates the memory acquired by the code and show it in the submissions table under Memory column (like, 2.6M;)? And, how could a coder can see the same memory usage in its desktop c++ compiler or IDE.
Thanks!!!

//