469,343 Members | 5,377 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

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[]?

Dec 25 '06 #1
2 1166

"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

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.

Similar topics

2 posts views Thread by M | last post: by
4 posts views Thread by Bruce A. Julseth | last post: by
15 posts views Thread by Roy Smith | last post: by
2 posts views Thread by TOI DAY | last post: by
reply views Thread by Darrel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.