[LLVMdev] New type of smart pointer for LLVM

Renato Golin renato.golin at linaro.org
Thu Sep 25 01:44:50 PDT 2014


On 25 September 2014 06:16, David Blaikie <dblaikie at gmail.com> wrote:
> I can go & dredge up some examples if we want to discuss the particular
> merits & whether each of those cases would be better solved in some other
> way, but it seemed pervasive enough in the current codebase that some
> incremental improvement could be gained by replacing these cases with a more
> specific tool for the job. We might still consider this tool to be "not
> ideal".

Having done that in another code base, I can see both merits and problems.

Our smart pointer behaved more or less like it's described above
(explicit acquire/release) and we've seen around 20% performance
improvement over shared_ptr due to savings on acquire/release
semantics. We had three derivative types of pointers
(Shared/Owned/Linked) which would just differ on the default behaviour
of construction / destruction, but all of them could still explicitly
call getClear / getLink / etc.

The downside was that almost every interaction with smart pointers had
to be carefully planned and there was a lot of room for errors,
especially from people that didn't know the context. In the end, the
amount of work that had to be put to make it work was similar than
when dealing with normal pointers, but you had to learn yet another
pointer semantics.

The marginal gain was that pointer interactions were explicit, making
it easier for someone *not* used to C++ pointer semantics to
understand when reading code, not necessarily when writing it. The
marginal lost was getting people that already knew the STL and Boost
smart pointer semantics to get confused.

Having done that, I still rather use normal pointers and have valgrind
/ sanitizers tell me when I screwed up.

My tuppence.

cheers,
--renato



More information about the llvm-dev mailing list