 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Money Guest
|
Posted: Mon Dec 25, 2006 9:05 am Post subject: Need for user defined delete or built-in will work? |
|
|
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
|
Posted: Mon Dec 25, 2006 9:23 am Post subject: Re: Need for user defined delete or built-in will work? |
|
|
"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 |
|
 |
|
|
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
|
|