Re: Object's allocated memory
- From: Tim Hunter <TimHunter@xxxxxxxxx>
- Date: Mon, 24 Sep 2007 03:23:26 +0900
crb002@xxxxxxxxx wrote:
I have an application where I need to sort objects based on their
memory footprint. What is the easiest way to get this information
from Ruby1.6 ? I have no problem with having to call some C functions
to get this info.
The hack Marshal.dump(foo).size() would work, but since this might be
called often I need an elegant solution.
Hmmm...tricky. Seems like you'd want a #footprint method in every class that accumlated the memory footprint of the object. That method would be written in C so it could account for the sizes of the C structure (RString, RArray, etc.) that represents the object. You'll have to make some rules about collections. Does the footprint of an array include the footprints of the object in the array, or just the container? Same for Hash, etc. Then there's going to be some objects for which you just can't get an accurate count. I suspect it would be hard to find out how much memory is allocated to buffers for an open file, for example (if that matters). And I know for a fact that you can't find out how much memory is allocated to one of RMagick's Magick::Image objects. Even the Marshal hack wouldn't work there since the on-disk size doesn't have to match the in-memory size. Of course your application may not use such objects, but they exist.
--
RMagick OS X Installer [http://rubyforge.org/projects/rmagick/]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618]
RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]
.
- References:
- Object's allocated memory
- From: crb002
- Object's allocated memory
- Prev by Date: I'm looking for this certain ruby blog software
- Next by Date: Re: Recent Criticism about Ruby (Scalability, etc.)
- Previous by thread: Object's allocated memory
- Next by thread: Does open("| #{cmd}", "r") work in Windows?
- Index(es):
Relevant Pages
|