delegate memory layout help needed

torhu fake at address.dude
Tue Feb 13 19:23:54 PST 2007


nobody wrote:
> More importantly I have been trying to watch two delegate members of a struct to 
>   make sure they are getting initialized:
> 
>      printf("&opIndexDg : [%X]\n", opIndexDg );
>      printf("    +0 -> [%X]\n", *(cast(int*)(&opIndexDg)+0) );
>      printf("    +1 -> [%X]\n", *(cast(int*)(&opIndexDg)+1) );
> 
>      printf("&opIndexAssignDg : [%X]\n", &opIndexAssignDg );
>      printf("     +0 -> [%X]\n", *(cast(int*)(&opIndexAssignDg)+0) );
>      printf("     +1 -> [%X]\n", *(cast(int*)(&opIndexAssignDg)+1) );
> 
> According to what I have seen the delegates in the struct are getting 
> initialized but I keep getting an Array Bounds Error unless I do the exact same 
> assignment done during the initialization afterwards in main(). Am I correctly 
> interpreting the memory layout?

You can access the context pointer with .ptr, and the function pointer 
with .funcptr.  See:

http://www.digitalmars.com/d/function.html#closures

As for the array bounds error, it's hard to tell without some more 
context.  A common mistake is to return a delegate whose .ptr points to 
stack data.


More information about the Digitalmars-d-learn mailing list