| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
January 25, 2009 C++ operator new | ||||
|---|---|---|---|---|
| ||||
Hi,
I wonder if this is doable in D ?
class Cpp
{
public:
void* operator new(size_t n);
void* operator new(size_t n, void* p)
{ return p; }
}
Just guessing that operator new means this in D
class D
{
new(uint n);
new(uint n,void* p)
{ return p; }
}
Am I wrong ?
TIA, Bjoern
| ||||
January 25, 2009 Re: C++ operator new | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote: > Hi, > > I wonder if this is doable in D ? > > class Cpp > { > public: > void* operator new(size_t n); > void* operator new(size_t n, void* p) > { return p; } > > } > > Just guessing that operator new means this in D > class D > { > new(uint n); > new(uint n,void* p) > { return p; } > > } > > Am I wrong ? > TIA, Bjoern > http://digitalmars.com/d/1.0/class.html#allocators | |||
January 25, 2009 Re: C++ operator new | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Keep | This might also be of interest, as it has an example of overriding allocation/deallocation to use malloc: http://digitalmars.com/d/1.0/memory.html#newdelete | |||
January 25, 2009 Re: C++ operator new | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Keep | Daniel Keep wrote:
> This might also be of interest, as it has an example of overriding
> allocation/deallocation to use malloc:
>
> http://digitalmars.com/d/1.0/memory.html#newdelete
Thanks! It seems that using freelists is preferable. Are there any
drawbacks ? F.I. How to implement a class using freelist + constructor/destructor, if possible at all...
Bjoern
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply