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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-07-17 12:02
(Received via mailing list)
> 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.
This topic is locked and can not be replied to.