I’m using ReferenceCountedObjectArray with CriticalSection quite heavily, and I seem to be running into a hole in the implementation…

I’m using the array across threads, and I have some arrays holding ‘spare’ objects. The problem is when I want to ‘pop’ them off. I can get a reference or index to one of them, but I can’t guarantee that the array won’t change in between my query and removing the object.

Is there a reason that ‘ObjectClass * remove(int)’ won’t work with that class? Obviosuly it would need to return a reference, but if the reference isn’t picked up it would be a simple remove, right?


Why not just call the lockArray() and unlockArray() methods around the bit of code that you’re trying to do?

I do now, but that seems like it will cause some problems in the future. It’s for multi-threaded video playback and I want to return available frames to the back of the queue and pop them off the top, so I’d rather not lock the whole thing.


Well if there was a method to do what you’re asking, it’d still have to lock it - there’s no real difference between that and you locking it while you pop the item off yourself.