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

Strange linking behavior when overriding global new and malloc

P: n/a
I'm doing development on an embedded system using a GCC 2.96 MIPS cross
compiler and a minimal C standard library replacement. The system loads
at startup a base executable. The base executable then loads one DLL
after another during execution to reduce memory usage. The base
executable statically links in a library which overrides the default
malloc (and related functions) and the built-in operator new/delete. That
works fine and as expected.

The DLLs, on the other hand, do not statically link in this library (or
the C standard library) as they can call code in the base executable which
already defines these functions. The DLL, unlike I had expected, does not
call my new function, but the built-in new function in turn *does* call my
malloc function. The solution was to statically link the library defining
new/malloc/etc into both the base executable and all of the DLLs. These
functions are one-line wrappers around our memory manager so the space
wasted is minimal.

Could someone please explain why I'm seeing this behavior? I don't
understand why the DLLs wouldn't call my new function but it would call my
malloc function. I would have guessed they would behave the same.

Thanks a bunch, Ryan Mack. Please CC me at:
[first letter of first name][last name]@[last name]man.net
Jul 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.