C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need for user defined delete or built-in will work?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Money
Guest





PostPosted: Mon Dec 25, 2006 9:05 am    Post subject: Need for user defined delete or built-in will work? Reply with quote



When we do this

Test *ptr=new Test[10];

then runtime memory manager will allocate 10*sizeof(Test) + X bytes(X
varying from implementation to implementation)

But instead if I call operator new explicitly like

Test *ptr = static_cast<Test *>(operator new[]( 10*sizeof(Test) ));

Now there's no extra X bytes allocated by me. So, will the built-in
delete[] will work properly? or do I need to supply my own operator
delete[]?
Back to top
Mike Wahler
Guest





PostPosted: Mon Dec 25, 2006 9:23 am    Post subject: Re: Need for user defined delete or built-in will work? Reply with quote



"Money" <spicymonchi (AT) gmail (DOT) com> wrote in message
news:1167015924.241462.69590 (AT) i12g2000cwa (DOT) googlegroups.com...
Quote:
When we do this

Test *ptr=new Test[10];

then runtime memory manager will allocate 10*sizeof(Test) + X bytes(X
varying from implementation to implementation)

There's no guarantee that the new[] operator or 'operator new[]()'
will allocate more than the size requested. Only that *at least*
the requested size will be allocated.

Quote:

But instead if I call operator new explicitly like

Test *ptr = static_cast<Test *>(operator new[]( 10*sizeof(Test) ));

Now there's no extra X bytes allocated by me.

See above.

Quote:
So, will the built-in
delete[] will work properly? or do I need to supply my own operator
delete[]?

Normally the new[] operator will suffice.

What specifically are you trying to do?

-Mike
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.