Bug #8984

ObjectSpace.memsize_of(obj) should return with sizeof(RVALUE)

Added by Koichi Sasada over 1 year ago. Updated about 1 month ago.

[ruby-core:57666]
Status:Closed
Priority:Normal
Assignee:Koichi Sasada
ruby -v:- Backport:2.0.0: WONTFIX, 2.1: UNKNOWN

Description

Now, ObjectSpace.memsize_of(obj) return without sizeof(RVALUE).
For example, ObjectSpace.memsize_of('foo') returns 0 because shorter string are embedded in RVALUE.

Proposal is returning the size including sizeof(RVALUE).
If we introduce variable RVALUE size (*1), then it will help.

*1: for example, T_FLOAT only use sizeof(double).
Only 2 words (or 1 word on 64bit enviornment) are needed.

Question is: it breaks compatibility, but anyone care about it?

Another option is to add optional parameter. memsize_of(obj, include_rvalue: true), etc.

Associated revisions

Revision 48846
Added by Koichi Sasada 3 months ago

  • ext/objspace/objspace.c: ObjectSpace.memsize_of(obj) returns with sizeof(RVALUE). [Bug #8984]
  • gc.c (obj_memsize_of): ditto.
  • NEWS: add a NEWS entry.
  • test/objspace/test_objspace.rb: catch up this fix.
  • test/ruby/test_file_exhaustive.rb: ditto.

Revision 48846
Added by Koichi Sasada 3 months ago

  • ext/objspace/objspace.c: ObjectSpace.memsize_of(obj) returns with sizeof(RVALUE). [Bug #8984]
  • gc.c (obj_memsize_of): ditto.
  • NEWS: add a NEWS entry.
  • test/objspace/test_objspace.rb: catch up this fix.
  • test/ruby/test_file_exhaustive.rb: ditto.

History

#1 Updated by Sam Saffron over 1 year ago

Personally I have only ever seen mention of this in http://stackoverflow.com/questions/10068018/memory-size-of-a-hash-or-other-object

I googled pretty hard and all I saw was wonderful pictures of tenderlove and a slightly less accurate description here: http://www.slideshare.net/tenderlove/hidden-gems-of-ruby-19 http://imgur.com/yeFYtiM

I think we should break compatibility here and properly document, cause people just have no idea about this now

#2 Updated by Hiroshi SHIBATA about 1 year ago

  • Target version changed from 2.1.0 to current: 2.2.0

#3 Updated by Koichi Sasada 3 months ago

  • % Done changed from 0 to 100
  • Status changed from Assigned to Closed

Applied in changeset r48846.


  • ext/objspace/objspace.c: ObjectSpace.memsize_of(obj) returns with sizeof(RVALUE). [Bug #8984]
  • gc.c (obj_memsize_of): ditto.
  • NEWS: add a NEWS entry.
  • test/objspace/test_objspace.rb: catch up this fix.
  • test/ruby/test_file_exhaustive.rb: ditto.

#4 Updated by Usaku NAKAMURA about 1 month ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 2.0.0: WONTFIX, 2.1: UNKNOWN

Also available in: Atom PDF