Hi,
reading the output of gprof for one of my projects, I found that the
STL list assignment operator consumes a larger fraction of the
program's execution time. The exact entry in gprof's output looks
as follows:
std::list<MyCla ss*, std::allocator< MyClass*::opera tor=
(std::list<MyCl ass*, std::allocator< MyClass* const&) >
Since I don't know the source code for STL lists, I assume that
calling the assignment operator means that for each element
of the STL list the element's assignment operator is called. If
this is right, I don't understand why this works at all since I
explicitly disallow copying of MyClass objects by defining its
assignment operator private:
class MyClass:
private:
MyClass& operator=( const& MyClass );
So, the compiler does not create an default assignment operator
automatically. Thus, IMHO, STL list's operator= should fail.
Any ideas why this still works?
Regards,
Chris 3 2710
Christian Christmann wrote:
Hi,
reading the output of gprof for one of my projects, I found that the
STL list assignment operator consumes a larger fraction of the
program's execution time. The exact entry in gprof's output looks
as follows:
std::list<MyCla ss*, std::allocator< MyClass*::opera tor=
(std::list<MyCl ass*, std::allocator< MyClass* const&) >
Since I don't know the source code for STL lists, I assume that
calling the assignment operator means that for each element
of the STL list the element's assignment operator is called. If
this is right, I don't understand why this works at all since I
explicitly disallow copying of MyClass objects by defining its
assignment operator private:
class MyClass:
private:
MyClass& operator=( const& MyClass );
So, the compiler does not create an default assignment operator
automatically. Thus, IMHO, STL list's operator= should fail.
Any ideas why this still works?
Your list seems to hold MyClass _pointers_ so only the pointers are
assigned not the objects themselves.
On Sun, 06 Aug 2006 19:10:37 +0200, Christian Christmann
<pl*****@yahoo. dewrote:
>reading the output of gprof for one of my projects, I found that the STL list assignment operator consumes a larger fraction of the program's execution time. The exact entry in gprof's output looks as follows:
std::list<MyCl ass*, std::allocator< MyClass*::opera tor= (std::list<MyC lass*, std::allocator< MyClass* const&) >
Since I don't know the source code for STL lists, I assume that calling the assignment operator means that for each element of the STL list the element's assignment operator is called.
... and the assignment operator also allocates a new node for each
element in the list (which probably is the performance problem). Try
vector instead (using reserve()).
>If this is right, I don't understand why this works at all since I explicitly disallow copying of MyClass objects by defining its assignment operator private:
class MyClass:
private:
MyClass& operator=( const& MyClass );
So, the compiler does not create an default assignment operator automaticall y. Thus, IMHO, STL list's operator= should fail.
Any ideas why this still works?
Your list contains pointers. MyClass objects are not copied, only
pointers to MyClass objects. After assignment the pointers in both
lists point to the same objects. This may or may not be what you want.
Note that STL containers use value semantics. They are made to work
with values, not with pointers to objects.
Best regards,
Roland Pibinger
In article <44************ ***********@new sread2.arcor-online.net>, pl*****@yahoo.d e says...
Hi,
reading the output of gprof for one of my projects, I found that the
STL list assignment operator consumes a larger fraction of the
program's execution time. The exact entry in gprof's output looks
as follows:
std::list<MyCla ss*, std::allocator< MyClass*::opera tor=
(std::list<MyCl ass*, std::allocator< MyClass* const&) >
Since I don't know the source code for STL lists, I assume that
calling the assignment operator means that for each element
of the STL list the element's assignment operator is called. If
this is right, I don't understand why this works at all since I
explicitly disallow copying of MyClass objects by defining its
assignment operator private:
One possibility would be that it's using a copy constructor to copy the
nodes.
--
Later,
Jerry.
The universe is a figment of its own imagination. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: CoolPint |
last post by:
It seems to me that I cannot assign objects of a class which has a constant data
member since the data member cannot be changed once the constructor calls are
completed. Is this the way it is meant to be? Am I not suppose not to have any
constant data member if I am going to have the assignment operator working for
the class?
Or am I...
|
by: Edward Diener |
last post by:
Is there a way to override the default processing of the assignment operator
for one's own __value types ? I realize I can program my own Assign method,
and provide that for end-users of my class, but I would like to use
internally my own = operator for some of my value types, so I can say "x =
y;" rather than "x.Assign(y);".
The op_Assign...
|
by: fudmore |
last post by:
Hello Everybody.
I have a Segmentation fault problem. The code section at the bottom
keeps throwing a Segmentation fault when it enters the IF block for the
second time.
const int WORDS_PER_LINE = 4;
when counter == 7 is when the string Concatenation fails within the IF
block.
|
by: Darryl B |
last post by:
I can not get anywhere on this project I'm tryin to do. I'm not
expecting any major help with this but any would be appreciated. The
assignment is attached. The problem I'm having is trying to set up the
class link and tel_list. I set up a class person with strings for
name, town, and number. I just don't know how to set up the classes w/...
|
by: Barry Hynes |
last post by:
G'Day folks,
Have been working on this problem for quite some time and still no farther
ahead. :(
Here is my problem...bare with me i am very green :)
I have to implement a Safe List, that is derived from the STL class List and
uses exception handling.
| |
by: raylopez99 |
last post by:
I need an example of a managed overloaded assignment operator for a
reference class, so I can equate two classes A1 and A2, say called
ARefClass, in this manner: A1=A2;. For some strange reason my C++.NET
2.0 textbook does not have one. I tried to build one using the format
as taught in my regular C++ book, but I keep getting compiler...
|
by: APEJMAN |
last post by:
I know what I'm posting here is wired, but it's been 3 days I'm workin g on these codes, but I have no result
I post the code here
I dont wanne bother you, but if any one of you have time to read my program I appriciate it.
the program suppose to print a message on the screen
#include <iostream>
#include <string>
|
by: jerry.teshirogi |
last post by:
I have the following class and main:
//////////////////////////////////////////////////////////
#include <iostream.h>
class myVector
{
public:
double x, y, z:
|
by: Taras_96 |
last post by:
Hi everyone,
The FAQ at http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6
states that:
"Consider the following constructor that initializes member object x_
using an initialization list: Fred::Fred() : x_(whatever) { }. The
most common benefit of doing this is improved performance. For
example, if the expression whatever is the...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |