0

I have wited a Class ProcReader for generation of the memory snapshot of a process in linux. The ProcReader read the information from /proc/[pid]/status and then generate the memory snapshot for this process. I want test this class. So i write the followed code.

 ShowMemSnapShot();

    unsigned char* pDynArray = NULL;

    pDynArray  = new unsigned char[2048];

 ShowMemSnapShot();

    pDynArray[0] = 1;

    delete [] pDynArray;

 ShowMemSnapShot();

Problem:

The VmPeak and VmSize in \proc[pid]\status have no change. I don't understand this. Why?

Robᵩ
  • 163,533
  • 20
  • 239
  • 308

1 Answers1

1

I am not sure but it maybe something to do with the size of your allocation. The proc entries monitor kernel memory allocations to your process and these are issued in pages of 4K on x86 platforms. Also new, which uses malloc under the hood, probably grabs a bunch of pages when it requires more heap space.

I suggest you allocate a decent chunk of memory - say 1MB

pDynArray = new unsigned char[0x100000];

pablobill
  • 13
  • 1
  • 4
  • i have tried to change array size to 20 Pages = 20 * 4 KB. VmSize has no Change. But if i set the array size bigger then 33 KB. The value of vmsize has a Change. I don't know why? Maybe, There are some reserved Adresse Space in VmSize. – user2983904 Nov 14 '13 at 14:25
  • I have readed in the Internet: VmSize = VmData + VmStk + VmExe + VmLib. But this is not correctly. This is my result in proc/pid/status: – user2983904 Nov 14 '13 at 14:27
  • ********************Before****************** /proc/894/status File Opened nVmPeak=3252 nVmSize=3252 nVmHWM=980 nVmRSS=980 nVmData=192 nVmStk=136 nVmExe=8 nVmLib=2740 nVmPTE=8 nVmSWAP=0 ********************Declared****************** /proc/894/status File Opened nVmPeak=3388 nVmSize=3388 nVmHWM=1032 nVmRSS=1032 nVmData=328 nVmStk=136 nVmExe=8 nVmLib=2740 nVmPTE=8 nVmSWAP=0 ********************Deleted****************** /proc/894/status File Opened nVmPeak=3388 nVmSize=3252 nVmHWM=1036 nVmRSS=1032 nVmData=192 nVmStk=136 nVmExe=8 nVmLib=2740 nVmPTE=8 nVmSWAP=0 – user2983904 Nov 14 '13 at 14:28