This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Counting amount of memory allocated?
On Mon, Nov 04, 2002 at 10:57:01PM -0600, Chris Lattner wrote:
> Another idea... is there a (perhaps non-portable, perhaps ugly) way to ask
> the libstdc++ pool allocator how much memory is allocated but not used
> yet?
Not really. The free shared area is delimited by two pointers, and when
we need to mark a chunk as taken, the function just subtracts them to find
the memory remaining.
> So is there an api, documented and stable (or not) that I can call to get
> this info?
To see what you have available, right now you'd have to look in
bits/stl_alloc.h. I haven't finished marking up all the internal guts
functions for Doxygen, since that would all change in a memory rework anyhow.
> To compound this, I'd like to make it work on x86 and Solaris, but
> at least are running GCC 3.2. :)
FWIW, the memory pool works in exactly the same fashion on both platforms.
:-)
> If there is absolutely no hope, of course, I will give up... but the pool
> allocator has got to have some way to find out how much memory is "free"
> in it's pools. :)
Yeah, but it's not in a function. (It only happens once, maybe twice, so
there's no real need for a separate function. Storing the free size as a
variable would be a waste of space for the same reason.)
You can add a hack to your local library if you want, as a public member
function in the pool allocator. :-) Look for a line like
__bytes_remaining = _S_end_free - _S_start_free;
and duplicate it.
Phil
--
I would therefore like to posit that computing's central challenge, viz. "How
not to make a mess of it," has /not/ been met.
- Edsger Dijkstra, 1930-2002