Re: the inefficiency of noncontiguous data - why?



Daniel Pitts wrote:
On Sep 29, 12:00 pm, wittle <w...@xxxxx> wrote:
Daniel Dyer wrote:
On Sat, 29 Sep 2007 19:44:45 +0100, wittle <w...@xxxxx> wrote:
I noticed that breaking up a large array into 2 pieces results in a
much higher memory usage for my program. Example:
A program with:
float[] a = new float[32000000];
uses 138MB of memory on my system.
But a program with:
float[] b = new float[16000000];
float[] c = new float[16000000];
uses 187MB of memory, even though it's the same amount of data.
Why is this? My heap size is 800MB.
How are you measuring memory usage?
Dan.
--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.


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.
.



Relevant Pages

  • How to find out how many other processes share VM with $PID?
    ... I was a bit frustrated by bad quality of memory usage info ... I know how to detect and correctly account for threads ...
    (Linux-Kernel)
  • Re: Backup fails with volsnap error
    ... memory usage is way over the top. ... In fact, if you get Trend under control, you'll probably see Exchange grab ... The Trend requirments say 512MB of RAM for the system.... ... I will talk to Trend about the memory usage. ...
    (microsoft.public.windows.server.sbs)
  • Re: Memory problem
    ... > I test the memory usage with my System Resources Manager and the top ... > command (I work with Linux but the Mac forums are the only place to go ... There are two levels of memory allocation going on here, ... One level is the malloc level, where you can request things in byte-sized ...
    (comp.sys.mac.programmer.help)
  • Re: High Memory Usage Garbage Collection Question
    ... > whether I can reduce the memory usage. ... > I have an app that wakes up and processes text files into a database ... > public static string readLineResponse; ...
    (microsoft.public.dotnet.general)
  • Re: Indexing uses *lots* of memory
    ... I'm not worried about store.exe memory usage (the ... server supports over 500 users). ... please refer to the following Microsoft ...
    (microsoft.public.exchange2000.general)