New memory management strategy

Axe via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 24 22:29:02 PDT 2017


Hi there. I have found a new memory management strategy based on 
whole program lifetime inference.

Disclaimer: I am no expert and hence what follows may be 
completely wrong or impractical. So bear with me.

The first step is to construct an "escape" lists for each and 
every function.
Escape list stores all the lvalues that may escape, while all 
other lvalues are released when the scope ends.

Foo get(Baz baz)
{	
	Bar bar;
	baz.bar = bar; // 'bar' escapes into field 'bar' of 'baz' which 
is the argument.
} // Escape list consist of 'bar'. Every field of 'baz' except 
baz.bar is freed.

int main()
{
	Baz baz; // Scope depth is 1.
	get(baz); // From the already built escape list for 'get', we 
can infer
			  // that baz.bar escapes to call-site's scope depth 1.
} // baz is eventually released here.

Since we cannot find the control flow path in a function. All the 
variable
declarations are moved to the top of the function, so that 
control flow doesn't determine whether
the variables are allocated or not.

Now the question is whether this is correct/practical or not?


More information about the Digitalmars-d mailing list