C++ London Meetup: Pointers and Errors

This C++ Meetup, held at Skillsmatter, was split into two talks.

The first by Ervin Bosenbacher was Modern C++ Smart Pointers in C++ 17, 20 & Beyond. It served as a good introduction to smart pointers and motivation for using them, particularly for developers new to C++ (or those who had not yet started to use C++11). The talk covered:

  • Issues with use of raw pointers (ownership, how to delete, exception safety)
  • std::auto_ptr and why not to use it
  • std::unique_ptr and std::shared_ptr – trade-offs and performance figures
  • Use RAII – assign a raw pointer to a smart pointer as soon as it is allocated

A good point was that use of std::shared_ptr means that other parts of the codebase can modify an object that you’re sharing – so synchronisation primitives (such as a std::mutex) are needed to ensure access to the underlying resource is thread-safe. This is often overlooked because the reference counting *is* thread-safe. In C++20, we will get atomic smart pointers to help with this.

Discussing std::shared_ptr with a friend, I also learnt about a secret constructor on std::shared_ptr to share the resource control block and keep a parent pointer alive.

The second talk was Arno Schödl on Error Handling. He described how Think Cell grade errors into different levels, each with a clearly defined error handling strategy. The aim is to minimise coding and testing overhead whilst maximising the ability to capture and debug error conditions.

Leave a comment

Filed under C++, Meetup, Programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.