On Feb 27, 2018, at 12:00 AM, Daniel Vollmer <[email protected]> wrote:
> Hi,
> 
> On 27. Feb 2018, at 03:11, Brian Willoughby <[email protected]> wrote:
>> I do know that std::array will cause glitches. One of the students taking my 
>> CoreAudio & AudioUnit course suffered from audio glitches until replacing 
>> std::array with a pre-allocated Standard C array.
> 
> I don’t see how this can be, std::array stores its data inside the object and 
> performs no heap allocations of its own. The only problem areas I can think 
> are either that the contained type did something funny, or that arrays were 
> accidentally copied too much instead of being passed by reference.

I don’t quite follow what you’re saying here. If you add an item to an array 
that is not large enough to hold that item, then some allocation is necessary 
by definition. There are only limited situations in which this fact can be 
avoided.

I made no attempt to debug the situation in my student’s code. My first 
reaction was to consider that adding an element to an array requires that it 
allocate space to hold that new item. This is necessarily true unless the array 
was created with foreknowledge of the maximum number of elements it might ever 
be called upon to hold. After that brief consideration, I didn’t give it any 
more thought.

The glitches went away when the student stopped using std::array, but I suppose 
it’s possible that other  code design changes were also made at the same time 
that actually solved the problem, or that the student could have made better 
use of std::array in such a way that the problem might not occur.

I seem to recall that AUEffectBase uses std::array for the kernels, but I 
assume that Apple was careful in their code design to ensure that no kernels 
are ever added after the AU is Initialized. Such practices should ensure that 
no allocation happens in the audio thread.

Of course, this is a very different situation, since my student was adding 
items to the array in the audio thread based on various events.

Brian

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to