OwnedArray::getLock


#1

Hi,

I’m wondering how can this method be used in client code ?
I’ve seen that once you’ve locked the array, you can only call size() which isn’t lock protected, but all other method have a ScopedLock on enter (so it would deadlock if we called them).
Maybe it’s a good idea to add a “getUnlocked” method, which would be the internal of “getUnchecked” but with no lock protection ?
Something like:

    /** Returns a pointer to the object at this index in the array, without checking whether the index is in-range.

        This is a faster and less safe version of operator[] which doesn't check the index passed in, so
        it can be used when you're sure the index if always going to be legal.
    */
    inline ObjectClass* getUnchecked (const int index) const throw()
    {
        const ScopedLockType lock (getLock());
        return getUnlocked(index);
    }
    /** Returns a pointer to the object at this index in the array, without checking whether the index is in-range, 
         and without locking the array.

        This is a faster and less safe version of operator[] which doesn't check the index passed in, so
        it can be used when you're sure the index if always going to be legal.
    */
    inline ObjectClass* getUnlocked (const int index) const throw()
    {  
        jassert (((unsigned int) index) < (unsigned int) numUsed);
        return data.elements [index];
    }

This would avoid having another lock in our class for array protection while “slowly” iterating it.


#2

What do you think ?