473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 9962
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Oliver Gebele | last post by:
/* OK, after years i'm still more into C; but i already do understand some C++. And there are still many things about the STL which i do not know... I try to put 8-character-arrays in a...
9
by: BekTek | last post by:
How do you think? and why?
8
by: googlebart2000 | last post by:
I'm about to be a new user of the Boost C++ library, and I've installed and compiled it, but I've come up empty on how to use it in my C++ programs. I can't find the documentation that explains...
32
by: Mateo | last post by:
I have char *array and it is dinamically alocated.... When I pass it to other function, I need to determine size of this array.... Problem: sizeof operator does not work with dinamically alocated...
12
by: Cleverbum | last post by:
Hi, I'm a complete beginner, having written my second program and finally got it to compile, I've got an error I can't track down occurring at runtime - basically whatever I do it says...
8
by: Skay | last post by:
Someone challenged me to create a dynamic multidimensional array using auto_ptr http://www.gotw.ca/gotw/042.htm Provides a good way to create a single dimensional array using an adapter. ...
24
by: Chameleon | last post by:
Is there a possibility to create memory leak, the code below if I run the line: --------------------------------------------------------- MyClass cl = new MyClass();...
10
by: Sabiyur | last post by:
Hi All, I am coding as below. int *x = new int; int * y= x; ............ ............. del y; x=NULL;
4
by: Vijay Bajwa | last post by:
Say I have a const char* msg which is pointing to memory gotten by something like (msg = new char ). Then if I declare thus: auto_ptr<const charsmartptr (msg) ; Then will this bomb royally,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.