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

overload new in shared library (crazy)

P: n/a
Hi

I have overloaded new in a shared library (s1.so) sucessfully. but I do
not what main program and any other shared library to be able to use
this new operator. In other words, I do not operator new to be globally
used.

I tried some ld options -Bsymbolic as follows

g++ -shared -Wl,-Bysmbolic f1.o -o s1.so
g++ -lstdc++ main.o s1.so -o main

However, if I put -lstdc++ after s1.so, the overloaded new being used
by main (which is not what I want )

Any comments?

thanks
yan

Apr 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sh*****@gmail.com wrote:
I have overloaded new in a shared library (s1.so) sucessfully. but I
do not what main program and any other shared library to be able to
use this new operator. In other words, I do not operator new to be
globally used.

I tried some ld options -Bsymbolic as follows

g++ -shared -Wl,-Bysmbolic f1.o -o s1.so
g++ -lstdc++ main.o s1.so -o main

However, if I put -lstdc++ after s1.so, the overloaded new being used
by main (which is not what I want )

Any comments?


For compiler- and platform- specific questions please ask in the newsgroups
for that compiler or that platform. "Shared library" is a concept undefined
in C++. "ld options" is specific to your compiler and/or platform.

Usually, a way to limit the use of the overloaded operator 'new' is to give
it an additional argument, similar to

// header
class my_new_identifier {}; // just some unique type
extern my_new_identifier mynew;

// implementation
my_new_identifier mynew;
void* operator new(size_t howmuch, my_new_identifier&) {
... // same as before
}

// somewhere in the code
SomeClass* ptr = new SomeClass(args); // regular 'new'
SomeClass* ptr2 = new (mynew) SomeClass(args); // your 'new'

Well, you get the idea. Disclaimer: I didn't test this.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 18 '06 #2

P: n/a
gcc has an option for controlling symbol visibility.
You need to declare your overloaded function with
__attribute__ ((visibility("hidden")))
My gcc compiler is not yet configured to use the "visibility" option and
I couldn't try it out.
good luck.
-Aman.

--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Apr 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.