- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: C++ question - copy contructor call (aCC/HP)
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 02:27 AM
10-08-2002 02:27 AM
OurClass::instance()->handleException(OurException(params));
Our exception object is created to be passed to the handleException
function. On Windows, Solaris & AIX this creates an exception object and
passes that object to the handleException function.
On HP (using aCC) the object is created, then a copy of that object is
passed to handleException.
This doesn't seem entirely unreasonable, if a little pointless. Is this just
the way they have chosen to implement the spec, or is it wrong? Is it just a
case of poor optimisation?
Is there any way to optimise this out? Or any way around it?
Thanks,
Richard.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 05:53 AM
10-09-2002 05:53 AM
SolutionSo if your handleException() function is declared something like this:
void handleException(OurException e)
change it to this:
void handleException(OurException &e)
and recompile the program. The call to this function will no longer result in a copy of the parameter being made; instead it will be passed by reference, meaning that the parameter is an implicit pointer.
Of course, there may be side effects to this depending on the rest of the program code, but in general it's probably OK as long as you can assure the called function "handleException" can safely act on the actual object passed in rather than a copy of it.
Good luck -
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 06:00 AM
10-09-2002 06:00 AM
Re: C++ question - copy contructor call (aCC/HP)
I just thought of some possible reasons why you might observe this behavior only on HP-UX while it is probably occurring on the other platforms anyway:
- If you're running this under a debugger, it may not show you that the copy constructor is called if it is inlined or if it is optimized code on those platforms.
Well, OK, just one reason, but something like this may be going on depending on what you're doing to make you say that it only seems to be happening on HP-UX. Like I said, based on your description, it sounds like the exection on HP-UX is running properly.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 07:10 AM
10-09-2002 07:10 AM
Re: C++ question - copy contructor call (aCC/HP)
Your suggestion of passing by reference is a good one, but as you suggest there is a down side to the idea.
This code is in a piece of middleware and the handleException function is written by our users in an instance of one of our classes. It isn't possible to just change this kind of information as it is already in use by our customers.
This product is availible on 6 platforms, and HP is probably the least used of them, which is probably why it has taken so long for this to appear.
When it has been tested on these other platforms it has been done under the same conditions, and I put extra trace points into the code to in order to diagnose this, so I didn't need to use a debugger. I was able to see that on HP we went into the copy constructor, but not on any of the other platforms.
The source file I had to modify is platform independant, so the exact same file was compiled on the different platforms to test what was happening.
I agree this probably isn't a bug with the compiler, it doesn't seem unreasonable what it is doing. I suspect that this call to the copy constructor is being optimized out on the other platforms. As we are creating this Exception object in the call to the function, there really isn't a lot of point copying it.
Is there any way to force this to be optimized out?
Thanks,
Richard.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 03:59 AM
10-10-2002 03:59 AM
Re: C++ question - copy contructor call (aCC/HP)
If you can't modify this source code, I'm not sure what you can do to eliminate the call to the copy constructor. But a more fundamental question: why do you really want to get rid of this call to the copy constructor upon calling "handleException"? Is this called so often or taking so long to execute that it is really slowing the program down? Have you seen this as a result of profiling the program at runtime?
- Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 06:49 AM
10-23-2002 06:49 AM
Re: C++ question - copy contructor call (aCC/HP)
Sorry about the delay in my reply, the forum mailer didn't let me know I had another.
The reason we want to get rid of the call to the copy constructor is that the copy constructor doesn't do a complete copy. The Exception object contains a void* and we didn't want to just copy this pointer, as that would be mixing a deep and shallow copy. We can't copy the object that the pointer points to, because we don't know what it is.
Ideally we are looking for a way to fix this without having to rewrite too much.
Suggestions have included some way to track what the object is, so we know its size and can copy it or keeping track of the number of pointers to the object, to ensure the object isn't freed until all pointers are out of use.
None of these solutions have been very practical in our circumstances, and would require more redesign than we would like. Especially considering this is just to make it work on HP.
Richard.