From: Alexandre Naaman (naaman++at++laplace.engr.sgi.com)
Date: 10/15/2000 03:25:02
On Sun, 15 Oct 2000, Satheesh Ganapathi Subramanian wrote:
Hi Satheesh,
You really should not try calling methods on a pointer to an object if
you've not created it via new. The new operator will invoke the
constructor and allocate sufficient memory for you. Simply malloc'ing
enough memory to hold the sizeof(your class struct) is not sufficient.
Try replacing the line:
a = (B*) pfMalloc (sizeof(B), pfGetSharedArena());
with:
a = new (pfGetSharedArena()) B;
in order for this to work you need to ensure that you are deriving your
classes from pfMemory or add the following somewhere in the definition of
your base class:
class A {
PFSTRUCT_DECLARE
};
and include <Performer/pr/pfStruct.h>
> Hi Performers,
>
> I've a question regarding the use of pfMalloc to allocate memory for user
> defined classes.
>
> I've a class A, class B and class C as follows:
>
> class A {
> public:
> ...
> virtual void initialize() = 0;
>
> };
>
> class B : public A{
> public:
> void initialize();
> }
>
> class C : public pfTexture{
> public:
> A* a;
> static void init();
> void initialize();
> }
>
> void C::init()
> {
> pfTexture::init();
> initialize();
> }
>
> void C::initialize()
> {
> a = (B*) pfMalloc (sizeof(B), pfGetSharedArena());
> a->initialize(); /*----------- Get core dump here ------- */
> }
>
> When I try to run this program, I get a core dump at the placed marked.
> Infact, any virtual function called by A dumps core. Can anyone point the
> mistake I'm making. I'm not sure if this is totally a C++ problem or is it
> in some way related to pfMalloc.
>
> Thanks
> Satheesh
>
> -----------------------------------------------------------------------
> List Archives, FAQ, FTP: http://www.sgi.com/software/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
>
A+,
Alexandre.
-- Alexandre Naaman - naaman++at++sgi.com - La conformite est la mort de l'ame.
This archive was generated by hypermail 2b29 : Sun Oct 15 2000 - 03:25:09 PDT