c++ - Boost Pointers as a means of an array -
i'm converting c code open-source, c++11 style compatible code, uses boost. (purposefully not used c++ shared ptr implementation)
i've studied use of boost shared_ptrs vs unique_ptrs vs. raw pointers means of managing memory resources, based on intended ownership, etc.
i'm getting confused though, @ different layers of abstraction @ raw pointers can used , whether semantics translate boost.
i have templated class purposely composed of different structs make use of said structs.
example:
template <typename my_type> class : public base_a { ... typedef struct b { float* numbers; my_type* my_types; }; typedef struct c { b* b_types; }; }
this i'm getting confused. pointers used reference contiguous blocks of memory, right? because pointers, can use [] operator index offset of reference memory, , in way pointers not used reference objects, arrays of types well. again, guess can class can pointers , data structures, right?
so question mainly, how translate boost , how boost controls deallocation of nested data types, such structs , nested classes?
for example, if do, in main:
boost::shared_ptr<a> my_a(new a());
or
boost::unique_ptr<a> my_a(new a());
...when reference count goes 0, get's deallocated, mean of pointers composed of followed, , deallocated? need provide virtual destructor explicitly deletes atomics? or pointer variables, including float*, example, need weak_ptr's that?
if want smart-pointers arrays can use
std::unique_ptr<t[]>
- this- deletes using
delete[]
through default deleter - is specialized support
operator[]
c-style array indexing
- deletes using
boost::shared_array
boost::shared_ptr
t[]
instead oft*
that said, modern c++11 style suggests boost::array<>
or std::vector<>
instead
Comments
Post a Comment