exeやdllにPDBの絶対パスではなくファイル名だけ含める方法
以下のコンパイルオプションを指定する。
/pdbpath:none
WinDbgを使ってハンドル(カーネルオブジェクト)のリークをデバッグする方法
1. !htrace -enable
2. !handle コマンドでリーク前のハンドル使用状況を出力し、テキストに保存
3. アプリケーションを動かしてリークさせる
4. !handle コマンドでリーク後のハンドル使用状況を出力し、テキストに保存
5. diff BeforeLeak.txt AfterLeak.txt | grep '> Handle' > LeakHandles.txt
6. LeakHandles.txt をエディタで開いて、"> Handle "を"0x"に置換してリークしたと疑われるハンドルIDのリスト完成
7. .foreach /f (hid "C:\LeakHandles.txt") { !htrace hid 1 }
これで、リークしたと疑われるハンドルを最後に操作したコードのスタックトレースが表示されます。
WinDbgすごい!
int型の配列へのconst参照を返す関数
const int (&GetArray())[4] {
const static int s_array[4] = {1, 2, 3, 4};
return s_array;
}まずはコード。
template<class Derived>
class Base {
public:
void Process() {
// 派生クラスのメソッド呼び出し
static_cast<Derived*>(this)->SubProcess();
}
};
class Hoge : public Base<Hoge> {
public:
void SubProcess() {
std::cout << "Hoge!" << std::endl;
}
};
テンプレートクラスにネストされた、テンプレートクラスのテンプレートメソッドの実装を
クラスの定義と切り離してみました。
Before:
template<class T>
struct Hoge
{
template<class U>
struct NestedHoge
{
template<class V>
void Process()
{
std::cout << "Hoge Hoge!!" << std::endl;
}
};
};
template<class T>
struct Hoge
{
template<class U>
struct NestedHoge
{
template<class V>
void Process();
};
};
template<class T>
template<class U>
template<class V>
inline void Hoge<T>::NestedHoge<U>::Process()
{
std::cout << "Hoge Hoge!!" << std::endl;
}
整数を2のべき乗で割り算したいとき、割り算の代わりに右算術シフトを使うことがあります。
特に割り算の処理コストが無視できないときにはよく右算術シフトを利用します。
が、今日1つ落とし穴があることに気付きました。
(-1) >> 1
© Blogger template 'Isolation' by Ourblogtemplates.com 2008
Back to TOP