<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 30, 2014 at 12:50 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Thu, Jan 30, 2014 at 12:46 PM, Brad Aagaard <span dir="ltr"><<a href="mailto:baagaard@usgs.gov" target="_blank">baagaard@usgs.gov</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On 01/30/2014 10:34 AM, Jed Brown wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Brad Aagaard <<a href="mailto:baagaard@usgs.gov" target="_blank">baagaard@usgs.gov</a>> writes:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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>
</blockquote>
<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>
</blockquote>
<br></div></div>
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>
What is the rationale for not returning NULL for mallocs of size zero other than conforming to C malloc behavior?</blockquote><div><br></div></div></div><div>There is no such thing as "conforming to C malloc", since that WOULD allow returning NULL in this case.</div>
</div></div></div></blockquote><div><br></div><div>Actually, we are violating the malloc standard that Jed sent out. It says that for 0 size, malloc must return</div><div><br></div><div>  NULL or a unique pointer</div><div>
<br></div><div>However, if we have</div><div><br></div><div>  PetscMalloc2(0,&r1,1,&r2)</div><div><br></div><div>then r1 == r2 with the optimized implementation, and the pointers are not unique.</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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I think we are doing users a disservice by not enforcing this.</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><font color="#888888"><br>
Brad<br>
<br>
<br>
</font></span></blockquote></div><div class="im"><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></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>