This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc 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]

Counting amount of memory allocated?


Hi all,

I am trying to find a way to find a reasonably accurate estimate of the
number of bytes allocated on the heap by my program at specific points in
its execution.  The program is written in C++ (compiling with GCC 3.2, and
the included libstdc++, on x86/Linux) and makes extensive use of the STL.

My current idea is to play with the STL allocators to make my containers
use malloc/free directly instead of (the default?) pool allocation.  Once
I have this working, I intend to try to get information from the
malloc/free functions about the amount of memory currently allocated
(fragmentation doesn't concern me, actual RSS isn't important.  I just
want a way to determine the aggregate size of the data structures I'm
allocating for a research paper).

So with that background, here are my questions:

 1. Does this sound like a reasonable approach to take?  Is there any
    easier way to get the information that I'm looking for?

 2. Is there an easier way to get the various STL containers that we are
    using to use the malloc/free allocator without changing a bunch of
    code?  I see macros like __USE_MALLOC in the STL headers, can these
    safely be used?  (binary compatibility is not a problem, I can
    recompile the entire application)

 3. Does G++ operator new and operator new[] call malloc or will I have to
    override those as well?

 4. Is there a way built into libc to access the amount of memory
    allocated?  It appears that mallopt may have some of the information
    that I need, but I'm not sure that it is implemented in libc.  If
    there is no way to get this information from the current malloc
    information, I can just LD_PRELOAD a custom malloc implementation that
    does provide the information, right?

I hope that these lists are the appropriate place to ask these questions.
If not, I'll bug off.  :)

Thanks for the help,

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/


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