# Re: What is the fastest way to convert a object?

**URL:** <https://www.ruby-forum.com/t/re-what-is-the-fastest-way-to-convert-a-object/109622>\
**Category:** Ruby\
**Created:** [July 17, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/re-what-is-the-fastest-way-to-convert-a-object/109622 "2007-07-17T12:02:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [July 17, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/re-what-is-the-fastest-way-to-convert-a-object/109622/1 "2007-07-17T12:02:47Z")

</div>

> Yes, this is my problem, too.  
> I need an efficient way to transfer data model, but it seems that drb is  
> not just “transfer”.  
> Even if I ignore the object size thing, still, calling a drbObject’s  
> complex method is an issue.

DRb uses Marshal to convert objects into a stream of bytes. It then adds  
a tiny wrapper (basically 4 bytes giving the length)

So if you want to see how big an object is when sent via DRb, just use  
Marshal explicitly:

irb(main):001:0\> class Test; attr\_accessor :foo; end  
=\> nil  
irb(main):002:0\> a = Test.new; a.foo = [“this”, “thing”]  
=\> [“this”, “thing”]  
irb(main):003:0\> b = Marshal.dump(a)  
=\> “\004\010o:\tTest\006:\t@foo[\a”\tthis"\nthing"  
irb(main):004:0\> b.size  
=\> 31  
irb(main):005:0\> c = Marshal.load(b)  
=\> #\<Test:0xb7cc2994 @foo=[“this”, “thing”]\>  
irb(main):006:0\>

In the above example, b contains the marshalled version of object a,  
which  
in turn contains another object (an array), which in turn contains two  
strings. As you can see, this entire compound object takes 31 bytes on  
the  
wire.

HTH,

Brian.
