bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Does substr make a hard copy of the input string?


From: Aharon Robbins
Subject: Re: [bug-gawk] Does substr make a hard copy of the input string?
Date: Thu, 08 Nov 2012 19:56:33 +0200
User-agent: Heirloom mailx 12.5 6/20/10

Greetings. Re this:

> Date: Wed, 7 Nov 2012 23:04:52 -0600
> From: Peng Yu <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] Does substr make a hard copy of the input string?
>
> Hi,
>
> I don't find it in the document. Does anybody know whether substr()
> makes a hard copy of returned substr from the input string? Or the
> returned result still has a reference of the input string (but just
> with start and end adjusted)?
>
> Depending on which alternative it is, I think that it may have
> different implications for the runtime when the input string and the
> substring are long.

It is up to the implementation. The result of substr() must act like
it is an independent string.

Gawk makes a fresh copy for substr but otherwise uses reference counted
strings.  Thus if you have something like

        a = "some extremely long string here"
        b = c = d = e = f = a

There is only one copy of the very long string.

Practically speaking, on today's systems where 2 GB of RAM is on the
low end, it doesn't make much difference.  :-)

Thanks,

Arnold



reply via email to

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