From: Ron Jeffries Date: 2002-03-07T08:57:50+09:00 Subject: Re: object size and overhead. On Wed, 06 Mar 2002 22:10:33 GMT, Matt Armstrong wrote: >Ron Jeffries writes: > > >[...] > >> I see 7 objects per set, so 60,000,000 / 600,000 = 100 bytes per >> object, which seems a bit rough. >> >> So my question is ... what's the overhead in a Ruby object. And my second >> question is: ask what I /should/ have asked and answer that too. > >Every ruby object has the same overhead since every Ruby object is >allocated from the same sized piece of memory (called an RVALUE in the >C source). > >It is 20 bytes. > >This jives with my research. A 600,000 element array of zeroes took >3.5 megs on my machine. A 600,000 element arrays of "" took 15 megs. >That's a difference of 12,058,624 bytes / 600,000 = 20.098 bytes for >each extra String object. This is much like I would expect. I can't figure out why I was at 200 meg and climbing with my 100,000 records. > >If you're using ruby 1.7 and use things like Array#<< and String#<<, >then be aware that the array and string internal memory buffers double >in size whenever the array needs to grow. This makes things a lot >faster, but can waste some memory. Yes, but on the way to 100,000 elements there are only at most 17 doublings and a total storage usage of 200K. Something took me to 60 megabytes. Weird. I guess I need to find out how to track memory utilization ... something isn't right. Thanks, Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.