Re: Questionable advice
?? Tiib <ootiib@hot.ee> wrote:
The problem with C++'s generic smart pointers is that they are either
limited or very inefficient.
std::unique_ptr is very efficient, but limited in usage (because it
can't be used to share, or even deep-copy, the object among several
owners.)
Yes, you have to write deep-copy yourself but same applies to raw pointer.
I was not comparing C++'s smart pointers to raw pointers. I was comparing
them to a custom class that manages some resource.
std::shared_ptr can be used to share the object, but is very inefficient.
(In cases where you just need a few of them that doesn't matter. It starts
to matter if you need millions of them, or you need to create and destroy
millions of them in short timespans.)
When it takes millions to affect performance then it is not exactly
"very inefficient".
My intention was not to say that it takes millions for the difference
to show. My intention was to say that there's a big difference, and
it shows up especially when you need to have lots of them. If you have
literally millions of them, we can probably talk about an order of
magnitude of time difference (compared to a more efficient solution.)
This doesn't mean there's no difference with smaller amounts as well.
Also, there currently exists no ready-made solution for copy-on-write,
which is sometimes the most efficient solution to some problems.
Yes. Who wants to have lockless copy-on-write has to write it.
It's not like any of the standard library containers are very
thread-safe either...
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---