0

Trying to allocate (direct memory) with Javolution.Struct that contains arrays, and the memory "explodes". No idea why, Would love to have a clue

Class A holds array of 50 of class B. Class B holds array of 1 million unsigned shorts:

import javolution.io.Struct;

public class Test {

    public static void main(String[] args) {
        Test t = new Test();
        t.work();
    }

    public void work() {
        A a = new A();
        System.out.println("a.size() = "+a.size()); // prints 100000000
    }
}

public class A extends Struct {
    public B[] randomName = array(new B[50]);
}

public class B extends Struct {
    public Unsigned16[] someData = array(new Unsigned16[1000000]);
}

The reason I need those arrays in one piece is the comfort of calling getByteBuffer() and getting the whole structure as single piece of memory, directly allocated in non jvm memory

The memory shows (10 GB) 6 GB instead of 100MB no clue why

[ javolution 6.1.0 ]

Edit 1: A more concise issue found to cause the same memory problem:

public Unsigned16[] someData = array(new Unsigned16[50000000]);

Allocating 50m unsigned16 in main (class needs to extend Struct obv) function is expected to have a 100mb memory footprint where its actually allocates 6gb

Edit 2: Its not happening if i'm calling the same line, without the wrapping with array() function:

public Unsigned16[] someData = new Unsigned16[50000000];

This is weird. I need the struct to contain this array, along with other Struct members (like Signed8 etc..), and when calling getByteBuffer() it will have the same piece of memory allocated and not pointers to different structs

Edit 3: This works as expected: ByteBuffer bb = ByteBuffer.allocateDirect(100*1000000); // allocates 100MB

I suspect there is a bug in Struct.array function in javolution lib. I will keep this post open until its fixed or someone post a workaround..

Li3ro
  • 1,837
  • 2
  • 27
  • 35
  • What you mean by "The memory shows 10 GB"? Have you used profiler? Has it shown that your `a` object uses 10 GB? – mentallurg Aug 25 '19 at 14:12
  • I'm positive its allocating much more than it should. Its the only thing that I'm running in the jvm. (java 8). I see it jumps to 6 GB, and drop back once I kill the process. and its a 6GB, not 10.. my mistake – Li3ro Aug 26 '19 at 05:46
  • Just use a profiler, check what are the biggest objects that use memory. Tell us what you see or post a screenshot of the profiler. – mentallurg Aug 28 '19 at 00:27

0 Answers0