The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Memory overhead for small objects: often underestimated

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
Memory overhead for small objects: often underestimated Posted: Apr 11, 2006 2:57 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: Memory overhead for small objects: often underestimated
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

It is well known that the minimal space overhead for a non-immediate object in Ruby is 20 bytes*1. But the overhead will be much higher if your object happens to have instance variables (read: almost always).

Take for instance

class Stupid; attr_accessor :foo end
class Stupid2; attr_accessor :foo, :bar end

o1 = Stupid.new
o1.foo = 1
o2 = Stupid2.new
o2.foo = 1
o2.bar = 2

o1 will take around 20 + 16 + 11 times 4 + 4 times 4 + 3 times roman MALLOC_OVERHEAD = 108/120 and o2 20 + 16 + 11 times 4 + 2 times 4 times 4 + 4 times roman
MALLOC_OVERHEAD = 128/140 bytes, i.e. for objects with under 55 instance variables, the memory footprint is around 100 bytes plus 20 bytes per instance variable --- that's quite heavy.

The exact numbers depend on the behavior of malloc regarding memory alignment and overhead. Doug Lea's malloc, in wide use, takes 8 or 4 bytes per chunk.

Here are some other overheads for Arrays, Hashes, etc. (+M denotes the malloc overhead per allocated chunk, normally 4 or 8 bytes):


Read more...

Read: Memory overhead for small objects: often underestimated

Topic: A humorous quote Previous Topic   Next Topic Topic: A small FS in DATA and a pure Ruby compiler (in the classical sense)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use