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

isolating operator new overload with gcc 4 (XCode2.2)

Hello,

I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be overloaded, but I need to
link with the system libraries (frameworks) and I DO NOT want my
overloads to be mapped to them. I'm working with some code that is
currently working on Win32 but also needs to work on the Mac. Under
windows this is very simple because none of the essential Win32
libraries use or require C++ (or at least in no way that gets exposed
to normal application code), and overloading operator new has no effect
on their memory allocations. I need similar functionality on the Mac
using XCode2.2 (which I think is using gcc 4). This first pass is just
being built for intel (mainly so I don't have to deal with endian
issues right now). Maybe some odd combination of dynamic and static
libraries linked in the right order might do it??

Sep 27 '06 #1
5 3454

richard.par...@adventure.com wrote:
Hello,

I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be overloaded, but I need to
link with the system libraries (frameworks) and I DO NOT want my
overloads to be mapped to them. I'm working with some code that is
currently working on Win32 but also needs to work on the Mac. Under
windows this is very simple because none of the essential Win32
libraries use or require C++ (or at least in no way that gets exposed
to normal application code), and overloading operator new has no effect
on their memory allocations. I need similar functionality on the Mac
using XCode2.2 (which I think is using gcc 4). This first pass is just
being built for intel (mainly so I don't have to deal with endian
issues right now). Maybe some odd combination of dynamic and static
libraries linked in the right order might do it??
Just a correction for the top... I need to overload new WITHOUT
affecting the system libraries (frameworks).

Sep 27 '06 #2
<ri************@adventure.comwrote in message news:11*********************@m73g2000cwd.googlegro ups.com...

richard.par...@adventure.com wrote:
>Hello,

I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be overloaded, but I need to
link with the system libraries (frameworks) and I DO NOT want my
overloads to be mapped to them. I'm working with some code that is
currently working on Win32 but also needs to work on the Mac. Under
windows this is very simple because none of the essential Win32
libraries use or require C++ (or at least in no way that gets exposed
to normal application code), and overloading operator new has no effect
on their memory allocations. I need similar functionality on the Mac
using XCode2.2 (which I think is using gcc 4). This first pass is just
being built for intel (mainly so I don't have to deal with endian
issues right now). Maybe some odd combination of dynamic and static
libraries linked in the right order might do it??
Just a correction for the top... I need to overload new WITHOUT
affecting the system libraries (frameworks).

This is not really a C++ question, more an system specific C++ implementation question.
However, I tried to do something like you asked, but with limited success.

It is not clear what you want. Do you want the C++ Standard Library to use your overloaded new,
or do you want them to use the original new?

If you want to use your overloaded new everywhere, then use static libraries only, because
operator new is used in many places in the standard library.
If you want to use your overloaded new for your own code and the original new for the STL,
then your are moving on dangerous grounds. There is not a clear separation of the two,
because a large part of the STL consists of templates. Do the specific instantiations of those
templates belong to the STL, or to your own code? Some of those instantiations are used also
in the STL and, therefore, will be in the dynamic C++ library, others are only in your own code
and will not be in a dynamic library. You have no control over which instantiations are in
the dynamic library and which are not. So, you have no control over when your instantiations
use your overloaded new and when they use the original new.

If you still insist on doing so, try to link the object code of your program with the object code of the
overloaded operator new and then add the normal libraries to the linker command.

Fred.Zwarts.
Sep 27 '06 #3

Fred Zwarts wrote:
<ri************@adventure.comwrote in message news:11*********************@m73g2000cwd.googlegro ups.com...

richard.par...@adventure.com wrote:
Hello,

I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be overloaded, but I need to
link with the system libraries (frameworks) and I DO NOT want my
overloads to be mapped to them. I'm working with some code that is
currently working on Win32 but also needs to work on the Mac. Under
windows this is very simple because none of the essential Win32
libraries use or require C++ (or at least in no way that gets exposed
to normal application code), and overloading operator new has no effect
on their memory allocations. I need similar functionality on the Mac
using XCode2.2 (which I think is using gcc 4). This first pass is just
being built for intel (mainly so I don't have to deal with endian
issues right now). Maybe some odd combination of dynamic and static
libraries linked in the right order might do it??
Just a correction for the top... I need to overload new WITHOUT
affecting the system libraries (frameworks).


This is not really a C++ question, more an system specific C++ implementation question.
However, I tried to do something like you asked, but with limited success.

It is not clear what you want. Do you want the C++ Standard Library to use your overloaded new,
or do you want them to use the original new?

If you want to use your overloaded new everywhere, then use static libraries only, because
operator new is used in many places in the standard library.
If you want to use your overloaded new for your own code and the original new for the STL,
then your are moving on dangerous grounds. There is not a clear separation of the two,
because a large part of the STL consists of templates. Do the specific instantiations of those
templates belong to the STL, or to your own code? Some of those instantiations are used also
in the STL and, therefore, will be in the dynamic C++ library, others are only in your own code
and will not be in a dynamic library. You have no control over which instantiations are in
the dynamic library and which are not. So, you have no control over when your instantiations
use your overloaded new and when they use the original new.

If you still insist on doing so, try to link the object code of your program with the object code of the
overloaded operator new and then add the normal libraries to the linker command.

Fred.Zwarts.
Sorry about the ambiguity, my goal is to overload new/delete for all of
my code and the STL that my code is using. Basically everything except
the system libraries (frameworks in XCode, which I believe are just
dynamic libraries, linked with a dynamic c runtime). Is it possible,
with gcc 4, to isolate operator new/delete overloads to a libarary?
Can it be static or does it have to be dynamic? If so I could put all
my code in one (library). But I don't want the system frameworks
(other dynamic libaries) to get a hold of my overloads when I link the
application and I don't want my code to use the non-overloaded
new/delete.

Sep 27 '06 #4
<ri************@adventure.comwrote in message news:11**********************@m7g2000cwm.googlegro ups.com...

Fred Zwarts wrote:
><ri************@adventure.comwrote in message news:11*********************@m73g2000cwd.googlegro ups.com...
>
richard.par...@adventure.com wrote:
Hello,

I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be overloaded, but I need to
link with the system libraries (frameworks) and I DO NOT want my
overloads to be mapped to them. I'm working with some code that is
currently working on Win32 but also needs to work on the Mac. Under
windows this is very simple because none of the essential Win32
libraries use or require C++ (or at least in no way that gets exposed
to normal application code), and overloading operator new has no effect
on their memory allocations. I need similar functionality on the Mac
using XCode2.2 (which I think is using gcc 4). This first pass is just
being built for intel (mainly so I don't have to deal with endian
issues right now). Maybe some odd combination of dynamic and static
libraries linked in the right order might do it??

Just a correction for the top... I need to overload new WITHOUT
affecting the system libraries (frameworks).


This is not really a C++ question, more an system specific C++ implementation question.
However, I tried to do something like you asked, but with limited success.

It is not clear what you want. Do you want the C++ Standard Library to use your overloaded new,
or do you want them to use the original new?

If you want to use your overloaded new everywhere, then use static libraries only, because
operator new is used in many places in the standard library.
If you want to use your overloaded new for your own code and the original new for the STL,
then your are moving on dangerous grounds. There is not a clear separation of the two,
because a large part of the STL consists of templates. Do the specific instantiations of those
templates belong to the STL, or to your own code? Some of those instantiations are used also
in the STL and, therefore, will be in the dynamic C++ library, others are only in your own code
and will not be in a dynamic library. You have no control over which instantiations are in
the dynamic library and which are not. So, you have no control over when your instantiations
use your overloaded new and when they use the original new.

If you still insist on doing so, try to link the object code of your program with the object code of the
overloaded operator new and then add the normal libraries to the linker command.

Fred.Zwarts.
Sorry about the ambiguity, my goal is to overload new/delete for all of
my code and the STL that my code is using. Basically everything except
the system libraries (frameworks in XCode, which I believe are just
dynamic libraries, linked with a dynamic c runtime). Is it possible,
with gcc 4, to isolate operator new/delete overloads to a libarary?
Can it be static or does it have to be dynamic? If so I could put all
my code in one (library). But I don't want the system frameworks
(other dynamic libaries) to get a hold of my overloads when I link the
application and I don't want my code to use the non-overloaded
new/delete.
1) I don't know XCode, So I am not sure that I completely understand your question.
I can speak only in general terms, which is applicable not only to gcc 4,
but also for other compiler environments.
My point is that it is not possible to make a clear separation of the STL that
your code is using and the STL that is used by libraries used by your code.
There is an overlap.
E.g., you may use the std::string class, but the library may use the std::string class
as well. The std::string class uses new/delete internally. Should this class std::string
use the overloaded version or the original version? You cannot have both.

2) You now speak not only about an overloaded operator new, but also about an
operator delete. If the overloaded versions are not compatible with the original
operators, the pairing of new and delete must be very strict. (An object created with
and overloaded new should not be destructed with the original delete and vice versa.)
This can not be guaranteed if part of the STL is in dynamic libraries and part of it is
in static libraries. However, as I explained before, you have no control of what is
in dynamic libraries and what is in static libraries, in particular in cases where templates
from the STL are used.

Concluding I would say that what you want is impossible in interpreted strictly.
However, if you can live with cases where the wrong version of the new/delete is
used it is possible to go a bit in that direction.

Fred.Zwarts.
Sep 28 '06 #5

ri************@adventure.com wrote:
Hello,

I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be overloaded, but I need to
link with the system libraries (frameworks) and I DO NOT want my
overloads to be mapped to them. I'm working with some code that is
currently working on Win32 but also needs to work on the Mac. Under
windows this is very simple because none of the essential Win32
libraries use or require C++ (or at least in no way that gets exposed
to normal application code), and overloading operator new has no effect
on their memory allocations. I need similar functionality on the Mac
using XCode2.2 (which I think is using gcc 4). This first pass is just
being built for intel (mainly so I don't have to deal with endian
issues right now). Maybe some odd combination of dynamic and static
libraries linked in the right order might do it??
Do not overload the global new operator. Over the new operator specific
to your class only, if you at all need.

Sep 28 '06 #6

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

Similar topics

5
by: bsaucer | last post by:
I am creating a class with operator overloads. It makes references to another class I've created, but do not wish to modify. I try to overload an operator having arguments having the other class...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
4
by: Chiller | last post by:
Ok, thanks to some good assistance/advice from people in this group I've been able to further develop my Distance class. Since previous posts I've refined my code to accept the unit measurement...
7
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the compiler complain this. Thanks, $ g++...
17
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: ...
9
by: Tony | last post by:
I have an operator== overload that compares two items and returns a new class as the result of the comparison (instead of the normal bool) I then get an ambiguous operater compile error when I...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
11
by: dascandy | last post by:
Hello, I was wondering, why is overloading operator. (period) forbidden? It would make a few odd applications possible (dynamic inheritance and transparent remote method invocation spring to my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.