bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] Memory usage of multi-dimensional arrays


From: Christian Schneider
Subject: [bug-gawk] Memory usage of multi-dimensional arrays
Date: Thu, 15 Mar 2018 18:23:10 -0700
User-agent: NeoMutt/20170609 (1.8.3)

Hi all,

I encountered an interesting behaviour with multi-dimensional arrays and 
was wondering, if this is expected or a bug:

Example 1:

## create array with 100k elements
BEGIN { for (I = 0; I < 100000; I++) X[I] = 0 }
## wait to allow for memory analysis
END { while (1 == 1) Y = 0 }

Result:

The memory usage (looked at with "ps" and all its limitations) is of 
order a few (~8) bytes per element, as expected.

Example 2:

## create multi-dimensional array with 100k elements
BEGIN { for (I = 0; I < 100000; I++) X[I][I] = 0 }
## wait to allow for memory analysis
END { while (1 == 1) Y = 0 }

Result:

Uses a few (~4) kB per element.  This also means, an array with 1m 
elements cannot even be created on a machine with 8 GB RAM anymore.

I could not find any documentation on that behaviour.  If it is 
considered "normal", could you mention this somewhere, please?  Is there 
a way to make these arrays more efficient?

Thank you very much for any comments.

Best regards,
Christian

P.S.: Please CC me, as I am not subscribed.

P.P.S.: version:
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2)
from: Debian 9.4, amd64



reply via email to

[Prev in Thread] Current Thread [Next in Thread]