メモリの割り当てにもう一度問題があり、その理由を理解できません。メモリ割り当て/ std :: stringコンストラクタでのヒープの破損
私はデバッグモードでプログラムを実行すると、私は(私はできるだけ正確にそれを翻訳してみました)次のエラーメッセージを受け取る:
WindowsはLogoColorDetector.exeにブレークポイントをトリガしました。私は問題は次の行で発生しているようだことがわかったプログラムをデバッグする場合これは、ヒープLogoColorDetector.exeに問題があることを示して破損やそのロードされたDLLの1 [...]
によって発生する可能性があります。
imgTrain [J]の画像オブジェクトが正しい_filePath文字列を持っている場合、私はすでに確認されているconst std::string& support::Image::getFilepath() const
{
return this->_filePath;
}
: -
std::string tmp = imgTrain2[j]->getFilepath();
getFilepath()次のように機能が実装されています。だから問題はどこか別のものだと思う。面白いことは、問題のある行を含む関数がうまくいくようだということです。関数が呼び出されるのは2回目ですが、関数自体に問題がないことが示されます。私は、任意のメモリを割り当てません。また私は、それがスタックトレースここでは誰のためのヘルプ、あるかもしれない場合はstd ::文字列
を介して間接的に行われているものを除き、関数内で何も削除します:
msvcr100d.dll!_heap_alloc_base(unsigned int size) Zeile 55 C
msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Zeile 431 + 0x9 Bytes C++
msvcr100d.dll!_nh_malloc_dbg_impl(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Zeile 239 + 0x19 Bytes C++
msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine) Zeile 302 + 0x1d Bytes C++
msvcr100d.dll!malloc(unsigned int nSize) Zeile 56 + 0x15 Bytes C++
msvcr100d.dll!operator new(unsigned int size) Zeile 59 + 0x9 Bytes C++
LogoColorDetector.exe!std::_Allocate<char>(unsigned int _Count, char * __formal) Zeile 36 + 0xf Bytes C++
LogoColorDetector.exe!std::allocator<char>::allocate(unsigned int _Count) Zeile 187 + 0xb Bytes C++
LogoColorDetector.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Copy(unsigned int _Newsize, unsigned int _Oldlen) Zeile 1933 + 0x12 Bytes C++
LogoColorDetector.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Grow(unsigned int _Newsize, bool _Trim) Zeile 1963 + 0x13 Bytes C++
LogoColorDetector.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right, unsigned int _Roff, unsigned int _Count) Zeile 902 + 0xe Bytes C++
LogoColorDetector.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right) Zeile 546 C++
LogoColorDetector.exe!compareClasses(support::ImageCollection * coll, support::ImageClass * cl1, support::ImageClass * cl2, float * mean, float * var) Zeile 111 + 0x22 Bytes C++
これを引き起こす可能性のある人は誰ですか?
ありがとうございました。
- 編集 -
は、Visualリークディテクタとの提案をしようとしました。上記のエラーメッセージがポップアップし、メモリが解放された後にメモリが変更されたという瞬間までは、何も表示されません。どのオブジェクトがメモリアドレスに関連付けられているかを調べる方法はありますか?メモリダンプはあまり役に立ちません。
物事をよりmyterious作るために、私は次の行を追加してみました:今、最初の行が正しく実行され、2行目に障害が発生した
std::string tmp = imgTrain2[j]->getFilepath();
std::string t2Path = imgTrain2[j]->getFilepath();
を。
参照の代わりにコピーを返すgetFilepath()はどうでしょうか? 'const std :: string support :: Image :: getFilepath()const' – karlphillip