digitalmars.D.learn - Explicit Class Instance Allocation
- Mike (30/30) Feb 05 2014 In this article (http://dlang.org/memory.html) there is an
- bearophile (4/7) Feb 05 2014 Also that usage of new() is deprecated.
- Mike (3/10) Feb 05 2014 Thank you, but can you please point me to your source. It's not
- Stanislav Blinov (3/16) Feb 05 2014 It's mentioned here: http://dlang.org/class.html#allocators.
- bearophile (4/5) Feb 05 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12081
- Stanislav Blinov (2/3) Feb 05 2014 Why do I sense another holy war in the bugzilla coming? :)
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
Feb 05 2014
Mike:class Foo { new(size_t sz)Also that usage of new() is deprecated. Bye, bearophile
Feb 05 2014
On Wednesday, 5 February 2014 at 11:19:00 UTC, bearophile wrote:Mike:Thank you, but can you please point me to your source. It's not listed here (http://dlang.org/deprecate.html)class Foo { new(size_t sz)Also that usage of new() is deprecated. Bye, bearophile
Feb 05 2014
On Wednesday, 5 February 2014 at 11:23:57 UTC, Mike wrote:On Wednesday, 5 February 2014 at 11:19:00 UTC, bearophile wrote:It's mentioned here: http://dlang.org/class.html#allocators. Perhaps a bugreport or even a pull request is in order?Mike:Thank you, but can you please point me to your source. It's not listed here (http://dlang.org/deprecate.html)class Foo { new(size_t sz)Also that usage of new() is deprecated. Bye, bearophile
Feb 05 2014
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
Feb 05 2014
On Wednesday, 5 February 2014 at 12:12:12 UTC, bearophile wrote:https://d.puremagic.com/issues/show_bug.cgi?id=12081Why do I sense another holy war in the bugzilla coming? :)
Feb 05 2014