468,503 Members | 2,126 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,503 developers. It's quick & easy.

How to get the size of the array in boost::shared_array?

Hi,

I remember that the main difference between "int * a = new
std::complex<double>;" and "int *b = new std::complex<double>[10]" is
that the compiler keep the size of the array that "b" pointing to. So
"delete [] b" will call "std::complex<double>"'s destructor 10 times.

If that is the case, can we have any way to know the size of the array
the shared_array pointing to?

Thanks,
Peng

Oct 18 '06 #1
1 9144
On 17 Oct 2006 17:28:40 -0700 in comp.lang.c++,
"Pe*******@gmail.com" <Pe*******@gmail.comwrote,
>If that is the case, can we have any way to know the size of the array
the shared_array pointing to?
In general, you cannot get that information. Not any more than you
can for a naked pointer to a new[]'ed array.

If you need the size remembered for you, use the more general and
standard mechanism of std::vector<>. If you need shared management,
a boost::shared_pointer to the vector will do that for you.

Oct 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Oliver Gebele | last post: by
8 posts views Thread by googlebart2000 | last post: by
32 posts views Thread by Mateo | last post: by
12 posts views Thread by Cleverbum | last post: by
24 posts views Thread by Chameleon | last post: by
10 posts views Thread by Sabiyur | last post: by
4 posts views Thread by Vijay Bajwa | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.