# PlugScape : C++ memory checks and benchmarking

## Overview

A small library for C++/GNU/Linux to find bugs and memory leaks and benchmark your application. Available under the GPLv2 or any later version.

Bugs are found using contract programming and asserts, memory leaks are found with an overload of the new and delete operators.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details

## Installation Instructions

• install plugscape : $sudo dpkg -i plugscape_0.8-1_i386.deb ### Installation from source • Install CMake. • Install the Boost Libraries and more specifically Boost Date-Time if it is distributed in a different package for your operating system. • Download and extract the contents of the plugscape source archive. • Inside the newly created directory configure the package :$ cmake . .
• build the project : $make • (Optional) install it with administrator privileges :$ make install or \$ sudo make install . The location of the installed files is recorded in the file “install-manifest.txt” for later removal.

## How to use contract programming ?

Include the plugscape header :

Then use the following macros in your code : ”INVARIANT, REQUIRE, ENSURE, ASSERT, EXPECT”.
Link your program with the library libPlugScape.

Compile your project with the definition ”PLUGSCAPE_CONTRACT”. You can disable it later for a final release.

## How to find memory leaks ?

Include the plugscape header :

Instead of allocating memory with ”new”, use ”NEW”. Instead of unallocating memory with ”delete”, use ”DELETE”.

If you have already written your code and do not want to change any of it, you can add the following definition:

You will have to make sure that this macro is not defined before any standard header. defining the macro ”new” will not work with code such as ”operator new”. ”new” can only be used for memory allocation.

Link your program with the library libPlugScape.

## How to benchmark your application ?

Include the plugscape header :

Place function calls you want to test inside a BENCHMARK macro call.

Link your program with the library libPlugScape.

Compile your project with the definition PLUGSCAPE_BENCHMARK. You can disable it later for a final release.

## How to create new exceptions easily ?

in your header insert the line :

and in your C++ code, use it with throw EXCEPTION(YourException); .

## Why use plugscape exceptions ?

With plugscape, all exceptions inherit from plugscape::RuntimeError so that they can be caught in one simple catch statement. Moreover, the message what() will always include information about the file and line where the exception was thrown. PlugScape can also be configured to include the backtrace in the message.

## Demonstration

File used for this demo :