awk memory leak?
This statement is odd:
split("0,2,4,5,7,9,11,12",a,",");
It repetitively splits a constant string to create an array a
. If you move that into a BEGIN
section, the program should work the same — without allocating a new copy of the a
array for each input-record.
Addressing comments: the for-loop and expression do not allocate memory in a simple manner. A quick comparison of mawk, gawk and awk shows that there is no problem with the first two, but /usr/bin/awk
on OSX does leak rapidly. If Apple had a bug-reporting system, that would be the place to go.
Here's a perl equivalent that doesn't leak:
perl -lne 'BEGIN { @a=(0,2,4,5,7,9,11,12);}
for ($i = 0; $i < 1; $i+= 0.0001) {
printf("%08X\n", 100*sin(1382*exp($a[$F[0] % 8]/12)*log(2))*$i) }'
It's almost identical. $1
gets replaced by $F[0]
and i
is replaced with $i
. The hash a
is replaced with an actual array, @a
.
You would be wise to generate some input and compare the output and note differences between the two. There are often nuances as to how interpretive languages deal with floating point.