
On Sun, 6 Mar 2011 17:43:15 -0800 "Simonson, Lucanus J" <lucanus.j.simonson@intel.com> wrote:
Chad Nelson wrote:
The only concrete complaint that people could give me about CoW was that code using it couldn't be made thread-safe, which is true. [...]
This is not true, I made a concrete complaint about why I don't like COW or move-emulation for performance reasons. [...]
Sorry, but that isn't really a complaint about CoW. It's a complaint about pass-by-value, an admitted mistake (which I'm correcting now) which CoW makes cheaper.
Rather that the false dicotomy between between COW and move lets answer the more fundamental question, why either? Just use expression templates. Don't bother to use proto for your expression templates, by the way, it is very easy to do yourself in this simple case.
I looked into it briefly yesterday (I've used the concept behind it before, but I didn't realize that that the name referred to it), and that's almost certainly the way to go in the long run. Apologies if I missed answering your message; I did see it, but some may have slipped through unanswered.
This whole argument misses the point of optimizing code that uses a bigint class. You want to reuse the memory allocated in a bigint variable over and over instead of reallocating every time.
That requires writing at least a minimal memory manager. As I understand it, the managers that come with compiler libraries are optimized for that sort of thing these days, since C++ is geared toward so many small heap-allocated objects. I'd rather let the compiler's library deal with it than write more non-core code for something that the built-in code will almost certainly be able to do better most of the time.
Whether you make one unneeded allocation or two is a less important consideration than whether you make one or zero since 2/1 is a lot smaller than 1/0. If a temporary is generated by the user's code they have already pessimized their code. I am sorry, but you cannot avoid allocation with a return by value semantic, only expression templates allows you to reuse the storage on the left hand side of the assignment operator. [...]
I'm not familiar with a use of expression templates that would allow that. Can you point me to something explaining it? -- Chad Nelson Oak Circle Software, Inc. * * *