Boost logo

Boost Users :

Subject: [Boost-users] why is make_shared using so much of my stack....?
From: Michael Xu (mx2323_at_[hidden])
Date: 2011-02-05 19:01:18


Hi everyone,

I've been investigating our program's memory usage, and one of the spots
that I keep seeing the stack hitting its limit is when using
boost::make_shared.

I've written a simple test program, that completes fine when I use new...
but fails with a stack overflow when I use boost::make_shared
========================
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
using namespace std;
struct arr
{
char arg[1024*1024];
};

struct test
{
struct arr array[1024];
};

int main()
{
test * myTest = new test(); //complete!
if (!myTest)
 cout << "new alloc failed";
boost::shared_ptr<test> testPtr = boost::make_shared<test>(); //fails with
stack overflow!
 if (!testPtr)
{
cout << "alloc failed;";
 }
}
===========================

If you run this with a reasonable thread stack of 8 megabytes, it fails when
using boost::make_shared.

Here is the stack trace.....

#0 boost::shared_ptr<test>::shared_ptr<test,
boost::detail::sp_ms_deleter<test> >(test*,
boost::detail::sp_ms_deleter<test>) ()
#1 boost::shared_ptr<test> boost::make_shared<test>() ()
#2 main ()

Is there a reason this happens?

Thanks

michael



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