Using the windows task manager, "Virtual Memory Usage" column.
> >> I noticed that breaking up a large array into 2 pieces results in a
> >> much higher memory usage for my program. Example:
[quoted text clipped - 16 lines]
> > --Daniel Dyer
> > http//www.uncommons.org
[Top posting fixed]
> Using the windows task manager, "Virtual Memory Usage" column.
Please don't top post, it confuses the conversation...
Windows task manager does not accurately measure Java memory usage.
The JVM's allocation of memory, and the Java programs allocation of
memory don't always correspond one-to-one. It could be that your test
does a garbage collection in one instance, and not in the other... It
would be interesting to compare
float[] b = new float[16000000];
and compare it to
float[] b = new float[32000000];
and see how the memory differs.
Also, see if running the program several times has different results,
or running it inside an IDE, vs running it outside an IDE.
wittle - 29 Sep 2007 20:25 GMT
>>>> I noticed that breaking up a large array into 2 pieces results in a
>>>> much higher memory usage for my program. Example:
[quoted text clipped - 30 lines]
> Also, see if running the program several times has different results,
> or running it inside an IDE, vs running it outside an IDE.
Thanks, I did a little googling to find a more accurate way to measure
my program's memory usage, and found out about the Runtime.maxMemory(),
Runtime.totalMemory(), and Runtime.freeMemory(). I created a small test
program to test the results of allocating memory in one 32000000 length
chunk vs 2 16000000 length chunks and these were the results:
1 32000000 length chunk:
Max memory: 832438272
Total memory: 130035712
Free memory: 1915488
2 16000000 length chunks
Max memory: 832438272
Total memory: 178917376
Free memory: 50663416
So it seems in the latter case the JVM does request and receive more
memory from windows for some reason, but that memory is free for my
program to use, so it is not wasted, so it's fine.
xen - 29 Sep 2007 22:30 GMT
I'm pretty sure there is no big difference in memory consumption.
The array itself takes up 16 bytes; that's 8 for the object, 4 for the
size, and 4 for alignment.
So your overhead is 16 bytes.
Add to that what the VM needs for memory allocation, which is also
insignificant compared to 64 MB.