[petsc-dev] PetscMalloc for size zero

Jed Brown jed at jedbrown.org
Thu Jan 30 13:07:51 CST 2014


Matthew Knepley <knepley at gmail.com> writes:
> Actually, we are violating the malloc standard that Jed sent out. It says
> that for 0 size, malloc must return
>
>   NULL or a unique pointer
>
> However, if we have
>
>   PetscMalloc2(0,&r1,1,&r2)
>
> then r1 == r2 with the optimized implementation, and the pointers are not
> unique.

They are still correct to pass to PetscFree2(r1,r2).  I thought the
point of PetscMalloc[1-7] was to emulate doing a single big malloc and
calculating offsets, not to be semantically identical to calling malloc
several times (which would then allow separate calls to PetscFree).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20140130/cd5eda08/attachment.sig>


More information about the petsc-dev mailing list