I am writing virtual machine that has Garbage Collector that when he runs out of memory he allocates big chunk of memory. I need to implement delegates that you can convert (Similar to C#'s) A.B(C)
to simply D()
(D is the delegate variable).
My solution: To create those dynamically I thought about generating function in runtime and store them in the GCHeap (I need in the GCHeap because that it can be unreachable in the future), but to run them I need to make the whole memory in the GC marked as executable, writeable and readable.
Will it impact performance for accessing the memories that aren't delegates but still have been marked by those permissions? Is there better solution?
NOTE: I know those permissions is to throw exceptions when program doesn't working properly by executing memory that not meant to be executable, but I can't afford to lose the performance of big chunks's allocations.
Instead of flagging memory regions that can do security issues. You can for example expand in compile time: (C# as pseudo-code)
public static Func<???> Method() { //Not the same Func as C#'s implementing, and ??? is the return type.
MyClass A=...,C=...;
return ( ) => A.B(C);
}
To:
class __call001 /* Anonymous type */ : Func<???> {
MyClass var0, var1; //Storing those variables,
//because we won't have them available when calling the lambda.
public __class001(MyClass var0, MyClass var1) {
this.var0=var0;
this.var1=var1;
}
public override ??? operator() {
var0.B(var1);
}
}
...
public static Func<???> Method() {
MyClass A=..., C=...;
return new __call001(A, C);
}