473,763 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

storing pointer vs storing object

Hi,
all of the containers in STL stores object itself (thus copy
contsructabilit y & assignability is needed), while NTL or boost
ptr_container stores pointer to the object in the container (either
exclusively owns, or just stores).
Now, my question is for a general guideline when to use which one?
What I understand,
1) polymorphic objects need ptr_container.
2) non copy constructable, non assignable objects need ptr_container.

Other than that, any guideline is there? I am specially interested for
small devices (handheld, pda etc) with limited memory, where gaining
performance is important.
To be specific, can it be a guideline like, lots of small objects =>
STL container (faster due to cache effect)., a few large objects (like
GUI widgets) , use ptr_container. So, why there should be two different
types of container, and when one or the other would be used?

thanks
abir

Oct 11 '06
11 2369

toton wrote:
Hi,
all of the containers in STL stores object itself (thus copy
contsructabilit y & assignability is needed), while NTL or boost
ptr_container stores pointer to the object in the container (either
exclusively owns, or just stores).
Now, my question is for a general guideline when to use which one?
What I understand,
1) polymorphic objects need ptr_container.
2) non copy constructable, non assignable objects need ptr_container.

Other than that, any guideline is there? I am specially interested for
small devices (handheld, pda etc) with limited memory, where gaining
performance is important.
To be specific, can it be a guideline like, lots of small objects =>
STL container (faster due to cache effect)., a few large objects (like
GUI widgets) , use ptr_container. So, why there should be two different
types of container, and when one or the other would be used?
I recommend an alternative to the boost ptr_container, which is the
following smart_ptr:
http://axter.com/smartptr/
You can use the above smart pointer with the STL containers, and it can
be more efficient then the boost::ptr_cont ainer. It's also more
compatible to the STL containers.

Oct 13 '06 #11

KiLVaiDeN wrote:
Gavin Deane wrote:

Unless and until proven otherwise, both those concerns are secondary
to:

"Which option produces the most clearly human-readable code" and
"Which option enables you to get to the point where that code is
written, teted and error-free more quickly"

So, to the OP: consider the options in that context and choose
whichever answers those questions best. If you find, for example, that
it takes longer (including testing and debugging time) to write correct
code using containers of pointers, and that code is less clear to a
human reader, then use containers of objects.

Premature optimisation is the root of all evil and all that.
I am well aware of that. Both STL & pointer container generates human
readable code. If one wants to throw pointer_contain er from readibility
point of view , I can say it is matter of taste. I want from efficiency
point of view. I am not using unreadable C++ or C code. I am using some
very well known and well proven library like STL, Boost and Blitz.
Gavin Deane

I totally agree with your point, in a normal environnement, but he's
working for small devices, therefore it's not only a matter of
Optimization, but more a matter of good practices for those targeted
platforms.
I don't do optimization, not perform any treak to optimize a code,
other than writing some template specialization. Only I want to assist
compiler to optimize my code. And to the requirement of the program,
and target platform this assistance change (It is much profile guided
optimization). I am using GCC, and target is a StrongARM processor
(Intel XScale). memory is as little as 50-200K.
May be C is a better choice, but from design point I needed to use
standard C++ (as it is going to be a scale down version of C++ program
written for PC ) , and in my experience, C++ is doing better job of
parallization of code or copying memory at a chunk.
The main difference is, for this small processors, one have to be
extremely carefull about memory allocation (or in that matter any
memory related operations). It is better to keep them at the bottom
level. while simple instructions are reasonably faster.And caching
effect is very dominant in those processors. Thus the thumb rule most
of the time becomes, pre-allocate some memory and use them, rather than
create memory and delete memory. We use a specially designed container
(circular_buffe r ) for most purpose which is a deque but have reserve
facility like vector, little more flexible than boost::circular _buffer.
So mainly placement new comes a better choce (allocator class).
However GCC really helps me for all of these optimizations.
I am looking at https://sourceforge.net/projects/smart-pointer , and
how they make a faster than boost ptr_container. It looks good.
The considerations you make are very valuable though; The best is to
test both of the scenarios, see how it's managed in your targeted
device, and then sticking to one or another; Tell me if you agree :)
Thanks to all for these valuable discussions.
Cheers,
K
Oct 13 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1664
by: William Djaja Tjokroaminata | last post by:
Hi, As I am interfacing my code in C++ with a scripting language which is written in C, I need to store pointers to objects in a class hierarchy: ParentClass *obj1; obj1 = new ParentClass (...); ... do things with obj1... STORE_POINTER (scriptObj1, obj1);
2
3108
by: Chester | last post by:
Is it possible to new an object A, downcast it to B, and store B in a vector? I'm having problem with the following code: B is a derived class of A Blist.push_back( new B() ); Blist.push_back( new B() ); A *a = new A(); B *b = static_cast<B*>(a);
10
2027
by: Whitney Kew | last post by:
Hello, I have a question regarding type conversion operators. Let's say I have a simple (nonsensical) class as follows: class MakeNewInt { private: int* _n;
6
2577
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a "SEGV" when run (presumably - attempt to delete deleted memory. Please take a look and see if you can notice any mistakes I'm making. Basically, I want to store classes of my objects in a vector. I also have three further questions:
12
3950
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
4
1965
by: gsyoon | last post by:
hi, all. I'm trying to make a "framework" to store the return value of a function to a global memory. My first attempt was 1) void store_to_global( char * type_name ) { if ( strcmp( type_name, "CLASS_A") )
5
1840
by: Joe | last post by:
Coming from C++ I'm so used to being able to use pointers in Tag properties that I'm a little lost. I want to assign an instance of a class to a Tag property and be able to change one of it's members. I need this change to take effect in the original class instance (as it would with a pointer). How can this be done? Thanks
3
4699
by: marco_segurini | last post by:
Hi, the 'user' class describes what is my target: I want to save a reference to a class instance and a reference to the reference to the class instance calling a 'user' member function and later use them in another member function to restore the original value. Is there any C# programming technique that may help me?
10
2717
by: Jess | last post by:
Hello, I have a program that stores dynamically created objects into a vector. #include<iostream> #include<vector> using namespace std;
0
9566
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
10003
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
9943
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
8825
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...
1
7370
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2797
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.