openPMD-api icon indicating copy to clipboard operation
openPMD-api copied to clipboard

add C array arguments in the storeChunk() function API

Open denisbertini opened this issue 3 years ago • 4 comments

** My problem ** My reading procedure is implemented via Fortran C interface. The interface exposes on static C arrays and i need to copy the C arrays to std::vector to use the storeChunk() function. I would like to avoid the additionnal copying of the data arrays ( these are huge array holding particle data!)

** Possible solution ** add C static array as argument of the storeChunk()

denisbertini avatar Oct 19 '22 09:10 denisbertini

This WIP PR adds these calls. Until then, you can use storeChunk(shareRaw(ptr), offset, extent) to hijack the shared_ptr overloads.

franzpoeschel avatar Oct 19 '22 09:10 franzpoeschel

what is the shareRaw() function exactly doing ?

denisbertini avatar Oct 19 '22 09:10 denisbertini

It creates a shared pointer from a raw pointer with a no-op destructor, i.e. a non-owning shared pointer.

template <typename T>
std::shared_ptr<T> shareRaw(T *x)
{
    return std::shared_ptr<T>(x, [](T *) {});
}

franzpoeschel avatar Oct 19 '22 09:10 franzpoeschel

ah ok thx !

denisbertini avatar Oct 19 '22 10:10 denisbertini