develooper Front page | perl.perl5.porters | Postings from September 2014

Re: sv_grow() and malloc()

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
September 23, 2014 12:31
Subject:
Re: sv_grow() and malloc()
Message ID:
20140923123041.GY5204@iabyn.com
On Tue, Sep 23, 2014 at 12:49:56PM +0100, Dave Mitchell wrote:
> For example the following simple C code:
> 
>     #include <stdio.h>
>     #include <malloc.h>
> 
>     int main(int argc, char**argv)
>     {
>         int i;
>         void *q, *p = malloc(1);
>         malloc(1); /* poison reallocs */
>         for (i=1; i<130; i++) {
>             q = realloc(p,i);
>             if (p != q) {
>                 printf("after %3d bytes realloc() using different address\n", i-1);
>                 malloc(i); /* poison reallocs */
>             }
>             p=q;
>         }
>     }
> 
> gives this output on my system:
> 
>     after  24 bytes realloc() using different address
>     after  40 bytes realloc() using different address
>     after  56 bytes realloc() using different address
>     after  72 bytes realloc() using different address
>     after  88 bytes realloc() using different address
>     after 104 bytes realloc() using different address
>     after 120 bytes realloc() using different address

PS

I'd be interested in what people get with that code on other OSes.

-- 
Lear: Dost thou call me fool, boy?
Fool: All thy other titles thou hast given away; that thou wast born with.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About