By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,165 Members | 980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,165 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a

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

P: n/a
<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

P: n/a

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

P: n/a
<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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.