Empirical
Namespaces | Functions
mem_track.h File Reference

A set of macros to track how many instances of specific classes are made. More...

#include <map>
#include <string>
#include <sstream>
#include "alert.h"

Go to the source code of this file.

Namespaces

 emp
 If we are in emscripten, make sure to include the header.
 
 emp::internal
 

Functions

static std::map< std::string, int > & emp::internal::TrackMem_GetMap ()
 
static std::string emp::internal::TrackMem_Status ()
 
static void emp::internal::TrackMem_Inc (const std::string &class_name)
 
static void emp::internal::TrackMem_Dec (const std::string &class_name)
 
static int emp::internal::TrackMem_Count (const std::string &class_name)
 

Detailed Description

A set of macros to track how many instances of specific classes are made.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Date
2015-2017
Note
Status: BETA

One way of tracking memory leaks is to simply count instances of classes. The macros here simplify this process.

To setup, every constructor for a class must incude EMP_TRACK_CONSTRUCT(CLASS_NAME), and every destructor must have EMP_TRACK_DESTRUCT(CLASS_NAME). Make sure to avoid implicit constructors/destructors or counts will be off.

To collect information, EMP_TRACK_COUNT(CLASS_NAME) will provide the current count for a specific class, and EMP_TRACK_STATUS will translate into a string providing information about all available classes.

Developer notes:

Todo:
Currently having issues with the memory map corruption. Perhaps it needs to use onload? Also, can try using JS maps instead? (only when using Emscripten.)