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?
Asked
Active
Viewed 1,041 times
0
3 Answers
4
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.

tadman
- 208,517
- 23
- 234
- 262
0
var = Base64.encode64(Marshal.dump(@result))
var.size
is life saver for me

Ravindra
- 1,039
- 2
- 12
- 26
-
I know nothing about RoR but this doesn't seem right. http://stackoverflow.com/questions/13378815/base64-length-calculation – spenibus Sep 07 '15 at 14:12