Strange linking behavior when overriding global new and malloc

Discussion in 'C++' started by Ryan Mack, May 24, 2004.

  1. Ryan Mack

    Ryan Mack Guest

    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
     
    Ryan Mack, May 24, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john smith

    overriding malloc and free

    john smith, Jan 19, 2005, in forum: C++
    Replies:
    4
    Views:
    10,022
    Dietmar Kuehl
    Jan 19, 2005
  2. shoosh
    Replies:
    6
    Views:
    3,277
    Dietmar Kuehl
    Jan 29, 2005
  3. john smith

    overriding global new

    john smith, Jan 28, 2005, in forum: C++
    Replies:
    1
    Views:
    4,033
    Ian McCulloch
    Jan 28, 2005
  4. Mark P
    Replies:
    6
    Views:
    847
    James Dennett
    Apr 27, 2005
  5. PerlFAQ Server
    Replies:
    0
    Views:
    147
    PerlFAQ Server
    Feb 3, 2011
Loading...

Share This Page