blitzpp / blitz

Blitz++ Multi-Dimensional Array Library for C++
https://github.com/blitzpp/blitz/wiki
Other
402 stars 83 forks source link

Improve array memory releasing mechanism #174

Open bpalak opened 2 years ago

bpalak commented 2 years ago

An array can have various memory management policy: duplicate, neverDelete, deleteWhenDone... Calling array.free(), doesn't release memory of array having neverDelete policy. Unfortunately there is no way to check what policy was used at array creation time, so it cannot be determined if array data should be released manually or not. Moreover, array.free() nullifies a pointer to data even if memory was not automatically deallocated. Potential solutions: A) (the simples one) to not nullify _data private variable if memory was not automatically deallocated. After calling array.free(), user may check if pointer is valid - if so, memory can be freed manually. B) to expose memory policy via array method to provide user knowledge if an array must be deallocated manually

slayoo commented 2 years ago

Thank you for reporting it! IIUC, option B has the advantage of not changing the existing behaviour. Would it be possible for you to create a PR for it? Thanks, Sylwester