473,395 Members | 1,462 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,395 software developers and data experts.

How to overwrite 'new' operation in c++

Hi all,

I heard new/delete operations could be overwritten with customed functions.

Just wonderring how this could be achieved. Could any one post some
suggestions please

Thanks:)

Joe
Sep 23 '07 #1
3 5539
Xianzheng Zhou wrote:
Hi all,

I heard new/delete operations could be overwritten with customed functions.
You don't "ovwerwite" in C++, you "override".
>
Just wonderring how this could be achieved. Could any one post some
suggestions please
The FAQ has some ideas:
http://www.parashift.com/c++-faq-lit....html#faq-16.7
http://www.parashift.com/c++-faq-lit...html#faq-11.14
Sep 23 '07 #2
Xianzheng Zhou wrote:
Hi all,

I heard new/delete operations could be overwritten with customed functions.

Just wonderring how this could be achieved. Could any one post some
suggestions please
Most of the cases, you *overload* /operator new/ to manage memory
yourself, as the heap offered by CRT is created to meet common needs,
not for small object allocation, etc.
And on some embedded platform, they even don't provide dynamic memory
allocation, you can only acquire a large trunk, then manage it yourself.
And you can even overload operator new for memory leak detection.
And as a rule of thumb, overload operator new and operator delete in
pair.

And some overloaded operator new is invented to meet special need, a
famous one is ELeave operator new on Symbian.

How to overload operator new? Find it in a textbook.
--
Thanks
Barry
Sep 23 '07 #3
On Sep 23, 12:48 pm, Xianzheng Zhou <j...@lgsolutions.com.auwrote:
I heard new/delete operations could be overwritten with
customed functions.
I presume you mean "overridden", not "overwritten".
Just wonderring how this could be achieved.
In a very real way, it depends on the implementation, but for
all of the implementations I know, if you define an operator new
and an operator delete function, and arrange for them to be
linked in before the standard library is linked in, then your
versions will be used instead of the standard ones.

Note that you should never do this except at the final
application level (e.g. to use a debugging new/delete, instead
of the standard one).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gord | last post by:
Hello, If you set the flag for an overwrite prompt using the 'Save' common dialog, how do you read the response when the user clicks the Yes or No in the 'overwrite' message box? Everything...
8
by: Sonoman | last post by:
Hi all: I have to functions. Function A that returns a parameter and function B that takes a parameter, both are the same type. Can I put a call to function A as a parameter for function B? or is...
2
by: B-Dog | last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is what I'm trying to do: If System.IO.File.Exists(dest) Then 'handle overwrite here If MessageBox.Show("Do you want...
3
by: Gene Vangampelaere | last post by:
Hi, I need to write a function that can replace some (.dll) files. That's easy to do but what if there are some files in use ? How can I replace those files ? is there a method to 'force' an...
4
by: wwwmike | last post by:
How can I overwrite the <FORM action=attribute? I can add new attributes with Dim xx As System.Web.UI.HtmlControls.HtmlForm xx = Page.FindControl("form1") xx.Attributes.Add("something",...
2
by: spowel4 | last post by:
I'm new to Visual Basic, so I apologize for basic questions. Here's the code I've got so far, which works as long as the destination file doesn't already exist: If...
5
by: Ben Sizer | last post by:
I need to copy directories from one place to another, but it needs to overwrite individual files and directories rather than just exiting if a destination file already exists. Previous suggestions...
2
by: hzgt9b | last post by:
I know how to overwrite a function. Normally this is what I would do: function someFunction() { /* orig definition here */ } //later in the execution stream I would do... someFunction = function...
8
by: Joe Duchtel | last post by:
Hello - I have the following code to detemine a file name when my application is saving a file. The problem is that if the file already exists and I select the Yes button in the "Do you want to...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.