Memory

Overloading Operator new and delete 1

It happens quite too often that a C++ application allocates memory but doesn't deallocate it. This is the job of the operator to new and delete. Thanks to them both, you can explicitly manage the memory management of an application.

Read more
Views: 83499

Explicit Memory Management

Explicit memory management has in C++ a high complexity but also provides great functionality. Sadly, this special domain is not so known in C++. For example, you can directly create objects in static memory, in a reserved area, or even a memory pool. That is functionality, which is often key in safety-critical applications in the embedded world. Before the harvest is the work, therefore, I will give in this post an overview, before I dive deeper into the details.

Read more
Views: 28030

Garbage Collection - No Thanks

C++ is old-fashioned. C++ has no garbage collection. No garbage collection? Right! Old fashioned? Wrong!

Read more
Tags: Memory
Views: 71418

Move Semantis: Two Nice Properties

I will talk about two nice properties of the move semantic in this post that is not so often mentioned. Containers of the standard template library (STL) can have non-copyable elements. The copy semantic is the fallback for the move semantic. Irritated? I hope so!

Read more
Tags: Memory, move
Views: 26416

Copy versus Move Semantics: A few Numbers

A lot was written about the advantages of move semantics to copy semantics. Instead of an expensive copy operation, you can use a cheap move operation. But what does that mean? In this post, I will compare the copy and move semantics performance for the Standard Template Library (STL) containers. 

Read more
Tags: Memory, move
Views: 66128

std::array - Dynamic Memory, no Thanks

std::array combines the best of two worlds. On the one hand, std::array has the size and efficiency of a C array; on the other hand, std::array has the interface of a std::vector. 

Read more
Tags: Memory
Views: 117969

Automatic Memory Management of the STL Containers

One of the significant advantages of a C++ string to a C string and of a std::vector to a C array is that both C++ containers automatically manage their memory. Of course, that holds for all further containers of the Standard Template Library. In this post, I will look closer at the automatic memory management of std::vector and std::string.

Read more
Tags: Memory
Views: 38021

std::weak_ptr

std::unique_ptr models the concept of exclusive ownership, std::shared_ptr the concept of shared ownership. If I stick to this picture then std::weak_ptr models the concept of temporary ownership because it borrows the resource from a std::shared_ptr. There is one dominant reason for having a std::weak_ptr in C++: breaking of cyclic references of std::shared_ptr's.

Read more
Views: 60119

Specialities of std::shared_ptr

After I draw the big picture of a std::shared_ptr in the last post, I want to present two special aspects of this smart pointer in this post. First, I show with std::shared_from_this how to create a std::shared_ptr from an object; second, I'm interested in the question to the answer: Should a function take a std::shared_ptr by copy or by reference? The numbers are quite interesting.

Read more
Views: 25150

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
Views: 43663

Stay Informed about my Mentoring

 

Mentoring

English 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)

Course: C++ Fundamentals for Professionals

Course: The All-in-One Guide to C++20

Course: Master Software Design Patterns and Architecture in C++

Subscribe to the newsletter (+ pdf bundle)

All tags

Blog archive

Source Code

Visitors

Today 4943

Yesterday 4550

Week 4943

Month 26617

All 12104826

Currently are 183 guests and no members online

Kubik-Rubik Joomla! Extensions

Latest comments