Allow tables to be resized and accessed as FloatBuffers#80
Conversation
There was a problem hiding this comment.
I'm concerned about the real-time implications here. The methods of libpd are generally written in such a way that they only take the lock outside of Java, and only for very short operations.
This one would be a deviation from this pattern because the runnable might do arbitrarily complex things and cause glitches. And even if we assume that developers will only pass in computationally cheap runnables, I still wouldn't trust Java with the native lock because the garbage collector might decide that this is an awesome time to do its thing and freeze everything for umpteen milliseconds.
|
This pull requests reminds me of a conversation we had a while ago, and my reaction now is pretty much what it was then: http://createdigitalnoise.com/discussion/334/accessing-arrays-in-pd The upshot is, these changes don't seem quite safe, and I'm not sure what the use case is. I suggest we start with the use case and see how we can address it. |
|
I agree that it's reasonable to require client code to make a defensive copy. Yeah, it's technically slower but I should be fine in most cases and keeps thread issues to a minimum. |
|
Regarding the use of My personal use case is reading an audio file outside of Pd and writing the sample data into a table. In the patch I ensure that the table is not being accessed, I resize the table, then get a |
|
Similarly, @nettoyeurny's thoughts are also correct regarding My use case is that I have an external which runs in Pd, but also has a Java component which has its own threads, independently of Pd. At some point the Java thread needs to update state in the native external struct, and I need to be able to guarantee that the audio thread (i.e. Pd) isn't in there doing something. Thus, |
|
@nettoyeurny What's your take on this now that locking is built into the C core? Access to filling arrays directly would solve the problem of missing native file format support in libpd for iOS, etc. Also, I'd like to see this in the C core. |
|
I have to say I'm still a bit worried about this idea because a large
transfer might cause the lock to be held for a long time. What about the
idea of swapping arrays, so that read/write operations can be done without
the lock?
…On Tue, Jan 9, 2018 at 7:44 PM, Dan Wilcox ***@***.***> wrote:
@nettoyeurny <https://github.com/nettoyeurny> What's your take on this
now that locking is built into the C core? Access to filling arrays
directly would solve the problem of missing native file format support in
libpd for iOS, etc.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#80 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABEQTosdmZS36c3nAFqUOuOa_-bAOqIyks5tJAfvgaJpZM4CXs0N>
.
|
|
I agree with Peter regarding the direct buffer access. It's probably best done manually outside of libpd when you really need it. Also, newer capabilities such as integrating double support internally would mean we couldn't guarantee the buffer type you are accessing, at least not trivially for most cases. However, I think being able to resize an array is definitely useful and ported your implementation to #281. |
I feel this takes use more into wrapper territory. The base C API should be simple and straight forward. I could see something a little more complicated like this being introduced as an additional helper utility, etc. |
These functions expose additional functionality to the Java domain. Tables may be resized. And instead of reading and writing to them via a Java-array intermediary, they may now be accessed directly as
java.nio.FloatBuffers. Finally, the ability to execute a genericRunnablein a thread-safe way has been added, ensuring that the audio thread is not running.