www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do you overload new and delete for a class?

reply Adrian Mercieca <amercieca gmail.com> writes:
Hi,

Can someone please provide an example regarding overloading new and delete 
for a class?

Thanks a lot.
Jan 09 2012
parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 09-01-2012 20:41, Adrian Mercieca wrote:
 Hi,

 Can someone please provide an example regarding overloading new and delete
 for a class?

 Thanks a lot.
This is deprecated. What you should be doing is using std.conv.emplace() with whatever allocator (say, malloc()) you wish to use. - Alex
Jan 09 2012
parent Adrian Mercieca <amercieca gmail.com> writes:
Hi Alex,

Thanks for the answer.

As for the allocation, you mention malloc: is that malloc from the C 
runtime library? You also imply alternatives to this allocator; what would 
these be?

As for deletion, does on then invoke delete on the malloc'ed data pointer?

Pointing me to some example would be greatly appreciated.

Thanks.
- Adrian.
Jan 09 2012