- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Use of nothrow in new() with aC++ compiler on HP-U...
Operating System - HP-UX
1753772
Members
5121
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
тАО11-13-2002 08:31 PM
тАО11-13-2002 08:31 PM
Use of nothrow in new() with aC++ compiler on HP-UX11 system
Dear friends,
I am using HP aC++ compiler(aCC) on HP-UX11 OS to compile C/C++ programs.
I want to know the usage of nothrow in the operator new() on C++ so as to avoid the new to throw an bad_alloc exception if new is unable to allocate the memory.
It would be better if the explanation would be assisted with a small example illustrating the concept.
Expecting Reply,
Thanks in Advance,
Yours,
Shashibhushan Gokhale
I am using HP aC++ compiler(aCC) on HP-UX11 OS to compile C/C++ programs.
I want to know the usage of nothrow in the operator new() on C++ so as to avoid the new to throw an bad_alloc exception if new is unable to allocate the memory.
It would be better if the explanation would be assisted with a small example illustrating the concept.
Expecting Reply,
Thanks in Advance,
Yours,
Shashibhushan Gokhale
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2002 04:18 AM
тАО11-18-2002 04:18 AM
Re: Use of nothrow in new() with aC++ compiler on HP-UX11 system
First the concept.
Good old malloc() used NULL for failure. But the programmers found it borring to check it every time the malloc() was called. So they invented mechanism to stop execution just in the place the error occured and decide what to do next. That's how the exceptions were born. But the exceptions are 'heavy'. It is extremally more work with handling exception than in returning NULL. It is not seen from the programmer's point of view, as it is duty for the compiler to add it.
That's why the programmers wanted to have a choice.
The first sollution was set_new_handler(new_handler new_p) function. Bad idea. Global function with global handling. And if there were, for example two libraries that wanted to install the handler, there would be one winner and one looser.
So now you have special version of operator new for not throwing the exceptions everytime you don't want them. You can mix calling the operators in the same code.
The usage is:
class C {
};
C *ptr1 = new C; // this throws exception by default, unless set_new_handler(new_handler new_p) installs something different
C *ptr2 = new(nothrow) C; // this never throws any exception, but remember to check for NULL!
And the last thing is: If the operator new returns, but the value is NULL, the compiler doesn't call the constructor for the class.
If you still have any doubt, feel free to ask.
Adam
Good old malloc() used NULL for failure. But the programmers found it borring to check it every time the malloc() was called. So they invented mechanism to stop execution just in the place the error occured and decide what to do next. That's how the exceptions were born. But the exceptions are 'heavy'. It is extremally more work with handling exception than in returning NULL. It is not seen from the programmer's point of view, as it is duty for the compiler to add it.
That's why the programmers wanted to have a choice.
The first sollution was set_new_handler(new_handler new_p) function. Bad idea. Global function with global handling. And if there were, for example two libraries that wanted to install the handler, there would be one winner and one looser.
So now you have special version of operator new for not throwing the exceptions everytime you don't want them. You can mix calling the operators in the same code.
The usage is:
class C {
};
C *ptr1 = new C; // this throws exception by default, unless set_new_handler(new_handler new_p) installs something different
C *ptr2 = new(nothrow) C; // this never throws any exception, but remember to check for NULL!
And the last thing is: If the operator new returns, but the value is NULL, the compiler doesn't call the constructor for the class.
If you still have any doubt, feel free to ask.
Adam
I do everything perfectly, except from my mistakes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2003 12:30 PM
тАО09-09-2003 12:30 PM
Re: Use of nothrow in new() with aC++ compiler on HP-UX11 system
Hi,
Dose the following neams that "nothrow" won't work, therefore a "bad_alloc" exception is thrown if "new" is unable to allocate the memory?
Thanks in advanced!
-Kevin
//test.cpp
#include
#include
using namespace std;
class myClass { };
int main()
{
myClass * x = new(nothrow) myClass;
return 0;
}
//test.cpp ends
$ aCC -AA test.cpp
Warning 930: "test.cpp", line 9 # Placement operator delete invocation is not yet implemented.
myClass * x = new(nothrow) myClass;
^^^^^^^^^^^^^^^^^^^^
Where,
$ uname -a
HP-UX lciahp8 B.11.23 U ia64 0582466038 unlimited-user license
$ aCC -V
aCC: HP aC++/ANSI C B3910B A.05.50 [May 15 2003]
Dose the following neams that "nothrow" won't work, therefore a "bad_alloc" exception is thrown if "new" is unable to allocate the memory?
Thanks in advanced!
-Kevin
//test.cpp
#include
#include
using namespace std;
class myClass { };
int main()
{
myClass * x = new(nothrow) myClass;
return 0;
}
//test.cpp ends
$ aCC -AA test.cpp
Warning 930: "test.cpp", line 9 # Placement operator delete invocation is not yet implemented.
myClass * x = new(nothrow) myClass;
^^^^^^^^^^^^^^^^^^^^
Where,
$ uname -a
HP-UX lciahp8 B.11.23 U ia64 0582466038 unlimited-user license
$ aCC -V
aCC: HP aC++/ANSI C B3910B A.05.50 [May 15 2003]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2003 09:27 AM
тАО09-12-2003 09:27 AM
Re: Use of nothrow in new() with aC++ compiler on HP-UX11 system
No.
I've just checked it on HP sites. This warning is quite new.
It means that if the _constructor_ of the class throws an exeption, the required cleanup is not added correctly by the compiler.
However the operator new itself should work as expected.
See:
http://h21007.www2.hp.com/dspp/ml/showArchiveMessage/1,,24!02!11!0118,00.html
Good luck
Adam
I've just checked it on HP sites. This warning is quite new.
It means that if the _constructor_ of the class throws an exeption, the required cleanup is not added correctly by the compiler.
However the operator new itself should work as expected.
See:
http://h21007.www2.hp.com/dspp/ml/showArchiveMessage/1,,24!02!11!0118,00.html
Good luck
Adam
I do everything perfectly, except from my mistakes
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP