<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 30, 2014 at 1:53 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On Jan 30, 2014, at 12:46 PM, Brad Aagaard <<a href="mailto:baagaard@usgs.gov">baagaard@usgs.gov</a>> wrote:<br>
<br>
> On 01/30/2014 10:34 AM, Jed Brown wrote:<br>
>> Brad Aagaard <<a href="mailto:baagaard@usgs.gov">baagaard@usgs.gov</a>> writes:<br>
>><br>
>>> Matt and Jed,<br>
>>><br>
>>> I see that Jed pushed some changes (jed/malloc-zero) for PetscMalloc to<br>
>>> deal with memory alignment and a zero size. It looks like the pointer<br>
>>> will NOT be NULL for a size of 0. Is this true?<br>
>><br>
>> Yes, just like malloc(), it can be either a unique pointer or NULL.  You<br>
>> need the size anyway to know how many elements are in the array.<br>
><br>
> I thought it was a nice feature that PETSc improved on malloc() and free() by returning NULL for zero sized allocation (although this wasn't true for --with-debugging=0 due to memory alignment) and set pointers to NULL after freeing.<br>

<br>
</div>   With PetscMalloc() we could certainly return NULL on 0 mallocs but the code is a bit more involved  for the PetscMallocn() case.<br>
<br>
   Here is what I suggestion. Someone suggest (i.e.. write) a refactorization of PetscMalloc(), PetscMallocn() that handles correctly any of the sizes being zero correctly in a branch and see how it goes.</blockquote><div>
<br></div><div>I have pushed it. It looks simple to me</div><div><br></div><div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888"><br>

   Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
><br>
> What is the rationale for not returning NULL for mallocs of size zero other than conforming to C malloc behavior?<br>
><br>
> Brad<br>
><br>
><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener
</div></div>