develooper Front page | perl.perl5.porters | Postings from April 2020

Renew() vs. realloc()

Thread Next
Felipe Gasper
April 21, 2020 18:08
Renew() vs. realloc()
Message ID:
Hi all,

	I’ve got the following test code:

        void *wtf = NULL;
        Newx( wtf, 0, void * );
        fprintf(stderr, "new pointer: %p\n", wtf);
        Renew( wtf, 0, void * );
        fprintf(stderr, "renewed pointer: %p\n", wtf);

… which prints:

new pointer: 0x7fa2bee94f30
renewed pointer: 0x0

Note that Renew() is NULLing out my pointer, which isn’t what realloc() does--at least on macOS. (“If size is zero and ptr is not NULL, a new, minimum sized object is allocated and the original object is freed.)

Is this discrepancy intended behavior? If so:

- Should perlclib mention that as a significant difference between Renew() and realloc()?

- Is there a Perl-API equivalent of realloc() that will do as I intend here?

Thank you!

-Felipe Gasper
Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About