Originally Posted by
Elysia
Yes. Yes, it does.
But it's making a local copy and then passing it by reference.
In contrast, foo3 does exactly the same thing, it takes a local copy. Only this time it isn't a reference. I find it not an argument for references. It just includes additional security on your part, giving you more responsibility. Which is not the way a class should work - it should remove responsbility for you (handling it for you) and exposing its functionality to you.
But it also goes against the design of the class: for each variable of the class that points to the same memory, they will count towards ref count.
If you need to pass a memory handler object through reference, then you're not supposed to be using the memory handler at all.
Well, no, not yet. I haven't had the need to do so. And when I do, I will make it optional. If you believe you're going to use it across threads, then you activate it, and if not, then you don't. That save time of expensive locking and unlocking if it's not going to be used by another thread.
It's just a sample. And, in fact, it's a race condition example too. And race conditions are not very rare at all.
Though it seems that yes, as long as you make at least one copy of the variable for each thread, it will work as it should.
But again, I designed the class to be passed by value (overloaded a copy constructor & all).