【发布时间】:2011-08-22 18:39:46
【问题描述】:
我有一个适用于 ARMV4I Windows Mobile 6 的 Visual Studio 2008 C++ 应用程序,我使用 boost::shared_ptr<> 管理一个相当大的对象 (4KB)。不幸的是,boost::make_shared<> 会导致访问冲突异常。
我的代码:
struct Foo
{
char a[ 4 * 1024 - 1 ];
};
int _tmain( int argc, _TCHAR* argv[] )
{
boost::shared_ptr< Foo > f = boost::make_shared< Foo >(); // Access Violation
return 0;
}
异常调用栈:
test.exe!boost::detail::sp_ms_deleter<o>::sp_ms_deleter<o>(void) Line: 60, Byte Offsets: 0x18 C++
test.exe!boost::make_shared<o>(void) Line: 106, Byte Offsets: 0x5c C++
test.exe!wmain(int argc = 1, wchar_t** argv = 0x01b40060) Line: 81, Byte Offsets: 0x18 C++
test.exe!mainWCRTStartup(HINSTANCE__* hInstance = 0x00000003, HINSTANCE__* hInstancePrev = 0x00000000, unsigned short* lpszCmdLine = 0x00000003, int nCmdShow = 0) Line: 188, Byte Offsets: 0x94 C++
异常的位置(boost\smart_ptr\make_shared.hpp):
template< class T > class sp_ms_deleter
{
/* snip! */
public:
sp_ms_deleter(): initialized_( false )
{ // line: 60 this = NULL
}
/* snip! */
为 x86 Windows 编译时不会出现此问题。像这样使用 shared_ptr 时也不会出现此问题:
boost::shared_ptr< Foo > f1 = boost::shared_ptr< Foo >( new Foo );
谁能解释发生了什么以及为什么这仅在 ARMV4I Windows Mobile 6 上出现问题?
谢谢, 保罗H
【问题讨论】:
-
@ildjarn - 1.45.0 和 STLPort 5.2.1
-
这看起来可能是平台特定的提升/智能指针错误;大概是因为在 ARM 上分配大型结构的某种复杂性。我建议将其发布到邮件列表中。
-
@PaulH :您是否有机会使用 Boost 1.46.1 进行测试,以防万一它是自 1.45.0 以来修复的错误?如果它确实是 Boost 中的一个错误,那么我强烈怀疑
boost::alignment_of<>或boost::type_with_alignment<>是罪魁祸首。 -
@Autopulated :我怀疑
sp_ms_deleter(或其子对象)没有正确对齐,而不是它太大了。 -
@ildjarn - 我没有在 1.46.0 或 1.46.1 的更新列表中看到 shared_ptr,所以我认为没有任何改变。它们是否包括未在 boost.org 主页的新闻部分列出的更改?
标签: c++ boost windows-mobile