Custom delete not getting called
d coder
dlang.coder at gmail.com
Fri Jun 24 20:53:19 PDT 2011
Hello People
I was just trying out custom memory allocation/deallocation that can be
found on the link
http://www.d-programming-language.org/memory.html#newdelete
The problem is that the delete function is never getting called. I have put
an example test case at the end of the email.
Any ideas?
Regards
- Puneet
import core.memory : GC;
import std.stdio;
import std.exception; // enforce
class Foo {
string value = ".";
new(size_t sz) {
write("+");
void* p = enforce(GC.malloc(sz),
"Out of memory while allocating Foo");
GC.addRange(p, sz);
return p;
}
delete(void* p) {
write("-");
if (p) {
GC.removeRange(p);
GC.free(p);
}
}
}
void main() {
for (size_t i = 0; i < 32; ++i) {
Foo foo = new Foo();
write(foo.value);
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110625/18e0ef89/attachment.html>
More information about the Digitalmars-d
mailing list