21-Jul-2013 00:42, Ali Çehreli пишет:
On 07/20/2013 01:22 PM, Dmitry Olshansky wrote:

 > 21-Jul-2013 00:19, Namespace пишет:
 >> Let us assume we have a method of a class which is used often and the
 >> method is called periodically and must allocate every time a array
 >> between 100 and 4000 elements. What would you do?

 > 5. Keep a TLS scratch pad buffer (static  class member) for said
 > 100-4000 floats and re-use it.

As long as the function finishes with that buffer, there shouldn't be
reentrancy issues in general. But if the function calls the same
function, say on another object perhaps indirectly, then the two objects
would be sharing the same buffer:


Yes, this case is problematic. It cannot be called recursively even with another instance.

class C
{
     void foo() {
         /* modify the static buffer here */
         auto c = new C();
         c.foo();
         /* the static buffer has changed */
     }
}

Ali



--
Dmitry Olshansky

Reply via email to