Get the size in KB of Marshal.dump output

Go To StackoverFlow.com

0

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?

2012-04-05 16:46
by Ran


3

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.

2012-04-05 17:02
by tadman


0

What about kbytes = Marshal.dump(ary_of_objs).size / 1000.0?

2012-04-05 16:59
by Guilherme Bernal


0

var = Base64.encode64(Marshal.dump(@result))
var.size 

is life saver for me

2015-09-07 11:46
by Ravindra
I know nothing about RoR but this doesn't seem right. http://stackoverflow.com/questions/13378815/base64-length-calculatio - spenibus 2015-09-07 14:12
Ads