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

P

PengYu.UT

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
 
D

David Harmon

On 17 Oct 2006 17:28:40 -0700 in comp.lang.c++,
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top