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        


In reply to Re^6: Is there something faster than string concatenation? (quantum shells) by tye
in thread Is there something faster than string concatenation? by rdj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.