Book Image

Boost C++ Application Development Cookbook

By : Antony Polukhin
Book Image

Boost C++ Application Development Cookbook

By: Antony Polukhin

Overview of this book

<p>Boost libraries are developed by professionals, tested on multiple platforms and processor architectures, and contain reliable solutions for a wide range of tasks. This Cookbook takes you on a journey of simplifying the process of application development and guides you through writing perfect applications fast.</p> <p>"Boost C++ Application Development Cookbook" provides you with a number of clear step-by-step recipes that will help you take advantage of the real power of Boost and C++, while giving you a good grounding in using it in any project.</p> <p>"Boost C++ Application Development Cookbook" looks at the Boost libraries, and breaks down the mystery and confusion about which library to use in which situation. It will take you through a number of clear, practical recipes that will help you to take advantage of the readily available solutions.</p> <p>Boost C++ Application Development Cookbook starts with teaching the basics of Boost libraries that are now mostly part of C++11 and leave no chance for memory leaks. Managing resources will become a piece of cake. We’ll see what kind of work can be done at compile time and what Boost containers can do. Do you think multithreading is a burden? Not with Boost. Think writing portable and fast servers is impossible? You’ll be surprised! Compilers and operating systems differ too much? Not with Boost. From manipulating images to graphs, directories, timers, files, strings – everyone will find an interesting topic.</p> <p>You will learn everything for the development of high quality fast and portable applications. Write a program once and then you can use it on Linux, Windows, MacOS, Android operating systems.</p>
Table of Contents (19 chapters)
Boost C++ Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Passing data quickly from one process to another


Sometimes we write programs that will communicate with each other a lot. When programs are run on different machines, using sockets is the most common technique for communication. But if multiple processes run on a single machine, we can do much better!

Let's take a look at how to make a single memory fragment available from different processes using the Boost.Interprocess library.

Getting ready

Basic knowledge of C++ is required for this recipe. Knowledge of atomic variables is also required (take a look at the See also section for more information about atomics). Some platforms require linking against the runtime library.

How to do it...

In this example we'll be sharing a single atomic variable between processes, making it increment when a new process starts and decrement when the process terminates:

  1. We'll need to include the following header for interprocess communications:

    #include <boost/interprocess/managed_shared_memory.hpp>
  2. Following...