|
Boost Users : |
Subject: Re: [Boost-users] [shared_ptr] make_shared causes Access Violation
From: Paul Heil (paul.heil_at_[hidden])
Date: 2011-05-10 16:31:55
I can declare two instances of Foo with no error:
int _tmain( int argc, _TCHAR* argv[] )
{
Foo a;
Foo b;
return 0;
}
The linker options I'm using are /STACK 65536,4096. So, the stack should be
capable of handling 16 times sizeof( Foo ).
-PaulH
On Tue, May 10, 2011 at 3:17 PM, Krzysztof Czainski <1czajnik_at_[hidden]>wrote:
> 2011/5/10 Paul Heil <paul.heil_at_[hidden]>
>
>> I have a Visual Studio 2008 C++ application for ARMV4I Windows Mobile 6
>> where I'm using `boost::shared_ptr<>` to manage a fairly large object (4KB).
>> Unfortunately, `boost::make_shared<>` causes an Access Violation exception.
>> I am using Boost 1.45.0 with STLPort 5.2.1.
>>
>> 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 the exception (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! */
>>
>> This issue does not occur when compiling for x86 Windows. This issue also
>> does not occur when using the shared_ptr like this:
>>
>> boost::shared_ptr< Foo > f1 = boost::shared_ptr< Foo >( new Foo );
>>
>> Can anybody explain what's going on and why this is breaking only on
>> ARMV4I Windows Mobile 6?
>>
>> Thanks,
>> PaulH
>>
>
> My guess: stack overflow. If I remember correctly, 2 times sizeof( Foo )
> must fit on the stack when using make_shared.
>
> Regards,
> Kris
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net