Monthly Archives: November 2009

why do I use alloca

alloca function allocates memory from stack, thus is much faster than heap and is released automatically when function exit. At first look it like like declare a char array, but the difference is that you can only declare array of … Continue reading

Posted in CPP | 2 Comments

std::stack, std::queue and std::priority_queue

The interesting fact is that std::queue and std::priority_queue has different interface – std::queue has front(), but std::priority_queue has top(). #include <stack>#include <list>#include <iostream>#include <string>#include <queue> template<typename ContainerType>void fill_container(ContainerType& cnt){    cnt.push(‘a’);    cnt.push(‘0’);    cnt.push(‘b’);    cnt.push(‘c’);} void main(){    typedef std::stack< char, std::list<char> > … Continue reading

Posted in CPP | Leave a comment

exception in ctor

operator new return NULL if ctor throw exception, this will leads to resource leak, and other possible problem like lock is not released. // ctor.cpp : test throw exception in ctor.// cl -EHsc -d1reportSingleClassLayoutCtorWithException ctor.cpp #define _CRTDBG_MAP_ALLOC#include <tchar.h>#include <stdlib.h>#include <crtdbg.h>#include … Continue reading

Posted in CPP | Leave a comment

boost.program_options crash

A program linking with libboost_program_options-vc90-mt-gd-1_35.lib crashed at desc.add_options(), but the release version worked. At last it turned out to be due to mixed usage of debug version CRT and release version CRT – the program in trouble linked to some … Continue reading

Posted in CPP | Leave a comment