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

Is there any way to disable global operator new?

We need to be able to disable global operator new at compile time. We
are developing a large library and need to control all memory
allocation and cannot have a mistake whereby a mistaken use of global
operator new creeps in. It is not feasible to solve this via
implementing our own global operator new which asserts(false), as
there is no practical way to test all paths of execution. This is a
large and complex library, to say the least. In fact there's a chance
you are using it to read this message. :)

Due to the design of C++ and its special/unusual treatment of new/
delete, I can think of no way to accomplish this, nor can I think of
an alternative means to accomplish what we need. #defining new away
doesn't work because placement new and class new still need to work.
Nov 16 '08 #1
1 3608
go****@pedriana.com wrote:
We need to be able to disable global operator new at compile time. We
are developing a large library and need to control all memory
allocation and cannot have a mistake whereby a mistaken use of global
operator new creeps in. It is not feasible to solve this via
implementing our own global operator new which asserts(false), as
Patch a you standard library for testing purposes and remove the global
operator new. You will get a linkage error in case you are calling new
from some point.
But I think that the standard library itself requires this operator. So
you might get some additional errors from there.
there is no practical way to test all paths of execution. This is a
large and complex library, to say the least. In fact there's a chance
you are using it to read this message. :)
While this is not uncommon, you may run into other troubles anyway.

Due to the design of C++ and its special/unusual treatment of new/
delete, I can think of no way to accomplish this, nor can I think of
an alternative means to accomplish what we need. #defining new away
doesn't work because placement new and class new still need to work.
I wonder why it is not possible to replace the global operators in a way
that they have a meaningful implementation of your memory management.

Otherwise you might derive all your base classes from a helper class
that overloads new and delete. Of course, this will not work for PODs.
Nov 16 '08 #2

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

Similar topics

1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
7
by: Emanuel Ziegler | last post by:
Hello, I want to do some mathematics with functions. In my case the function classes are very complex, but this simple example has the same problems. To allow calculations that begin with a...
44
by: Mohanasundaram | last post by:
int i = 10; int main() { int i = 20; return 0; } Hi All, I want to access the global variable i inside the main. Is there
9
by: Javaman59 | last post by:
I saw in a recent post the :: operator used to reach the global namespace, as in global::MyNamespace I hadn't seen this before, so looked it up in MSDN, which explained it nicely. My question...
16
by: Roman Ziak | last post by:
Hello, there were times when I used to be looking for a way to access JavaScript Global object similar to those found in VBScript or PHP ($GLOBALS). At present this has only academic value for...
2
by: ryan_melville | last post by:
Hi, Should I put the operator<<() for my class (which is in a namespace) in the namespace or make it global? If I understand the lookup rules correctly: If I make it global, it may be hidden...
7
by: Eric Lilja | last post by:
>From a book, I know the following is true for the comparison operators: An overloaded operator that is a class member is only considered when the operator is used with a *left* operand that is an...
3
by: mrstephengross | last post by:
Hi folks. I've got a weird situation--gcc doesn't like the folllowing code snippet, but I don't know if it's correct or not. Here's the situation: In the global namespace, I've got a operator<<...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.