View on GitHub

Shared ptr

A minimal light and fast shared_ptr implementation designed to handle cases where boost/std::shared_ptr are not available

Download this project as a .zip file Download this project as a tar.gz file

shared_ptr is a minimal implementation of smart pointer, a subset of the C++11 std::shared_ptr or boost::shared_ptr.

The goals of this minimal shared_ptr are:


 Suported platforms:

Developements and tests are done under the following OSs :



To use this shared_ptr implementation, you only need to include the shared_ptr.hpp file from the source code of your projects.


Copyright (c) 2013 Sébastien Rombauts (

Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or copy at

Getting started

About std::shared_ptr:

About boost::shared_ptr:

First sample demonstrates how to create a shared_ptr to a class Xxx:

The Xxx class:

class Xxx
    doSomething(size_t len);

shared_ptr usage:

void func(void)
    // Create an empty (ie. NULL) p1 shared_ptr
    shared_ptr<Xxx> xPtr;

    if (true)
        // Create a new Xxx object, and give its ownership to the yPtr shared_ptr
        shared_ptr<Xxx> yPtr(new Xxx());

        // Access members functions/variables like with a raw pointer

        // Share ownership by making a copy of the shared_ptr (the reference counter reachs 2)
        xPtr = yPtr;

    } // yPtr is destroyed, but xPtr retains the ownership of the object


} // xPtr is destroyed, the reference counter drops to 0 thus the object is destroyed and the memory freed

How to contribute

GitHub website

The most efficient way to help and contribute to this wrapper project is to use the tools provided by GitHub:


You can also email me directly, I will answer any questions and requests.

Coding Style Guidelines

The source code use the CamelCase naming style variant where :