Checking for nullptr in procesBlock?

Quick question for the gurus, is it ok to check for nullptr in my processBlock(). As in:

for (int i = 0; i < numSamples; i++)
{
   if(myBuffer != nullptr)//returns null when auval tries an unsupported config
   {
        ...

Question is, what type is myBuffer?
It is ok to check a pointer if it isn’t nullptr.
But you shouldn’t create an AudioBuffer on the heap. It is meant to be on the stack or as class member, since it is a lightweight wrapper around data, that can be shared or owned.

And for performance, do the check outside the loop (the optimiser will catch that, but in debug the optimiser is off).

The poster didn’t specify if it’s an AudioBuffer or just a float*, for example.

That’s why I asked :wink:

1 Like

It’s just a float* …

Then yes, nothing wrong with that (except if myBuffer is accessed from a different thread as well?)

And yes, still a good idea to pull the check outside the loop.

Thanks guys. Good to know. And yes, I can probably put it outside that loop too. :+1: