std::shared_ptr

std::shared_ptr's share the resource. The shared reference counter counts the number of owners. Copying a std::shared_ptr increases the reference count by one. Destroying a std::shared_ptr decreases the reference count by one. If the reference count becomes zero, the resource will automatically be released. 

Read more
Comments 48Views: 17274

std::unique_ptr

A std::unique_ptr manages automatically and exclusively the lifetime of its resource according to the RAII idiom. std::unique_ptr should be your first choice because it does its work without memory or performance overhead.

Read more
Add CommentViews: 19376

Memory and Performance Overhead of Smart Pointers

C++11 offers four different smart pointers. On two of them I will have a closer look in this post regarding memory and performance overhead. My first candidate std::unique_ptr takes exclusively care of the lifetime of one resource; std::shared_ptr shares the ownership of a resource with other std::shared_ptr's. I will state the result of my tests before I show you the raw numbers: There are only few reasons in modern C++ justifying the memory management with new and delete.

 

Read more
Comments 8Views: 74375

Careful Handling of Resources

The careful handling of resources - may it be for example memory, files or sockets - is a key concern of programming in C++. This holds in particular true for the embedded programming that is often characterized by limited resources. Therefore, I will write a few posts about this challenging and versatile topic.

Read more
Add CommentViews: 6019

Generalized Plain Old Data

Plain Old Data (POD) obeys the C standard layout. Therefore, you directly can apply the fast C functions memcopy, memmove, memset, or memcmp.

Read more
Tags: enum
Comments 1Views: 11099

Buckets, Capacity, and Load Factor

The hash function maps a potential infinite number of keys on a finite number of buckets. What is the strategy of the C++ runtime and how can you tailor it to your needs, that is what this article is all about.

Read more
Comments 3Views: 21724

Hash Functions

The reason for the constant access time (best cast) of the unordered associative containers are the hash functions. As ever, C++ offers a lot of ways to adjust the behaviour of the hash functions. On one hand, C++ has a lot of different hash functions; on the other hand, you can define your own hash function. You can even adjust the number of buckets.

Read more
Comments 3Views: 74059

Associative Containers - A simple Performance Comparison

Before I take a deeper look insight the interface of the hash tables - officially called unordered associative containers - I will at first compare the performance of the associative containers. The best candidates are std::unordered_map and the ordered pendant std::map because both are used most frequently.

Read more
Add CommentViews: 13307

Hash Tables

We missed hash table in C++ for a long time. They promise to have constant access time. C++11 has hash tables in four variations. The official name is unordered associative containers. Unofficially, they are called dictionaries or just simple associative arrays. 

Read more
Comments 4Views: 32740

Type-Traits: Performance Matters

If you look carefully, you see, type-traits have a big optimization potential. The type-traits support in the first step to analyse the code at the compile time and in the second step, to optimize the code based on that analysis. How is that possible? Dependent on the type of a variable a faster variant of an algorithm will be chosen.

Read more
Add CommentViews: 9793

My Newest E-Books

Course: Modern C++ Concurrency in Practice

Course: C++ Standard Library including C++14 & C++17

Course: Embedded Programming with Modern C++

Course: Generic Programming (Templates)

Subscribe to the newsletter (+ pdf bundle)

Blog archive

Source Code

Visitors

Today 4214

All 2925885

Currently are 181 guests and no members online

Kubik-Rubik Joomla! Extensions

Latest comments