Re: Overloading the 'new' operator

New Message Reply Date view Thread view Subject view Author view

Michael J. Smith (smith++at++vsl.ist.ucf.edu)
Wed, 31 May 1995 09:25:44 -0400 (EDT)


On Tue, 30 May 1995, Jim Helman wrote:

> I'm not sure why you are having problems since the same should be
> possible using a usinit arena (although a usinit arena is only
> *required* between unrelated processes and takes some care in
> positioning with usconfig(CONF_ATTACHADDR,...) to avoid virtual
> memory conflicts). This latter could be causing your problems.

Yes, if I add the following to my main program...

static usptr_t *arena;

void* operator new(unsigned int size)
{ return usmalloc(size, arena); }

void operator delete(void *info)
{ usfree(info, arena); }

....

int main(...
{

  arena = usinit("/usr/tmp/loader");
  usadd(arena);
   
  ....code that start's newing things like a class that interfaces with
        most of Performers primitives.

}

I get the following reset when I run it:

When my code tries to do a pfNewScene...this makes recursive calls back
to my delete operator which cause a segmentation violation. Is this
because the libpr libraries use "new" and not "::new"? If so, how can
I get around this?

the call stack looks like this for reference...some of the PC's are deleted
for clarity.

   1 _afree(0x625690, 0x580a78, 0x4, 0x625d14) ["amalloc.c":89, 0xfb0da00]
   2 _usfree(0x1, 0x62568c, 0x4, 0x625d14) ["usmalloc.c":42, 0xfb2efd4]
   3 operator delete(void*)() ["main.C":46, 0x418000]
   4 pfUpdatableList::_grow(void)() ["../../../lib/libpf/pfLists.C":25, 0x5ffa5b2c]
   5 pfUpdatableList::set(long,const pfUpdatable*)() ["../../../lib/libpf/pfLists.C":25, 0x5ffa5c0c]
   6 pfBuffer::newUpdatable(pfUpdatable*)() ["../../../lib/libpf/pfBuffer.C":172, 0x5ff8a20c]
   7 pfUpdatable::pfUpdatable(pfBuffer*)() ["../../../lib/libpf/pfUpdatable.C":19, 0x5ffd961c]
   8 pfNode::pfNode(pfBuffer*)() ["../../../lib/libpf/pfNode.C":37, 0x5ffac3a4]
   9 pfGroup::pfGroup(pfBuffer*)() ["../../../lib/libpf/pfGroup.C":21, 0x5ff9aadc]
   10 pfScene::pfScene(pfBuffer*)() ["../../../lib/libpf/pfScene.C":20, 0x5ffc4b4c]
   11 pfNewScene() ["../../../lib/libpf/pfProcess.C":2778, 0x5ffc130c]
   12 PerformerShell::PerformerShell(void)() ["PerfShell.C":195, 0x419704]
   13 main(0x1, 0x7fffaf34, 0x4, 0x625d14) ["main.C":67, 0x41808c]
   14 __start() ["crt1text.s":133, 0x417d2c]

>
> Performer has always used an overloaded new() operator for allocating
> libpf objects. In 1.2, this operator is a global new() operator with
> a private second argument type to keep it internal and separate from
> any application's usage or overloading of new. In 2.0, this has been
> changed so that libpf objects are newed using an class-specific new()
> function overloaded as appropriate within the libpr/libpf class
> hierarchy.
>

In 1.2 you may be using the correct new function, but this definitely isn't
using the correct delete function. Is there any way I can tell in my
delete that it needs to be pfFree'ed instead of usfree'ed?
  
-----------------------------------------------------------------------------
| Michael J. Smith University Of Central Florida |
| Visual Systems Laboratory Institute for Simulation & Training |
| Graduate Research Assistant 3280 Progress Drive |
| smith++at++vsl.ist.ucf.edu Orlando, FL 32826-0544 |
| ++at++cs.ucf.edu |
| Codesmith for hire |
-----------------------------------------------------------------------------


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:51:33 PDT

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