[Csnd-dev] Shared-memory arrays (views / slices)

Eduardo Moguillansky <[email protected]>
Newsgroups gmane.comp.audio.csound.devel
Message-ID <CAHFFssKtFu=mw5s-rQ_yO_Sy=uZygR3za=19yiPhjWu6Xr6uqg@mail.gmail.com>
Hi all,

I would like to make a plädoyer for shared arrays, meaning arrays which do
not own their memory. This is the case, for example, when slicing an array,
or querying a row of a 2D array, etc., where it is useful to have a
reference to the memory of the array, either to be able to modify it or to
prevent a full copy of the entire array.

I implemented something of the sort (
https://csound-plugins.github.io/csound-plugins/opcodes/ref.html), where
taking a reference from an array would move the memory to a global space,
making the original array (and any subsequent call to deref) a reference to
that memory (the deinit callback of the opcode would prevent the array from
freeing its memory).

This mechanism makes it possible to pass arrays around (between
instruments, for example), put arrays inside of other arrays, etc. But the
approach would be safer if it was possible to mark an array as not owning
its memory so that: 1. any attempt to reshape/resize it would result in an
error, 2. there would be no need to have a deinit callback intercept the
cleanup of the array.

cheers,
Eduardo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.