Re: C++ Objects in pfDataPool

New Message Reply Date view Thread view Subject view Author view

Marcus Barnes (marcus++at++multigen.com)
Wed, 20 Aug 1997 11:37:47 -0700


On Aug 19, 7:36pm, Chehayeb, Nassouh wrote:
> I want to create a general method to allocate object form a
> pfDataPool, so I create the following class:

[munch]

> void *PoolObject::operator new(size_t sz, int id)
> {
> void *mem;
>
> // żżż cast from volatile void * to void * ???
> mem = (void *) GetDataPool()->alloc(sz, id);

This cast is more precisely a const_cast<> and required by the language in this
circumstance. The pointer returned by alloc() is to shared memory and the data
it points to may be changed in ways unknown to the compiler. "volatile"
prevents the compiler from optimizing away data fetches related to the pointer
that are required for proper behavior. The reason you need the cast is because
C++ requires that operator new() return "void*" only.

[munch]

> class MyObject: public PoolObject
> {
> protected:
> int val;
>
> public:
> MyObject(int _val) { val = _val;}
> ~MyObject() {}
> };
>
> // in othe file the used can write:
> MyObject *mo = new MyObject(500);

"mo" is semantically volatile. Your scheme is casting away volatile. Your class
is more properly defined as:

class MgObject: public PoolObject { ... int volatile val; ... };

All data members of classes derived from PoolObject should be declared
volatile.

> // will create the object in the pool memory and call its constuctor.
> /*__________________________________________________*/
>
> The problem is that this method may causes a SIGBUS error (because of
> the cast above?).

I don't think the cast is the problem. You don't show the statement that
produces the bus error (access alignment error).

Regards.

--
+ Marcus Barnes, Technical Staff        mailto:marcus++at++multigen.com +
+ Multigen Inc.                         http://www.multigen.com    +
+ 550 S. Winchester Blvd.               phoneto:1-408-556-2654     +
+ Suite 500 San Jose CA 95128           faxto:1-408-261-4102       +

===================================List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/ Submissions: info-performer++at++sgi.com Admin. requests: info-performer-request++at++sgi.com


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:55:45 PDT

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