@nogc and NSAutoPool-style regions.

via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Jul 8 09:46:56 PDT 2014


Seems to me that most of the utility beyond maintaining graph 
like structures can be covered by making the compiler aware of 
region allocator semantics. Assuming that the use of GC is 
constrained locally and does not consume too much space. I think 
it would work out ok for loading of smaller files etc with the 
following kind of semantics:

Something_ptr someglobalvar;

process(A a) {
   int x;

   @regionalloc(1024,256) { // 1 MiB default size, 256KiB 
increments

	auto y = new ...; // gc new() is hijacked by @regionalloc
	
	// assignments must be restricted so that new() ptrs and y ptrs
	// are not assigned to memory that can escape the @regionalloc
	
	// and no writes to global ptrs of region allocated objects 
allowed

	auto ptr = compute_with_constrained_gc_semantics(a,y)
	
	someglobalvar = make_malloc_copy(ptr); // optimization: remove 
temporary
	x = obtain_some_value(ptr);
   }

   // region is dead here, including y and ptr objects

}

The real challenge is in putting the right constraints on the 
@regionalloc block, but I guess weakly pure functions are kind of 
close in their constraints. So it should be possible?

The goal would be to be able to link to libraries that aren't 
@nogc aware without having the GC runtime available. For loading, 
initialization etc.


More information about the Digitalmars-d-announce mailing list