473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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 1319

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: M | last post by:
How do you permanently remove a user from the MySQL database. Delete from MySQL.user where user="Unwanted User"; just seems to ignored. Thanks, Martin
4
by: Bruce A. Julseth | last post by:
My MySQL.user table (user, host, password) looks like the following: +---------+-----------+---------------------+ | user | host | password |...
15
by: Roy Smith | last post by:
I understand that "delete xp" deletes a scalar object and "delete xp" deletes an array of objects, but what I don't understand is why you need to tell the compiler which you're doing. When you...
2
by: TOI DAY | last post by:
Hi all, How can I delete the file on the server after the user download it? For example: I have file name "123.txt" on a server, I copy it to "ABC.txt", then allow uer download the...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
27
by: Randy | last post by:
Is there a way to override operators for user-defined types (e.g., typedefs) rather than class types? I'm trying to override the extractor operator for a user-defined enumeration type but...
0
by: Darrel | last post by:
I've been having problems trying to delete a file. I can upload and save the file no problem, but deleting it gives me two results: If I run the delete function from my app's unprotected (public)...
7
by: python | last post by:
after del list , when I use it again, prompt 'not defined'.how could i delete its element,but not itself? except list.remove(val) ,are there other ways to delete list 's elements? and , I...
1
by: robinsand | last post by:
I am a new C++ programmer. I am still having trouble with certain data types and constructors, among other things. I'm not sure if I've used "std::string" properly throughout this program. I need...
6
by: JLupear | last post by:
I have written a code (a translation of my first one) that is not working. I did a user defined function that is used on 'onsubmit'. It should total the value from the form selections and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.