Products Tools Articles Code Demoscene Links Contact
Products Tools Articles Code Demoscene Links Contact
» Base Framework » Physics Abstraction Layer (PAL) » Memory Debugging with Microsoft VC » Terminating own Process » STL comma-delimited reading » Microsoft Libraries

Base Framework

Never to be completed. Always sitting as: Nearly Complete - I will probably release bits and pieces of this over the years as they become 'complete'. Most of this framework is available in the PAL and ImprovCV projects.

The framework incldes: Memory management (stack/new/autodelete), Abstract pluggable factory patterns, versioning, base components, OS filesystem abstraction, OS dynamic library (shared library) abstraction, error logging, serialization, OS socket abstraction, and more...

^ top

Physics Abstraction Layer (PAL)

The Physics Abstraction Layer (PAL) provides a unified interface to a number of different physics engines. This enables the use of multiple physics engines within one application. See pal.sourceforge.net

^ top

Memory Debugging with Microsoft VC

This is just a small code block showing how to use microsofts CRT debug heap.

To get a listing of all memory leaks, you simply need to include crtdbg.h, and then set the debug flag, using the function _CrtSetDbgFlag.

Here is some example code:

#include <crtdbg.h>
int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // Get current flag
flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
_CrtSetDbgFlag(flag); // Set flag to the new value
If you want to see which calls to new are causing the memory leaks and have the MSVC IDE point to the lines of code which allocate the memory that causes the leak, simply redefine new as such:

#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
All done!

More information on setting up the debug heap here: The CRT Debug Heap

^ top

Terminating own Process

For the record, you probably shouldn't be doing this, however, just like 'delete this' has good uses, likewise the following snippet of code:
This is especially handy if your working on some small demo application that has a nasty habit of crashing on termination. (If you actually want to fix the problem, its probably due to memory allocations or your deconstructors for static objects).
In any case, its fun just to terminate your currently running process like this : especially if you want to avoid the exit() code.

^ top

STL comma-delimited reading

There is a better way to read comma delimited data with the STL (try boost), but I find myself hacking this snippet out all the time:
void CommaDelimited(std::string s) {
	std::string::size_type pos = 0;
	std::string::size_type last_pos = 0;
	pos = s.find_first_of(",");
	while (pos!=std::string::npos) {
		//do something with: s.substr(last_pos,pos-last_pos)
		pos = s.find_first_of(",",pos);
	//do something with: s.substr(last_pos)

^ top

Microsoft Libraries

Here are as many of Microsofts Visual C libraries as I have, as well as any other likely missing libraries you might have:

Microsoft provides information about the libraries MSVC will link with here