We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Category: C++ 11

C++11 Smart Pointer – Part 1: shared_ptr Tutorial and Examples

In this article we will discuss a smart pointer implementation provide by c++11 i.e. shared_ptr. What is std::shared_ptr<> ? shared_ptr is a kind of Smart Pointer class provided by c++11, that is smart enough to automatically delete the associated pointer when its not used anywhere. Thus helps us to completely remove the problem of memory leaks …

C++11 Smart Pointer – Part 1: shared_ptr Tutorial and ExamplesRead More

C++11 Smart Pointer – Part 2: shared_ptr and Custom Deletor

In this article we will discuss how to use custom deleter with std::shared_ptr. When a shared_ptr object goes out of scope, its destructor is called. Inside its destructor it decrements the reference count by 1 and if new value of reference count is 0 then it deletes the associated raw pointer. Advertisements To delete the …

C++11 Smart Pointer – Part 2: shared_ptr and Custom DeletorRead More

C++11 Smart Pointer – Part 4: Create shared_ptr objects carefully

We should create shared_ptr objects carefully. Checkout below two cases, [showads ad=inside_post] Advertisements 1.) Try not to use same raw pointer for creating more than one shared_ptr object because in that case different shared_ptr objects will not get to know that they are sharing the pointer with any other shared_ptr objects. How this can create …

C++11 Smart Pointer – Part 4: Create shared_ptr objects carefullyRead More

C++11 Smart Pointer – Part 3: shared_ptr vs Pointer

In this article we will compare C++11 Smart Pointer Implementation shared_ptr and a normal pointer. Let’s compare shared_ptr and raw pointer based on following aspects i.e. Advertisements Missing ++, – – and [] operator In comparison to a raw pointer, shared_ptr provides only these operators 1.) -> , * 2.)  Comparison Operators Frequently Asked: C++11 …

C++11 Smart Pointer – Part 3: shared_ptr vs PointerRead More

C++11 Smart Pointer – Part 5: shared_ptr, Binary trees and the problem of Cyclic References

bst

Main advantage of shared_ptr is that it automatically releases the associated memory when not used any more. But if we don’t use shared_ptr carefully then this advantage can turn into a disadvantage. Let’s look how, Advertisements Suppose I have to design a binary tree and in it the node contains a pointer to left and …

C++11 Smart Pointer – Part 5: shared_ptr, Binary trees and the problem of Cyclic ReferencesRead More

Using std::find & std::find_if with User Defined Classes

std::find and std::find_if algorithms are used to find first element in the given range. In this article we will see how to use std::find and std::find_if algorithm with user defined datatypes i.e. Classes & Structures. Advertisements Internally std::find algorithm uses the == operator for comparisons. For built-in data types like int, std::string etc operator == …

Using std::find & std::find_if with User Defined ClassesRead More

C++11 Multithreading – Part 1 : Three Different ways to Create Threads

In this article we will discuss how to create threads in C++11 using std::thread. Introduction to C++11 Thread Library Original C++ Standard supported only single thread programming. The new C++ Standard (referred to as C++11 or C++0x) was published in 2011. In C++11 a new thread library is introduced. Advertisements Compilers Required:  Linux: gcc 4.8.1 …

C++11 Multithreading – Part 1 : Three Different ways to Create ThreadsRead More

C++11 Multithreading – Part 2: Joining and Detaching Threads

In this article we will discuss about joining and detaching of std::thread. Joining Threads with std::thread::join() Once a thread is started then another thread can wait for this new thread to finish. For this another need need to call join() function on the std::thread object i.e. Advertisements std::thread th(funcPtr); // Some Code th.join(); Let’s see …

C++11 Multithreading – Part 2: Joining and Detaching ThreadsRead More

C++11 Multithreading – Part 3: Carefully Pass Arguments to Threads

To Pass arguments to thread’s associated callable object or function just pass additional arguments to the std::thread constructor. By default all arguments are copied into the internal storage of new thread. Lets look at an example Advertisements Passing simple arguments to a std::thread in C++11 #include <iostream> #include <string> #include <thread> void threadCallback(int x, std::string …

C++11 Multithreading – Part 3: Carefully Pass Arguments to ThreadsRead More

C++11 Multithreading – Part 4: Data Sharing and Race Conditions

Order of Executions Of Commands

In multithreading environment data sharing between threads is very easy. But this easy sharing of data can cause problems in application. One such problem is Race Condition. What is a Race Condition? Race condition is a kind of a bug that occurs in multithreaded applications. Advertisements When two or more threads perform a set of …

C++11 Multithreading – Part 4: Data Sharing and Race ConditionsRead More

Cart

Your Cart is Empty

Back To Shop