This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++ code for display memory usage


Hi erik,

[erik]> I want my encryption and decryption program display how much memory
are usage in encryption and decryption process.

That varies depending on your platform.

I recommend looking at the source code for ps (process status) or top, to
glean how they calculate rss, rsz, tsiz, and vsz.

ps and top source code:
http://directory.fsf.org/project/procps/

If you don¹t need to monitor your program from within your program, you may
want to use ps and/or top in a separate process to monitor your
encryption/decryption process¹s footprint.  That would be easier, I suspect.

There are also Microsoft Windows equivalents written by Mark Russinovich,
located at http://sysinternals.com (recently acquired by Microsoft).  I
don't think the source code is available, but you could you those tools in a
separate process to monitor your encryption/decryption process's footprint.

Alternatively, you could intercept malloc (and calloc, realloc, and perhaps
valloc) and sum up all memory allocations on the heap, then call the real
Standard C malloc.  That would give you "all memory ever allocated"
footprint.

If you also wanted to keep track of high water memory allocation, you'd have
to intercept free and figure out how the heap stores the memory block's size
(or record the block size yourself in your intercepted the malloc).

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]