MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / StructureToByteArray

Method StructureToByteArray

Source/Editor/Utilities/Utils.cs:525–535  ·  view source on GitHub ↗

Converts the structure to the raw bytes. Supported only for structures with simple types and no GC objects. The structure type. The structure value. The bytes array that contains a structure data.

(ref T value)

Source from the content-addressed store, hash-verified

523 /// <param name="value">The structure value.</param>
524 /// <returns>The bytes array that contains a structure data.</returns>
525 public static byte[] StructureToByteArray<T>(ref T value) where T : struct
526 {
527 // #stupid c#
528 int size = Marshal.SizeOf(typeof(T));
529 byte[] arr = new byte[size];
530 IntPtr ptr = Marshal.AllocHGlobal(size);
531 Marshal.StructureToPtr(value, ptr, true);
532 Marshal.Copy(ptr, arr, 0, size);
533 Marshal.FreeHGlobal(ptr);
534 return arr;
535 }
536
537 /// <summary>
538 /// Converts the structure to the raw bytes. Supported only for structures with simple types and no GC objects.

Callers 3

SaveMethod · 0.80
SaveTrackMethod · 0.80
SaveTrackMethod · 0.80

Calls 4

MemoryCopyMethod · 0.80
CopyMethod · 0.45
GetTypeMethod · 0.45
GetPointerMethod · 0.45

Tested by

no test coverage detected