|
jiwoo
Automatic memory management of containers of array pointers
|
Despite its generalist-sounding title, jiwoo is actually just designed for a very specific use case - managing a thread-specific allocation to store partial results in a parallelized function that accepts a vector of array pointers from the caller. This is more involved than one might expect when we try to squeeze out some more performance by avoiding unnecessary allocations.
The EquilengthArrays class is an array of equilength arrays of the specified value type. When destoyred, all of the arrays are automatically freed.
Check out the reference documentation for more details.
jiwoo is primarily intended for use in a function that:
A toy example of such a function is shown below. Some more concrete examples can be found in tatami_stats::group_rss() and scran_aggregate::aggregate_across_cells().
The use of jiwoo here is motivated by several considerations:
output_buffers in the first thread. This optimization avoids an unnecessary allocation of temporary output buffers, particularly during serial execution.std::vector<std::vector<double> > that automatically manages the memory. However, if we want to easily switch between output_buffers and our temporary buffers in different threads, our temporary output buffers must also be represented as a contiguous array of double* pointers. It would be slightly inefficient to allocate both a std::vector<std::vector<double> > and also a std::vector<double*> with pointers to each vector's data.jiwoo::EquilengthArrays and extract the pointer to the internal array of pointers with the get() method. This is directly interchangeable with the equivalent pointer from output_buffers.FetchContentIf you're using CMake, you just need to add something like this to your CMakeLists.txt:
Then you can link to jiwoo to make the headers available during compilation:
find_package()You can install the library by cloning a suitable version of this repository and running the following commands:
Then you can use find_package() as usual:
If you're not using CMake, the simple approach is to just copy the files in the include/ subdirectory - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I.
This library is named after the main character of a K-drama that I imagined in the shower. The title of the K-drama is 잘 익은 자두의 향기, "Scent of a ripe plum".
Synopsis: Ji-Woo never believed in love. After her parents divorced in her teens, she devoted herself to study and work, steadily climbing the corporate ladder until she became a vice-president of a major company. Now approaching her forties, she watches on from the sidelines as her friends and family experiences the highs and loves of their romantic lives. However, when a handsome young graduate joins her team, youthful passions begin to stir in her heart. Has spingtime finally come for Ji-Woo?
The show has three main arcs.
Anyway, I don't have the time to flesh this out into a screenplay and also I need to learn Korean. A reference to this idea in this library is the best we're going to get for now.