SOLVED: Size of allocated Byte Buffer and message size

Hi all,

I have read SpiderMonkey allocates “only” 32 KB for transferring a message. My problem is that I had a message with more data. So I “clipped” the data and have now a message class with the following fields:

public class ChunkDeliveryMessage extends AbstractMessage {
    private Byte[][][] m_blocks;
    private int m_locX;
    private int m_locY;
    private int m_locZ;

The Byte-Array has ALWAYS a (fixed) size of [10][256][10].

Assuming that one Byte needs 1 Byte and an int needs 4 Byte I calculated that I need to have

34 + 10256*10 = 25612 Bytes

But SpiderMonkey still throws an BufferOverflowException. I only can send the message if I reduce the array size to [9][256][9].

What is wrong in my calculation? I really thought that the message would fit to the 32 KB that is allocated by the SpiderMonkey.

You have an array of arrays of arrays of Byte objects. Because you are using Byte objects instead of byte primitives, you will need extra space. At minimum, there is one byte just to store whether it is null or not… so two bytes minimum. (Actually, it looks like the code might not do this but it should be and you should count on it for Object-based types.)

Anyway, you also need to take into account that for every one of the sub-arrays, a size must be stored. So if your array is [10][256][10] then there are 10 sizes for the first index and 10*256 sizes for the second index. All of those sizes are written as ints, so 4 bytes each.

You are waaaay better off flattening your message into a 1 dimension array of byte (with a lower case b)… then your data size will be much closer to what you’d expect.

Thanks for that fast answer :slight_smile: And for the explanation. I did not take this into account, but now I’ve learned something more :smile:

Okay, that sounds okay for me. Flatten it to a 1-dim-array is no problem. I’m not sure, if an element might be set to null by my current code. It should never be … but should means that I’m not sure. I need to check this first.

Thanks for your reply.

Okay … works as expected.