c++ - boost::make_shared causes access violation -
i have visual studio 2008 c++ application armv4i windows mobile 6 i'm using boost::shared_ptr<>
manage large object (4kb). unfortunately, boost::make_shared<>
causes access violation exception.
my code:
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; }
the exception callstack:
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++
the location of exception (boost\smart_ptr\make_shared.hpp):
template< class t > class sp_ms_deleter { /* snip! */ public: sp_ms_deleter(): initialized_( false ) { // line: 60 = null } /* snip! */
this issue not occur when compiling x86 windows. issue not occur when using shared_ptr this:
boost::shared_ptr< foo > f1 = boost::shared_ptr< foo >( new foo );
can explain what's going on , why breaking on armv4i windows mobile 6?
thanks, paulh
probably it's alignment issue. don't know details of implementation, make_shared<>()
tries allocate shared_ptr<>
object , pointed-to object in 1 single allocation. causes 1 of 2 objects end @ address isn't aligned should be.
this explain why crashes on arm: architecture has stricter alignment requirements normal pc hardware. if int or pointer ends on "strange" address, program crash on arm while pc happily access data.
Comments
Post a Comment