I'm using Marshal.dump
to serialize an array of objects, I need to get the size (in KB) of the returned value. Any ideas how to do that?
Since the output of Marshal.dump
is a string, you can just ask for the length of that. The safest way to do this is to ask for bytesize
:
dumped = Marshal.dump(array)
kb = dumped.bytesize / 1024
The bytesize
method always returns the length of a string in bytes, whereas length
returns the length of the string in characters. The two values can differ if you use a multi-byte encoding method like UTF-8.
What about kbytes = Marshal.dump(ary_of_objs).size / 1000.0
?
var = Base64.encode64(Marshal.dump(@result))
var.size
is life saver for me