[petsc-dev] Using multiple mallocs with PETSc
Satish Balay
balay at mcs.anl.gov
Mon Mar 13 13:21:27 CDT 2017
On Sun, 12 Mar 2017, Karl Rupp wrote:
>
> > > If, however, the long-term goal is to get rid of global state, then we
> > > would have to store a matching deallocation routine with the raw buffer.
> > > Actually, you could store the function pointers to malloc/realloc/free in
> > > the first bytes of the allocated buffer instead of an index.
> >
> > That was my original thought but this is more likely to cause a random
> > crash if that space is corrupted; by using integers one can detect the
> > corruption before the crash occurs (in 99.9+ % of the cases of
> > corruption)
>
> that's a valid point, yes.
How about:
stash the metadata for each allocation (and pointers for corresponding
free) in a hash table for all mallocs that we need to track? [this
avoids the wasted 'space' in each alloc.]
Assuming valgrind works with special memory types - rely in it instead
of the extra integer padding?
Satish
More information about the petsc-dev
mailing list