in reply to Re^5: Is there something faster than string concatenation? (hermit crabs)
in thread Is there something faster than string concatenation?
If realloc() doubles (at least) the size when a size increase is required, then the calling code would not know about it and so Devel::Size wouldn't know about it either.
I've not heard of such a feature of realloc() described that way. But I have seen malloc() libraries that build arenas that only hold buffers of size 2**n with a bitmap to note which buffers are in-use. And such a scheme would have that impact. Certainly Win32 does not use such a scheme (it has a pretty naive implementation of malloc() which can certainly be a source of problems that need to be worked around). And I don't think Win32 Perl is usually built to use Perl's private malloc().
So building up a string by repeated concat in Win32 Perl is probably going to copy the source string over and over. While some Perls with better malloc() implementations will only rarely have to copy the source string as I described above.
You could use repeated trials, noting how often the string's address changes in order to make a good guess whether such a malloc() is being used. To get the string's address you can use something very similar to:
my $fmt= "LIJ"; while( 1 ) { last if length( pack substr($fmt,0,1), 0 ) == length( pack "p", "" + ); $fmt= substr( $fmt, 1 ); die "No unpack format for integers the same size as pointers" if ! $fmt; } $fmt= substr( $fmt, 0, 1 ); my $addr= unpack $fmt, pack "p", $string;
Thanks for mentioning that, eyepopslikeamosquito.
- tye
|
---|