[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Object's allocated memory

Chad Brewbaker

9/23/2007 4:12:00 PM

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.

6 Answers

Tim Hunter

9/23/2007 6:23:00 PM

0

crb002@gmail.com 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/project...]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]

Konrad Meyer

9/23/2007 7:37:00 PM

0

Quoth crb002@gmail.com:
> 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.

You also might want to fix your Ruby1.6 problem. 1.8.6 has been out for a
while.

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertil...

Eric Hodel

9/24/2007 2:16:00 AM

0

On Sep 23, 2007, at 09:15, crb002@gmail.com 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.

Look at the mem_inspect gem. It has hooks into the GC for Ruby 1.8.

Marshal.dump(foo).size will include all the memory an object
references, including the object's instance variables & etc. The
Array ['x'*1024] takes up only a few bytes of memory, but
Marshal.dump.size says 1032 bytes.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars



Robert Klemme

10/3/2007 7:52:00 AM

0

On 24.09.2007 04:16, Eric Hodel wrote:
> On Sep 23, 2007, at 09:15, crb002@gmail.com 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.
>
> Look at the mem_inspect gem. It has hooks into the GC for Ruby 1.8.
>
> Marshal.dump(foo).size will include all the memory an object references,
> including the object's instance variables & etc. The Array ['x'*1024]
> takes up only a few bytes of memory, but Marshal.dump.size says 1032 bytes.

And that's the problem with all those memory inspection issues:
virtually no automated algorithm (that I know of) can automatically
decide which part of the object graph is supposed to be counted as
belonging to another object. And then there's still aliasing effects,
i.e. objects can be referenced by any number of other objects.

OP, what problem are you trying to solve?

Kind regards

robert

Adam H. Kerman

5/8/2013 4:10:00 AM

0

sctvguy1 <sctvguy1@invalid.net> wrote:

>It is only right that the . . .

Go fuck yourself, troy.

Dave \Crash\ Dummy

5/8/2013 5:17:00 AM

0

On Tue, 7 May 2013 20:40:06 -0400, "Obveeus" <Obveeus@aol.com> wrote:

>
>"Professor Bubba" <bubba@nowhere.edu.invalid> wrote:
>> This is an Audi ad, but it's well worth your time. Runs 2:44.
>>
>> <http://www.youtube.com/watch?feature=player_embedded&v=WPkBy...
>
>That was a funny 'ad'...but I still hate the 'luxury' of a
>trunk/hatch/etc... opening and closing automatically rather than by manual
>effort. Maybe I would feel differently if I was a paraplegic, but since I
>still have mobility I don't want a vehicle that slows everything down.

You got something against paying several hundred bucks to get the
Automagical Doohickey Activator replaced every now and then? =}