[Mono-devel-list] Managed to unmanaged structure question

Peter Dennis Bartok peter at novonyx.com
Fri Jun 11 01:00:20 EDT 2004


Did some more testing. On MS.Net I get the proper size returned. Also 
did more crash-testing. We definitely do not allocate enough memory when 
passing the structure to an unmanaged function. I'm filing a bug.

Peter

Peter Dennis Bartok wrote:
> Hi all,
> 
> Got a (hopefully) simple question:
> 
> If I have a structure:
> 
>  internal struct TestStructure
>         {
>                 internal int      number;
> [MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, 
> SizeConst=1024)]
>                 internal byte[] stuff;
>         }
> 
> and some code:
> 
>  TestStructure t = new TestStructure();
> 
>  Console.WriteLine("Size of t: {0}", 
> Marshal.SizeOf(typeof(TestStructure)));
> 
> I it returns a size of 8, instead of the expected size of 1028.
> 
> If I now pass this structure as ref to unmanaged code, and that code 
> writes more than 8 bytes, it seems that data gets overwritten. (I've got 
> some sample code that shows that the call stack is ok before the 
> P/Invoke and messed up afterwards, if I write more data)
> 
> Can anyone shed light on this, whether I'm up in the night or whether 
> this is a real bug?
> 
> Cheers,
>   Peter
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 



More information about the Mono-devel-list mailing list