Re: [boost] [Any] Reference counting

Steven Watanabe <watanabesj@gmail.com> wrote:
Have you read http://www.gotw.ca/gotw/045.htm? I haven't read it, and have looked into atomic numbers, but couldn't find the "Boost Way" to do it (except perhaps poking around with shared_ptr innards). I wanted to use intrusive counts, since we have control over the object we are sharing.
Thorsten Ottosen <thorsten.ottosen@dezide.com> wrote:
If you want to improve the performance of any, the thing to do is to add a small buffer optimization such that all buildin types (or equally small UDT) are created on the stack. I'll look into that.
Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
Also, any is a value type. We do not want it to have reference semantics. So you'd need to use COW. Actually, copy on write/implicit sharing is what I was proposing, if you had looked at the code. Hence this is fairly useless, especially since we're getting move semantics soon. "Soon" is relative. The trunk GCC may support it instantly (may already), but Debian Stable won't, nor will MSVC (both which will be used for a good while). Also, you usually copy the value when you store it, which may or may not involve writing. For example: #include <boost/any.hpp> using namespace boost; struct example { any variable; }; int main() { example object; example object2; any value = "I Love Boost!"; object.variable = value; object2.variable = value; return 0; }
Thanks for replying, everyone. -- Michael Howell mhowell123@gmail.com

AMDG Michael Howell wrote:
Hence this is fairly useless, especially since we're getting move semantics soon.
"Soon" is relative. The trunk GCC may support it instantly (may already),
gcc 4.3.0 supports rvalue references with -std=c++0x In Christ, Steven Watanabe

I wrote:
I haven't read it, and have looked into atomic numbers, but couldn't find the "Boost Way" to do it (except perhaps poking around with shared_ptr innards). I wanted to use intrusive counts, since we have control over the object we are sharing. I've found the "Boost Way" to do it: boost::detail::atomic_count. It even does non-atomic counts if people disable thread-safety.
-- Michael Howell mhowell123@gmail.com

Michael Howell wrote:
Hence this is fairly useless, especially since we're getting move semantics soon. "Soon" is relative. The trunk GCC may support it instantly (may already), but Debian Stable won't, nor will MSVC (both which will be used for a good while). Also, you usually copy the value when you store it, which may or may not involve writing.
Boost has a move emulation library as well as move-aware standard containers.

On Sunday 05 April 2009 18:06:46 I wrote:
Thorsten Ottosen <thorsten.ottosen@dezide.com> wrote:
If you want to improve the performance of any, the thing to do is to add a small buffer optimization such that all buildin types (or equally small UDT) are created on the stack.
I'll look into that. I've managed to make a patch to do it.
-- Please do not send HTML mail. Please, if you forward email, clean off the garbage. Thanks for making everyone's email experience more enjoyable. Michael Howell mhowell123@gmail.com

Michael Howell skrev:
On Sunday 05 April 2009 18:06:46 I wrote:
Thorsten Ottosen <thorsten.ottosen@dezide.com> wrote:
If you want to improve the performance of any, the thing to do is to add a small buffer optimization such that all buildin types (or equally small UDT) are created on the stack. I'll look into that. I've managed to make a patch to do it.
well, you're using shared_ptr now, so you don't avoid heap allocations, do you?´(and there must be an overhead with using shared_ptr do to the reference counts) Also, can those reinterpret_cast not be replace with static_cast? -Thorsten
participants (4)
-
Mathias Gaunard
-
Michael Howell
-
Steven Watanabe
-
Thorsten Ottosen