Allocating and freeing memory like this?

Bienlein jeti789 at web.de
Wed Feb 26 01:14:40 PST 2014


Hello,

ich found this article on the Internet that explains how to do 
malloc and free in D: 
http://fgda.pl/post/8/a-look-at-the-d-programming-language See 
the functions named _new and _delete. My question is whether this 
is really the way to allocate and free some memory for a class 
manually in D. Because I just did this playing around with D and 
it seems to work:

class D {
	public int i;
}

void main(string[] args)
{
	auto d = new D();
	delete(d);

         d.i = 123; // creates Access Violation as expected
}

The article confused me. Is the contents outdated or am I messing 
something up?

Thanks for shedding any light on this for me ;-).
Regards, Bienlein


More information about the Digitalmars-d-learn mailing list