Hello,

I have been playing around with the length less streaming overloads in JDBC4. In the discussion of DERBY-1471, it was suggested that we forgot about the layerB streaming in DRDA at the moment and instead implemented a much simpler approach. When we have what we need, we can improve the length less overloads.

The planned approach on the client side is to create a LOB and have it materialize the whole stream in memory to determine the length. The LOB is then sent to the server by using the existing methods/API, which require a length argument.

I have seen that the maximum possible size of a byte array is Integer.MAX_VALUE. However, when I tried this out, I was not able to create such a big array in all VMs. I got this error message:
java.lang.OutOfMemoryError: Requested array size exceeds VM limit

Does anyone know what's causing these reduced sizes?
Here are the numbers (all Sun VMs):
1.3             2^31 -20
1.4             2^31 -20
1.5, -d32       2^31 -20
1.5, -d64       2^31 -40
1.6, -d32       2^31 -1  <---- as expected


Thus, maximum LOB size in Derby for the new length less overloads is limited by two factors (seen from the client):
        1) Memory on the client (need at least 2xLOB size + overhead)
        2) Maximum size of byte array (in range [2^31 -40, 2^31 -1])

Since 1) will be in effect most of the time (still not common with >4G RAM is it?), 2) will almost never be seen. I don't plan to support LOBs of 2^31 -1 bytes if the VM don't support that big byte arrays...

Out of curiosity, does anyone know the max limit for byte arrays on other VMs? I attached the little program I used, don't forget to set the maximum heap size high enough.




--
Kristian
public class MaxByteArraySize {

    public static void main(String[] args) {
        int size = Integer.MAX_VALUE;
        byte[] b;
        while (true) {
            System.out.print(size);
            try {
                b = new byte[size];
                System.out.println("   SUCCESS!");
                break;
            } catch (Throwable t) {
                size--;
                System.out.println("   FAILED!");
            }
        }
    }
}

Reply via email to