Anybody can figure out how does CBase::operator new() work?

Login to reply to this topic.
Mon, 2005-08-22 08:15
Joined: 2003-04-01
Forum posts: 37
Hi all,

In Symbian SDK Doc  » Symbian OS v6.1 Edition for C++ » API Reference » Basic Types » CBase, it said:

Initialisation of the CBase derived object to binary zeroes through a specific CBase::operator new() - this means that members, whose initial value should be zero, do not have to be initialised in the constructor. This allows safe destruction of a partially-constructed object.

It means:

class CBaseTest : public CBase
{
   void* p;
};
class CTest
{
   void* p;
};

CBaseTest* bt = new CBaseTest;   // bt->p == NULL
CTest* t = new CTest;      // t->p != NULL


Anybody know how to do that? I wanna implement the CBase in other platform, but I can't figure out how to do that?  Sad

Thanks

ouseka


Mon, 2005-08-22 16:38
Joined: 2005-07-28
Forum posts: 122
Re: Anybody can figure out how does CBase::operator new() work?
I suggest you read some C++ books covering operator overloading, particularly the new operator. I would guess that anyone here who as seen the Symbian OS code would not be able to tell you how to do that, as it could be constructed that they have broken an NDA. However it's not difficult, and some books give possible solutions. In addition a search through the epoc32\include directory will give you a the CBase new operators signature.
Tue, 2005-08-23 01:49
Joined: 2003-04-01
Forum posts: 37
Re: Anybody can figure out how does CBase::operator new() work?
Thanks woods!

I had read the e32base.h e32base.inl etc., but it seems the operator new not overloaded, because while i comment all the code about operator new in e32base.h & e32base.inl,
the test code ditto still works.

//--- in e32base.h
class CBase
   {
public:
   IMPORT_C virtual ~CBase();
//   inline TAny* operator new(TUint aSize,TAny *aBase);
//   IMPORT_C TAny* operator new(TUint aSize);
//   inline TAny* operator new(TUint aSize, TLeave);
//   IMPORT_C TAny* operator new(TUint aSize,TUint anExtraSize);
protected:
   IMPORT_C CBase();
private:
   CBase(const CBase&);
   CBase& operator=(const CBase&);
//   IMPORT_C static TAny* newL(TUint aSize);
   };

//--- in e32base.inl
// Class CBase
//inline TAny* CBase::operator new(TUint aSize, TAny* aBase)
//   {Mem::FillZ(aBase,aSize);return(aBase);}
//inline TAny* CBase::operator new(TUint aSize, TLeave)
//   {return newL(aSize);}

ouseka

Tue, 2005-08-23 11:57
Joined: 2005-05-09
Forum posts: 46
Re: Anybody can figure out how does CBase::operator new() work?
Your code is still calling CBase operator new. Commenting it out in the header makes no difference. You don't get any compile errors because of the global operator new, but your code will sill call CBase's operator new.

It is as mc_woods said, you need to override operator new.

From the SDK docs:

Code:
Initialisation of the CBase derived object to binary zeroes through a specific CBase::operator new() - this means that members, whose initial value should be zero, do not have to be initialised in the constructor. This allows safe destruction of a partially-constructed object.

I reccommend Effective C++ by Meyers. It has an excellent description of how it can be done.
Wed, 2005-08-24 07:59
Joined: 2003-04-01
Forum posts: 37
Re: Anybody can figure out how does CBase::operator new() work?
Thanks cook & woods, I had resolved it by overriding CBase::operator new() according to Lauri's help at FN discussion board.
It's really exciting!  Grin Thanks!

ouseka

Sun, 2005-08-28 03:34
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: Anybody can figure out how does CBase::operator new() work?
Quote from: ouseka
Thanks cook & woods, I had resolved it by overriding CBase::operator new() according to Lauri's help at FN discussion board.
It's really exciting!  Grin Thanks!

I would really appreciate a link to that discussion. I guess others might also be interested in that.

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Mon, 2005-08-29 05:21
Joined: 2003-04-01
Forum posts: 37
Re: Anybody can figure out how does CBase::operator new() work?
  • Login to reply to this topic.