boost.filesystem create_directories抛出std :: bad_alloc [英] boost.filesystem create_directories throws std::bad_alloc
问题描述
我有一个使用Boost 1.47.0的Visual Studio 2008 C ++ 03应用程序,该应用程序在Windows XP SP3中运行.
I have a Visual Studio 2008 C++03 application using Boost 1.47.0 running in Windows XP SP3.
调用boost::filesystem::create_directories( L"c:\\foo\\bar" );
引发std::bad_alloc
异常.
在输出窗口中,我看到一条调试堆消息:"HEAP [test.exe]:无效的分配大小-CDCDCDCE(超过7ffdefff)"
In the output window, I see a debug heap message: "HEAP[test.exe]: Invalid allocation size - CDCDCDCE (exceeded 7ffdefff)"
调用堆栈显示boost.filesystem在Microsoft标准库文件xlocale第309行中创建了新的语言环境和最后可见的代码行.
The callstack shows boost.filesystem creating a new locale and last visible line of code in the Microsoft standard library file xlocale line 309.
msvcp90.dll!std::_Allocate<char>() + 0x17 bytes
msvcp90.dll!std::allocator<char>::allocate() + 0xf bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Copy() + 0x70 bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Grow() + 0x26 bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign() + 0x50 bytes
msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >() + 0x24 bytes
msvcp90.dll!std::locale::_Locimp::_Locimp() + 0x47 bytes
> test.exe!std::locale::locale<windows_file_codecvt>(const std::locale & _Loc={...}, const windows_file_codecvt * _Facptr=0x00b48f60) Line 309 + 0x69 bytes C++
test.exe!`anonymous namespace'::default_locale() Line 735 C++
test.exe!`anonymous namespace'::path_locale() Line 777 + 0x2a bytes C++
test.exe!boost::filesystem3::path::wchar_t_codecvt_facet() Line 797 + 0x25 bytes C++
test.exe!boost::filesystem3::path::codecvt() Line 388 + 0x5 bytes C++
test.exe!boost::filesystem3::path::path<wchar_t const *>(const wchar_t * begin=0x00b460f8, const wchar_t * end=0x00b46116) Line 162 + 0x5 bytes C++
test.exe!boost::filesystem3::path::parent_path() Line 313 + 0x57 bytes C++
test.exe!boost::filesystem3::detail::create_directories(const boost::filesystem3::path & p={...}, boost::system::error_code * ec=0x00000000) Line 832 + 0x13 bytes C++
test.exe!boost::filesystem3::create_directories(const boost::filesystem3::path & p={...}) Line 318 + 0x29 bytes C++
test.exe!wmain(int __formal=1, int __formal=1) Line 112 + 0xc bytes C++
test.exe!__tmainCRTStartup() Line 583 + 0x19 bytes C
test.exe!wmainCRTStartup() Line 403 C
kernel32.dll!_BaseProcessStart@4() + 0x23 bytes
有人可以建议如何解决此问题吗?
Can anybody suggest how to fix this issue?
EDIT (我更新为1.50.0).问题仍然存在.
EDIT I updated to boost 1.50.0. The issue remains.
推荐答案
这个问题闻起来像是_SECURE_SCL
中的不匹配(或者也许是有些相关的_HAS_ITERATOR_DEBUGGING
-但我怀疑后者,因为调用堆栈指示非-debug版本).有关某些信息,请参见 https://stackoverflow.com/a/6104239/12711 并确保已定义_SECURE_SCL
This problem smells like a mismatch in _SECURE_SCL
(or maybe the somewhat related _HAS_ITERATOR_DEBUGGING
- but I doubt the latter, since the call stack indicates a non-debug build). See https://stackoverflow.com/a/6104239/12711 for some info and make sure _SECURE_SCL
is defined the same way in the builds for test.exe
and the boost filesystem library linked in.
AFAIK,boost将使用VC默认值(即使在VS2008的发行版中也为_SECURE_SCL=1
),因此,如果您设置_SECURE_SCL=0
,可能就是问题所在.
AFAIK, boost will use the VC default (which is _SECURE_SCL=1
even in release builds for VS2008), so if you're setting _SECURE_SCL=0
that may be the problem.
这篇关于boost.filesystem create_directories抛出std :: bad_alloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!