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

Renew() vs. realloc()

Thread Next
From:
Felipe Gasper
Date:
April 21, 2020 18:08
Subject:
Renew() vs. realloc()
Message ID:
7A6CEB64-21BB-46F5-9728-5A305D20E487@felipegasper.com
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);
        Safefree(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!

cheers,
-Felipe Gasper
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