multi_array with large dimensions crashes
Hi all, I have just started to use boost libs. I am trying to create a large float array (mandatory for my purpose). it works fine till certain limit, but crashes above that. I think it about allocating memory in the stack. My code is like this typedef boost::multi_array<float,3> array_type; typedef array_type::index index; array_type Array(boost::extents[xDim][yDim][zDim]);//500,300,400 for instance Can some one help me to resolve this? Thanks Jothy
On 23.8.2011. 12:18, Jothy wrote:
Hi all,
I have just started to use boost libs. I am trying to create a large float array (mandatory for my purpose). it works fine till certain limit, but crashes above that. I think it about allocating memory in the stack.
My code is like this
typedefboost::multi_array<float,3>array_type; typedefarray_type::indexindex; array_typeArray(boost::extents[xDim][yDim][zDim]);//500,300,400 for instance
Can some one help me to resolve this?
I am not familiar with multi_array, but it seems that you are creating a
1GB object on the stack. This will almost always crash. Try creating it on the heap instead. Be prepared for std::bad_alloc.
HTH
Thanks for pointing this out. But how to do this? I am new to c++. Jothy On Tue, Aug 23, 2011 at 10:42 PM, Juraj Ivančić <juraj.ivancic@gmail.com>wrote:
On 23.8.2011. 12:18, Jothy wrote:
Hi all,
I have just started to use boost libs. I am trying to create a large float array (mandatory for my purpose). it works fine till certain limit, but crashes above that. I think it about allocating memory in the stack.
My code is like this
typedefboost::multi_array<**float,3>array_type; typedefarray_type::indexindex; array_typeArray(boost::**extents[xDim][yDim][zDim]);//**500,300,400 for instance
Can some one help me to resolve this?
1GB object on the stack. This will almost always crash. Try creating it on
I am not familiar with multi_array, but it seems that you are creating a the heap instead. Be prepared for std::bad_alloc.
HTH
______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**users<http://lists.boost.org/mailman/listinfo.cgi/boost-users>
I am not familiar with multi_array, but it seems that you are creating a 1GB object on the stack. This will almost always crash. Try creating it on the heap instead. Be prepared for std::bad_alloc.
But how to do this? I am new to c++.
I suggest you to either 1. read on the operators "new" and "delete" or 2. use a std::vector to allocate the memory then use a boost::multi_array_ref to refer to it. Here's an example: #include <vector> #include <boost/multi_array.hpp> int main() { typedef float data_type; typedef std::vector<data_type> array_storage_type; typedef boost::multi_array_ref<data_type,3> array_ref_type; array_ref_type::size_type xDim(500), yDim(300), zDim(400); array_storage_type Storage(xDim*yDim*zDim); array_ref_type Array(&Storage.front(),boost::extents[xDim][yDim][zDim]); // You may now use Array as usual. } Hope it helps, Pierre-André Noël On Wed, Aug 24, 2011 at 5:20 AM, Jothy <jothybasu@gmail.com> wrote:
Thanks for pointing this out.
But how to do this? I am new to c++.
Jothy
On Tue, Aug 23, 2011 at 10:42 PM, Juraj Ivančić <juraj.ivancic@gmail.com>wrote:
On 23.8.2011. 12:18, Jothy wrote:
Hi all,
I have just started to use boost libs. I am trying to create a large float array (mandatory for my purpose). it works fine till certain limit, but crashes above that. I think it about allocating memory in the stack.
My code is like this
typedefboost::multi_array<**float,3>array_type; typedefarray_type::indexindex; array_typeArray(boost::**extents[xDim][yDim][zDim]);//**500,300,400 for instance
Can some one help me to resolve this?
1GB object on the stack. This will almost always crash. Try creating it on
I am not familiar with multi_array, but it seems that you are creating a the heap instead. Be prepared for std::bad_alloc.
HTH
______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**users<http://lists.boost.org/mailman/listinfo.cgi/boost-users>
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks very much Pierre. Is this line correct it get compile errors at this line array_ref_type::size_type xDim(500), yDim(300), zDim(400); should it be like int(300) or float(300), some thing lie that Jothy On Wed, Aug 24, 2011 at 3:51 PM, Pierre-Andre Noel < noel.pierre.andre@gmail.com> wrote:
I am not familiar with multi_array, but it seems that you are creating a 1GB object on the stack. This will almost always crash. Try creating it on the heap instead. Be prepared for std::bad_alloc.
But how to do this? I am new to c++.
I suggest you to either 1. read on the operators "new" and "delete" or 2. use a std::vector to allocate the memory then use a boost::multi_array_ref to refer to it. Here's an example:
#include <vector> #include <boost/multi_array.hpp>
int main() { typedef float data_type; typedef std::vector<data_type> array_storage_type; typedef boost::multi_array_ref<data_type,3> array_ref_type;
array_ref_type::size_type xDim(500), yDim(300), zDim(400); array_storage_type Storage(xDim*yDim*zDim); array_ref_type Array(&Storage.front(),boost::extents[xDim][yDim][zDim]); // You may now use Array as usual. }
Hope it helps,
Pierre-André Noël
On Wed, Aug 24, 2011 at 5:20 AM, Jothy <jothybasu@gmail.com> wrote:
Thanks for pointing this out.
But how to do this? I am new to c++.
Jothy
On Tue, Aug 23, 2011 at 10:42 PM, Juraj Ivančić <juraj.ivancic@gmail.com>wrote:
On 23.8.2011. 12:18, Jothy wrote:
Hi all,
I have just started to use boost libs. I am trying to create a large float array (mandatory for my purpose). it works fine till certain limit, but crashes above that. I think it about allocating memory in the stack.
My code is like this
typedefboost::multi_array<**float,3>array_type; typedefarray_type::indexindex; array_typeArray(boost::**extents[xDim][yDim][zDim]);//**500,300,400 for instance
Can some one help me to resolve this?
1GB object on the stack. This will almost always crash. Try creating it on
I am not familiar with multi_array, but it seems that you are creating a the heap instead. Be prepared for std::bad_alloc.
HTH
______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**users<http://lists.boost.org/mailman/listinfo.cgi/boost-users>
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Is this line correct it get compile errors at this line
array_ref_type::size_type xDim(500), yDim(300), zDim(400);
It seems ok to me, and compiles on gcc. However, I am not familiar with other compilers... Maybe try to replace it with: typedef array_ref_type::size_type size_type; size_type xDim(500); size_type yDim(300); size_type zDim(400); or, if it still does not work: typedef unsigned int size_type; size_type xDim = 500; size_type yDim = 300; size_type zDim = 400; Pierre-André On Wed, Aug 24, 2011 at 11:18 AM, Jothy <jothybasu@gmail.com> wrote:
Thanks very much Pierre.
Is this line correct it get compile errors at this line
array_ref_type::size_type xDim(500), yDim(300), zDim(400);
should it be like int(300) or float(300), some thing lie that
Jothy
On Wed, Aug 24, 2011 at 3:51 PM, Pierre-Andre Noel < noel.pierre.andre@gmail.com> wrote:
I am not familiar with multi_array, but it seems that you are creating a >1GB object on the stack. This will almost always crash. Try creating it on the heap instead. Be prepared for std::bad_alloc.
But how to do this? I am new to c++.
I suggest you to either 1. read on the operators "new" and "delete" or 2. use a std::vector to allocate the memory then use a boost::multi_array_ref to refer to it. Here's an example:
#include <vector> #include <boost/multi_array.hpp>
int main() { typedef float data_type; typedef std::vector<data_type> array_storage_type; typedef boost::multi_array_ref<data_type,3> array_ref_type;
array_ref_type::size_type xDim(500), yDim(300), zDim(400); array_storage_type Storage(xDim*yDim*zDim); array_ref_type Array(&Storage.front(),boost::extents[xDim][yDim][zDim]); // You may now use Array as usual. }
Hope it helps,
Pierre-André Noël
On Wed, Aug 24, 2011 at 5:20 AM, Jothy <jothybasu@gmail.com> wrote:
Thanks for pointing this out.
But how to do this? I am new to c++.
Jothy
On Tue, Aug 23, 2011 at 10:42 PM, Juraj Ivančić <juraj.ivancic@gmail.com
wrote:
On 23.8.2011. 12:18, Jothy wrote:
Hi all,
I have just started to use boost libs. I am trying to create a large float array (mandatory for my purpose). it works fine till certain limit, but crashes above that. I think it about allocating memory in the stack.
My code is like this
typedefboost::multi_array<**float,3>array_type; typedefarray_type::indexindex; array_typeArray(boost::**extents[xDim][yDim][zDim]);//**500,300,400 for instance
Can some one help me to resolve this?
1GB object on the stack. This will almost always crash. Try creating it on
I am not familiar with multi_array, but it seems that you are creating a the heap instead. Be prepared for std::bad_alloc.
HTH
______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**users<http://lists.boost.org/mailman/listinfo.cgi/boost-users>
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
You mean 500,300,400 are the required dimesnions and xDim,yDim,zDim are site_type parameters. So the code should be like below I guess for an array of [x][y][z] array_ref_type::size_type xDim(x), yDim(y), zDim(z); array_storage_type Storage(xDim*yDim*zDim); array_ref_type Array(&Storage.front(),boost::extents[xDim][yDim][zDim]); Thanks Jothy On Wed, Aug 24, 2011 at 3:51 PM, Pierre-Andre Noel < noel.pierre.andre@gmail.com> wrote:
I am not familiar with multi_array, but it seems that you are creating a 1GB object on the stack. This will almost always crash. Try creating it on the heap instead. Be prepared for std::bad_alloc.
But how to do this? I am new to c++.
I suggest you to either 1. read on the operators "new" and "delete" or 2. use a std::vector to allocate the memory then use a boost::multi_array_ref to refer to it. Here's an example:
#include <vector> #include <boost/multi_array.hpp>
int main() { typedef float data_type; typedef std::vector<data_type> array_storage_type; typedef boost::multi_array_ref<data_type,3> array_ref_type;
array_ref_type::size_type xDim(500), yDim(300), zDim(400); array_storage_type Storage(xDim*yDim*zDim); array_ref_type Array(&Storage.front(),boost::extents[xDim][yDim][zDim]); // You may now use Array as usual. }
Hope it helps,
Pierre-André Noël
On Wed, Aug 24, 2011 at 5:20 AM, Jothy <jothybasu@gmail.com> wrote:
Thanks for pointing this out.
But how to do this? I am new to c++.
Jothy
On Tue, Aug 23, 2011 at 10:42 PM, Juraj Ivančić <juraj.ivancic@gmail.com>wrote:
On 23.8.2011. 12:18, Jothy wrote:
Hi all,
I have just started to use boost libs. I am trying to create a large float array (mandatory for my purpose). it works fine till certain limit, but crashes above that. I think it about allocating memory in the stack.
My code is like this
typedefboost::multi_array<**float,3>array_type; typedefarray_type::indexindex; array_typeArray(boost::**extents[xDim][yDim][zDim]);//**500,300,400 for instance
Can some one help me to resolve this?
1GB object on the stack. This will almost always crash. Try creating it on
I am not familiar with multi_array, but it seems that you are creating a the heap instead. Be prepared for std::bad_alloc.
HTH
______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**users<http://lists.boost.org/mailman/listinfo.cgi/boost-users>
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Jothy
-
Juraj Ivančić
-
Pierre-Andre Noel