Boost logo

Boost Users :

From: Jeffrey Jiang (gamedboy_at_[hidden])
Date: 2007-08-30 15:22:48


Hi,
I am new to boost, and is trying to implement shared_ptr solution to a 2d
array of pointers.

Eg
Character *** characters;

characters = new Character**[_info._l ];

for (int i=0; i< _info._l; i++){

    characters[i] = new Character* [_info._w];

    for( int j=0;j < _info._w; j++){

        characters[i][j] = 0;

    }

}

This is a sparse array, most of the pointers will be set to 0. As I could
not find much information about shared_array on line, I would like to check
is there any issue with this implementation.

boost::shared_array<boost::shared_array<boost::shared_ptr<Character>>>
characterGrid(new
boost::shared_array<boost::shared_ptr<Character>>[_info._l ]);

for( int i=0;i< _info._l; i++) {

    characterGrid[i] = boost::shared_array<boost::shared_ptr<Character>>(new
boost::shared_ptr<Character>[_info._w]);

    for( int j=0; j< _info._w; j++) {

        //is it alright for me to use an empty shared_ptr in this context to
init the array?

        characterGrid[i][j] = boost::shared_ptr<Character>();

    }

}

Thanks.

Jeffrey.


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