[petsc-dev] Allocating arrays

Barry Smith bsmith at mcs.anl.gov
Sat Nov 30 21:08:01 CST 2013


On Nov 30, 2013, at 7:34 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> Barry Smith <bsmith at mcs.anl.gov> writes:
> 
>>   I propose the following alternative:
>> 
>>      Remove the type arguments from PetscMalloc2-7()
> 
> I'm happy to do this.  I think I can almost entirely automate it.

   Cool, make it so.
> 
> I agree that these functions are almost exclusively used internally, and
> I think that every use in PETSc matches the types, so there is no point
> keeping the old versions.
> 
>>      Add PetscMalloc1() 
>> 
>>      Add PetscCalloc1() 
>> 
>>      Use PetscCalloc1() to implement PetscNew() 
> 
> PetscCalloc1 *is* PetscNew.  I would prefer "calloc" since it matches a
> libc function that does the same thing, where as "new" conjures up
> images of C++, where "new" only initializes non-POD types (which
> includes std::complex<double>, but not struct {double real,imag;}).  So
> perhaps replace all uses of PetscNew with PetscCalloc1?

  PetscNew() is PetscCalloc1(1,&beasty); the original analogy with C++ was that it creates a struct and initializes it to zero entries. :-)  I’d like to keep it.  

> 
> I wonder how many uses of PetscNew should have actually been PetscNewLog.

   I check and there are some that could be fixed.

  Barry






More information about the petsc-dev mailing list