use of virtual methods with user classes allocated with pfMalloc

New Message Reply Date view Thread view Subject view Author view

Scott Watson (scott++at++disney.com)
Sat, 3 Feb 1996 13:19:38 -0800


Dwight> I have created a class hierarchy that has virtual methods
Dwight> and am using pfMalloc to create instances of
Dwight> these. Whenever I call one of the virtual methods, I get
Dwight> core dump at the entry to the method. I do not make it into
Dwight> the method near as I can tell. When I look at the class

...

Dwight> Pointers on how I can create classes with virtual methods
Dwight> that I can pfMalloc into the shared arena would be greatly
Dwight> appreciated.

I'm not sure it addresses your problem but we use virtual functions
of objects allocated in shared arenas and use them in multiple
processes and it works ok.

We override new like:

void * operator new (size_t n) {
    void * p;
    if(!arena_inited) dvInitArena();

    if(! n) n++; // catch people who alloc 0 len

    if(arena){ // support running w/o a shared arena
        p = usmalloc(n, arena);
    } else {
        p = malloc(n);
    }

    if (!p) { // Be informative about failure to allocate
      report_mem_err();
    }
    return p;
}

Since most of our system is loaded as .so we also have the following
in our link/compile lines.

  -Wl,-update_registry,/usr/local/lib/so_locations

which has the effect of putting the text of your program at the
same address even when your not forked from the same parent.

-Scott


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:21 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.