overwrite operator new and delete

Login to reply to this topic.
Tue, 2005-02-01 21:16
Joined: 2004-12-14
Forum posts: 20
Hello,

 In our application we wanted to do memory management by ourselves. Basically we will allocate a chunk of memory that is big enough for our use and overwrite operator new and delete, so that inside our application all the memory allocation is done through the big chunk.

 However we encounter a linker error complaining operator new and deleted is all ready defined. One of the symbian headers (e32std.h) overwrites new and delete. I understand why there is a new with a "TLeave" parameter, but I don't understand why the normal new and delete is overwritten --- can anyone tell me if there is any special work done in this new and delete?

 In our code we have to include e32std.h for its other functionalities, but then we can not use our own new and delete --- is there a workaround that we can have both?

Thanks for your response.

Wed, 2005-02-02 00:00
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2009
overwrite operator new and delete
It just leaves if the allocation fails. The value of the TLeave parameter is not used.

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Wed, 2005-02-02 00:09
Joined: 2004-12-14
Forum posts: 20
To Eric
Sorry my question is about the normal new/delete which doesn't take a TLeave parameter. the function signatures are as following:

GLREF_C TAny* operator new(TUint aSize);
GLREF_C void operator delete(TAny* aPtr);

Do they do anything special? Thanks
Wed, 2005-02-02 01:04
Anonymous (not verified)
Forum posts: 2043
Re: To Eric
operator new(TUint aSize, ELeave)
ultimatley calls RHeap::AllocL(), via User::AllocL() if I remember

operator new(TUint aSize)
calls
RHeap::Alloc() via User::Alloc().

However those overloads don't exist anymore.
Wed, 2005-02-02 08:14
Joined: 2004-12-03
Forum posts: 192
overwrite operator new and delete
look through the forum. that question has been discussed.
Wed, 2005-02-02 08:57
Joined: 2004-07-28
Forum posts: 1379
overwrite operator new and delete
Specifically here:

http://forum.newlc.com/viewtopic.php?t=4083

You can't just provide your own new and delete in the global namespace, because these have already been defined in the base libs and as you notice, you get linker errors.

You either have to use the same tricks new (ELeave) does - so you'd end up doing something like new (EMyMemoryManager) - or you use namespaces to seperate your new and delete from the global namespace.

It's discussed in depth in that thread.

didster

Fri, 2005-02-04 00:44
Joined: 2004-12-14
Forum posts: 20
overwrite operator new and delete
Thanks for all the response. The namespace approach looks really promising.
  • Login to reply to this topic.