-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Matt wrote:
> What if any system calls exist to get the current process' system
> memory usage (including all of the current process' threads) in a
> C/C++ based program?
>
> I'm trying to write unit tests to make sure that my memory allocation
> processes (for Boost "smart pointers") are actually deallocating
> correctly after thousands of dynamic allocations...and my presumption
> is that a current-process-memory-usage "self check" will be very
> useful for my self-running unit test.
>
> I'd prefer cross-platform calls (be it POSIX, unix/linux, Boost C++,
> etc) if I can get them, but I'll take a system specific all (for my
> testing prototype) if I must.
>
> Thanks for any help,
> -Matt
> --
> Remove the "downwithspammers-" text to email me.
Your assumption is incorrect concerning the virtual memory of a process.
A call to free() does not enforce memory mapped to a programs virtual
memory space to be unmapped. I.e. your program might do thousands of
mallocs and the exact number of frees and everything is fine, but your
program's virtual memory size is higher after the free as before the
mallocs.
I think you should take a look at the various tools available for
debugging memory related problems. Under Linux valgrind and efence might
get you started and under Solaris there is libumem (take a look at
umem_debug(3malloc)).
The only thing that could give you a portable solution is to write your
own mallocs and frees and use either sbrk() or mmap() to allocate new
address space. Before doing so, I suggest going to opensolaris.org and
taking a look at the libumem source code.
HTH,
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (SunOS)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org
iD8DBQFEGM5R6U+hp8PKQZIRAqkrAKD0yPAIss7jgj2KZhpvhPDWzH+MbACg7wO7
ViL0h8N9Ktn2TlmdidsrUMM=
=pucF
-----END PGP SIGNATURE-----