473,721 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the size of the array in boost::shared_a rray?

Hi,

I remember that the main difference between "int * a = new
std::complex<do uble>;" and "int *b = new std::complex<do uble>[10]" is
that the compiler keep the size of the array that "b" pointing to. So
"delete [] b" will call "std::complex<d ouble>"'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 10007
On 17 Oct 2006 17:28:40 -0700 in comp.lang.c++,
"Pe*******@gmai l.com" <Pe*******@gmai l.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_p ointer 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
3164
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 vector and when compiling on my Linux-box i get too many errors to include here.
9
2251
by: BekTek | last post by:
How do you think? and why?
8
2073
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 which library (name? location?) to use for the uBLAS portion. Can anyone point me to some simple examples somewhere? Advance thanks, -ted in AZ
32
2660
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 arrays!?!?! How can I determine size of dinamically alocated array.... ? Please advice... Thx!
12
1709
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 Segmentation Fault. I was wondering if there was any way I could get a slightly more verbose description of the error so that I could think about sorting it out. Someone mentioned to me that the g++ option -DRANGE_CHECKING would check if i was accessing...
8
6399
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. However I am unable to come up with a way to create and access an array for more than 1-dimension. Any one up for the challenge?
24
2372
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(); --------------------------------------------------------- ??? --------------------------------------------------------- MyClass::MyClass() {
10
1571
by: Sabiyur | last post by:
Hi All, I am coding as below. int *x = new int; int * y= x; ............ ............. del y; x=NULL;
4
7289
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, when, on destruction, auto_ptr tries to call delete on msg instead of delete ? Well, not bomb, by will probably only free up 1 char worth of memory? Is the way around it to make sure you get memory thus?
0
8840
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8730
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9064
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8007
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.