c# - Size of managed structures -


Introduction to classes for the .NET 4.0 framework. The centers are centered around the methods and. These are not martial, but copied from and to the file in which they are laid out in the managed memory

Let's say I use a memory-mapped file to use these methods Want to write two structures sequentially:

  [structure layout (layout kick, seqyk, pack = 1)] structure fu {public four c; Public Bull B; } [StructLayout (LayoutKind.Sequential, Pack = 1)] struct bar {} static void type & lt; T1, T2 & gt; (MemoryMappedViewAccessor Accessor = file.CreateViewAccessor ()) (T1 item 1, T2 ITEM2) where T1: struct using T2: struct {(MemoryMappedFile file = MemoryMappedViewAccessor =) MemoryMappedFile.CreateNew (Null, 32)) {Accessor.Write & LT; T1 & gt; (0L, ITEM1 referee); // & lt; - (1) Accessor. Write and lieutenant; T2 & gt; (??, ref. 2); // & lt; - (2)}} static zero principal () {Foo foo = new fu {C = 'α', b = true}; Repeatedly = new times {}; Write (af, bar); }  

How do I get the number of bytes written in (1) so that I add the next value (2)?

Note: The number of bytes in the example is 3 (= 2 + 1), not given by Marshal.SizeOf as 5 (= 1 + 4)

Note 2:. Sizeof can not determine the size of the normal type parameter.

It looks like there is no way to access the internal / public path document If the function used by SizeOfType is the MemoryMappedViewAccessor class, then the most practical way of getting the size of those structures will be reflections like this:

  Fixed ReDonline Fanks & lt; Type type, UIT> size off = (Funk & lt; type, UIT>) Delegate. Cutlets (typef (lb; type, UIT), typef (martial) GetMethod ("SizeOfType", BindingFlags.NonPublic | BindingFlags.Static)); Write static void & lt; T1, T2> (T1 item 1, T2 ITEM2) where T1: struct using T2: struct {(MemoryMappedFile file = MemoryMappedFile.CreateNew (zero, 32)) (MemoryMappedViewAccessor Accessor = file. CreateViewAccessor ()) {Accessor. Type (0, ref item1); Accessor. Write (size of type (typef (T1)), ref item 2); }}  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -