By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,129 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,129 IT Pros & Developers. It's quick & easy.

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

P: n/a
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[]?

Dec 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Money" <sp*********@gmail.comwrote in message
news:11*********************@i12g2000cwa.googlegro ups.com...
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.
>
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.
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
Dec 25 '06 #2

P: n/a

Money wrote:
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[]?
it might work for intrinsic types or simple types with no
destructor.but for other types it certainly will not.I am using ms
vc++.net 7 and this dosent work fine on it.because for destructable
arrays the compiler generates extra storage for number of elements to
be destructed.

Dec 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.