[Issue 2105] Manual Memory Management for Associative Arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Sep 10 20:14:15 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2105
------- Comment #10 from dsimcha at yahoo.com 2008-09-10 22:14 -------
Here's a slightly updated version of deleteAA() that allows a reference to be
reused after the AA is deleted, so that deleteAA() can be used as both a memory
management tool and a clear function.
void deleteAA(T, U)(ref T[U] input) {
auto aaPtr = cast(BB*) cast(void*) input;
deleteBB(aaPtr);
//Allows AA reference to be reused, i.e. this can be used as a clear
function.
input = (T[U]).init;
}
void deleteBB(BB* aaPtr) {
void rdelAA(aaA* input) {
if(input.left !is null)
rdelAA(input.left);
if(input.right !is null)
rdelAA(input.right);
delete input;
}
foreach(node; aaPtr.b)
if(node !is null)
rdelAA(node);
delete aaPtr.b;
delete aaPtr;
}
--
More information about the Digitalmars-d-bugs
mailing list