Explicit Class Instance Allocation

2014-02-05 Thread Mike
In this article (http://dlang.org/memory.html) there is an 
example showing how one could explicitly allocate and deallocate 
an object.  However, the article seems to be sorely neglected and 
out of date ('delete' is deprecated, right?).  Could someone 
modify the example below using current best practices.


import std.c.stdlib;
import core.exception;
import core.memory : GC;

class Foo
{
new(size_t sz)
{
void* p;

p = std.c.stdlib.malloc(sz);

if (!p)
throw new OutOfMemoryError();

GC.addRange(p, sz);
return p;
}

delete(void* p)
{
if (p)
{
GC.removeRange(p);
std.c.stdlib.free(p);
}
}
}

Thanks,
Mike


Re: Explicit Class Instance Allocation

2014-02-05 Thread bearophile

Mike:


class Foo
{
new(size_t sz)


Also that usage of new() is deprecated.

Bye,
bearophile


Re: Explicit Class Instance Allocation

2014-02-05 Thread Mike

On Wednesday, 5 February 2014 at 11:19:00 UTC, bearophile wrote:

Mike:


class Foo
{
   new(size_t sz)


Also that usage of new() is deprecated.

Bye,
bearophile


Thank you, but can you please point me to your source.  It's not 
listed here (http://dlang.org/deprecate.html)


Re: Explicit Class Instance Allocation

2014-02-05 Thread Stanislav Blinov

On Wednesday, 5 February 2014 at 11:23:57 UTC, Mike wrote:

On Wednesday, 5 February 2014 at 11:19:00 UTC, bearophile wrote:

Mike:


class Foo
{
  new(size_t sz)


Also that usage of new() is deprecated.

Bye,
bearophile


Thank you, but can you please point me to your source.  It's 
not listed here (http://dlang.org/deprecate.html)


It's mentioned here: http://dlang.org/class.html#allocators.

Perhaps a bugreport or even a pull request is in order?


Re: Explicit Class Instance Allocation

2014-02-05 Thread bearophile

Stanislav Blinov:


Perhaps a bugreport or even a pull request is in order?


https://d.puremagic.com/issues/show_bug.cgi?id=12081

Bye,
bearophile


Re: Explicit Class Instance Allocation

2014-02-05 Thread Stanislav Blinov

On Wednesday, 5 February 2014 at 12:12:12 UTC, bearophile wrote:


https://d.puremagic.com/issues/show_bug.cgi?id=12081


Why do I sense another holy war in the bugzilla coming? :)