operator new/delete for beginners
-
Dear gurus, I have the following question. I heard/read somewhere that it does not make sense to check for a zero-pointer if operator new is used, as
int *p = 0;
p = new int [5];
if ( 0==p ) { ..some action here.. }It also is allowed to use operator delete even on zero-pointers. ...and more such issues..... Can somebody give me a short link to a good document on such topics? Thank you very much
-
Dear gurus, I have the following question. I heard/read somewhere that it does not make sense to check for a zero-pointer if operator new is used, as
int *p = 0;
p = new int [5];
if ( 0==p ) { ..some action here.. }It also is allowed to use operator delete even on zero-pointers. ...and more such issues..... Can somebody give me a short link to a good document on such topics? Thank you very much
See here [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
See here [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Another question: If I want to use the no-throw-Version: T *pt = new (std :: nothrow) T(); What happens if allocation fails? Can I test 'pt' for 0 then? Or does pt have any undefined value?
-
Another question: If I want to use the no-throw-Version: T *pt = new (std :: nothrow) T(); What happens if allocation fails? Can I test 'pt' for 0 then? Or does pt have any undefined value?
Well, I think you may test in both cases. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Another question: If I want to use the no-throw-Version: T *pt = new (std :: nothrow) T(); What happens if allocation fails? Can I test 'pt' for 0 then? Or does pt have any undefined value?
-
Dear gurus, I have the following question. I heard/read somewhere that it does not make sense to check for a zero-pointer if operator new is used, as
int *p = 0;
p = new int [5];
if ( 0==p ) { ..some action here.. }It also is allowed to use operator delete even on zero-pointers. ...and more such issues..... Can somebody give me a short link to a good document on such topics? Thank you very much
Tomerland wrote:
I heard/read somewhere that it does not make sense to check for a zero-pointer if operator new is used...
What if
new
fails?"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Tomerland wrote:
I heard/read somewhere that it does not make sense to check for a zero-pointer if operator new is used...
What if
new
fails?"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Which is not thrown on all compilers.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Which is not thrown on all compilers.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne