473,225 Members | 1,201 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,225 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 3448

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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.