in reply to Efficienty truncating a long string
A quick test shows that substr is pretty intelligent about the way it operates.
# OS reports memory use 3336k my $s = ' ' x 1_000_000; # OS reports memory use 4320k $s = substr $s, 0, 999_999; # OS continues to report 4320k
If substr was acting as a copy operator the memory would have to grow again to accomodate the copy. That is doesn't, even in this non-lvalue usage tends to indicate that the code has the smarts to recognise when the destination of a substr assignment is the same and the source and it performs a simple adjustment to the length of the SV in-situ, which is about a fast as is possible to be.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Efficienty truncating a long string
by Anonymous Monk on Dec 19, 2003 at 13:53 UTC | |
by BrowserUk (Patriarch) on Dec 19, 2003 at 16:05 UTC |