For Programmers: Free Programming Magazines  


Home > Archive > AWK > August 2007 > Re: Memory exhausted: error when match() function is called with









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Memory exhausted: error when match() function is called with
Ed Morton

2007-08-22, 6:57 pm

ram wrote:
> Hi All,
>
> I have the following small snippet of awk code
>
> function test(regexp)
> {
> match($0, regexp)
> }
>
> {
> test(": ");
> test("=");
> }
>
> When I execute the above small snippet of code with a big file as
> input I get the following
> error:
>
> awk: /var/tmp/awk_test:4: (FILENAME=- FNR=5776) fatal: Memory
> exhausted: /: /
>
> Output of top command shows that the memory of awk process increases
> gradually.
> ( I am executing this command in UNIX).
>
> Any idea what is the problem ? and How to solve this?
>
> When I tried calling the test() function with the same parameter I did
> not see this error.
> Also, when I commented the match() function I did not see this error.
>
> So, It looks like their is a memory leak in match() function when it
> is called with two different
> regular expression. I may be wrong also.
>
> Thanks,
> Ram
>


You're probably right. I'm curious and it may provide you a workaround:
if you don't mind trying it, what happens when you do either of these:

1)
function test(foo) { regexp=foo; match($0, regexp) }
{
test(": ")
test("=")
}

2)
function test() { match($0, regexp) }
{
regexp=": "; test()
regexp="="; test()
}

3)
{
regexp=": "; match($0, regexp)
regexp="="; match($0, regexp)
}

4)
{
match($0, ": ")
match($0, "=")
}

Regards,

Ed.
Ed Morton

2007-08-22, 6:57 pm

Ed Morton wrote:

> ram wrote:
>
>
> You're probably right. I'm curious and it may provide you a workaround:
> if you don't mind trying it, what happens when you do either of these:
>
> 1)
> function test(foo) { regexp=foo; match($0, regexp) }
> {
> test(": ")
> test("=")
> }
>
> 2)
> function test() { match($0, regexp) }
> {
> regexp=": "; test()
> regexp="="; test()
> }
>
> 3)
> {
> regexp=": "; match($0, regexp)
> regexp="="; match($0, regexp)
> }
>
> 4)
> {
> match($0, ": ")
> match($0, "=")
> }
>
> Regards,
>
> Ed.


Oh, and 1 more:

5)
BEGIN{ regexp1=": "; regexp2="=" }
{
match($0, regexp1)
match($0, regexp2)
}

Regards,

Ed.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com