-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathArrayEntries.cs
More file actions
555 lines (489 loc) · 24.5 KB
/
ArrayEntries.cs
File metadata and controls
555 lines (489 loc) · 24.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.IO;
using UnityEngine;
using UnityEditorInternal.Profiling.Memory.Experimental;
using UnityEditorInternal.Profiling.Memory.Experimental.FileFormat;
using Unity.Collections.LowLevel.Unsafe;
namespace UnityEditor.Profiling.Memory.Experimental
{
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class ArrayEntries<T>
{
internal MemorySnapshotFileReader m_Reader;
internal EntryType m_EntryType;
GetItem<T> m_GetItemFunc;
internal ArrayEntries()
{
m_EntryType = unchecked((EntryType)0xffffffff);
}
internal ArrayEntries(MemorySnapshotFileReader reader, EntryType entryType,
GetItem<T> getItemFunc)
{
m_Reader = reader;
m_EntryType = entryType;
m_GetItemFunc = getItemFunc;
}
public uint GetNumEntries()
{
if (m_Reader == null)
return 0;
return m_Reader.GetNumEntries(m_EntryType);
}
public virtual void GetEntries(uint indexStart, uint numEntries, ref T[] dataOut)
{
if (GetNumEntries() == 0)
{
Debug.LogError("Unable to read, the array has 0 entries");
return;
}
if (m_Reader == null)
throw new Exception("No reader present for array entries");
m_Reader.GetDataArray(m_EntryType, indexStart, numEntries, ref dataOut, m_GetItemFunc);
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
internal class ByteArrayEntries : ArrayEntries<byte[]>
{
public ByteArrayEntries(MemorySnapshotFileReader reader, EntryType entryType)
: base(reader, entryType, null)
{
}
public override void GetEntries(uint indexStart, uint numEntries, ref byte[][] dataOut)
{
m_Reader.GetDataByteArray(m_EntryType, indexStart, numEntries, ref dataOut);
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class ConnectionEntries
{
public ArrayEntries<int> from { get; }
public ArrayEntries<int> to { get; }
internal ConnectionEntries(MemorySnapshotFileReader reader)
{
from = new ArrayEntries<int>(reader, EntryType.Connections_From, ConversionFunctions.ToInt32);
to = new ArrayEntries<int>(reader, EntryType.Connections_To, ConversionFunctions.ToInt32);
}
public uint GetNumEntries()
{
return from.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class GCHandleEntries
{
public ArrayEntries<ulong> target { get; }
internal GCHandleEntries(MemorySnapshotFileReader reader)
{
target = new ArrayEntries<ulong>(reader, EntryType.GCHandles_Target, ConversionFunctions.ToUInt64);
}
public uint GetNumEntries()
{
return target.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class ManagedMemorySectionEntries
{
public ArrayEntries<byte[]> bytes { get; }
public ArrayEntries<ulong> startAddress { get; }
internal ManagedMemorySectionEntries(MemorySnapshotFileReader reader, EntryType entryTypeBase, bool hasHeapTypeEncodedInAddr)
{
//all addresses store the heap type in their highest bit (ver 12+)
//only the new reader inside com.unity.memoryprofiler will read the encodings
GetItem<ulong> func;
if (hasHeapTypeEncodedInAddr)
func = ConversionFunctions.ToUInt64WithMask;
else
func = ConversionFunctions.ToUInt64;
startAddress = new ArrayEntries<ulong>(reader, (EntryType)(entryTypeBase + 0), func);
bytes = new ByteArrayEntries(reader, (EntryType)(entryTypeBase + 1));
}
public uint GetNumEntries()
{
return bytes.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeObjectEntries
{
public ArrayEntries<string> objectName { get; }
public ArrayEntries<int> instanceId { get; }
public ArrayEntries<ulong> size { get; }
public ArrayEntries<int> nativeTypeArrayIndex { get; }
public ArrayEntries<HideFlags> hideFlags { get; }
public ArrayEntries<ObjectFlags> flags { get; }
public ArrayEntries<ulong> nativeObjectAddress { get; }
public ArrayEntries<long> rootReferenceId { get; }
public ArrayEntries<int> gcHandleIndex { get; }
internal NativeObjectEntries(MemorySnapshotFileReader reader, bool hasGcHandleIndex)
{
objectName = new ArrayEntries<string>(reader, EntryType.NativeObjects_Name, ConversionFunctions.ToString);
instanceId = new ArrayEntries<int>(reader, EntryType.NativeObjects_InstanceId, ConversionFunctions.ToInt32);
size = new ArrayEntries<ulong>(reader, EntryType.NativeObjects_Size, ConversionFunctions.ToUInt64);
nativeTypeArrayIndex = new ArrayEntries<int>(reader, EntryType.NativeObjects_NativeTypeArrayIndex, ConversionFunctions.ToInt32);
hideFlags = new ArrayEntries<HideFlags>(reader, EntryType.NativeObjects_HideFlags, ConversionFunctions.ToHideFlags);
flags = new ArrayEntries<ObjectFlags>(reader, EntryType.NativeObjects_Flags, ConversionFunctions.ToObjectFlags);
nativeObjectAddress = new ArrayEntries<ulong>(reader, EntryType.NativeObjects_NativeObjectAddress, ConversionFunctions.ToUInt64);
rootReferenceId = new ArrayEntries<long>(reader, EntryType.NativeObjects_RootReferenceId, ConversionFunctions.ToInt64);
if (hasGcHandleIndex)
gcHandleIndex = new ArrayEntries<int>(reader, EntryType.NativeObjects_GCHandleIndex, ConversionFunctions.ToInt32);
else
gcHandleIndex = new ArrayEntries<int>();
}
public uint GetNumEntries()
{
return objectName.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeTypeEntries
{
public ArrayEntries<string> typeName { get; }
public ArrayEntries<int> nativeBaseTypeArrayIndex { get; }
internal NativeTypeEntries(MemorySnapshotFileReader reader)
{
typeName = new ArrayEntries<string>(reader, EntryType.NativeTypes_Name, ConversionFunctions.ToString);
nativeBaseTypeArrayIndex = new ArrayEntries<int>(reader, EntryType.NativeTypes_NativeBaseTypeArrayIndex, ConversionFunctions.ToInt32);
}
public uint GetNumEntries()
{
return typeName.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class TypeDescriptionEntries
{
public ArrayEntries<TypeFlags> flags { get; }
public ArrayEntries<string> typeDescriptionName { get; }
public ArrayEntries<string> assembly { get; }
public ArrayEntries<int[]> fieldIndices { get; }
public ArrayEntries<byte[]> staticFieldBytes { get; }
public ArrayEntries<int> baseOrElementTypeIndex { get; }
public ArrayEntries<int> size { get; }
public ArrayEntries<ulong> typeInfoAddress { get; }
public ArrayEntries<int> typeIndex { get; }
internal TypeDescriptionEntries(MemorySnapshotFileReader reader)
{
flags = new ArrayEntries<TypeFlags>(reader, EntryType.TypeDescriptions_Flags, ConversionFunctions.ToTypeFlags);
typeDescriptionName = new ArrayEntries<string>(reader, EntryType.TypeDescriptions_Name, ConversionFunctions.ToString);
assembly = new ArrayEntries<string>(reader, EntryType.TypeDescriptions_Assembly, ConversionFunctions.ToString);
fieldIndices = new ArrayEntries<int[]>(reader, EntryType.TypeDescriptions_FieldIndices, ConversionFunctions.ToInt32Array);
staticFieldBytes = new ByteArrayEntries(reader, EntryType.TypeDescriptions_StaticFieldBytes);
baseOrElementTypeIndex = new ArrayEntries<int>(reader, EntryType.TypeDescriptions_BaseOrElementTypeIndex, ConversionFunctions.ToInt32);
size = new ArrayEntries<int>(reader, EntryType.TypeDescriptions_Size, ConversionFunctions.ToInt32);
typeInfoAddress = new ArrayEntries<ulong>(reader, EntryType.TypeDescriptions_TypeInfoAddress, ConversionFunctions.ToUInt64);
typeIndex = new ArrayEntries<int>(reader, EntryType.TypeDescriptions_TypeIndex, ConversionFunctions.ToInt32);
}
public uint GetNumEntries()
{
return flags.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class FieldDescriptionEntries
{
public ArrayEntries<string> fieldDescriptionName { get; }
public ArrayEntries<int> offset { get; }
public ArrayEntries<int> typeIndex { get; }
public ArrayEntries<bool> isStatic { get; }
internal FieldDescriptionEntries(MemorySnapshotFileReader reader)
{
fieldDescriptionName = new ArrayEntries<string>(reader, EntryType.FieldDescriptions_Name, ConversionFunctions.ToString);
offset = new ArrayEntries<int>(reader, EntryType.FieldDescriptions_Offset, ConversionFunctions.ToInt32);
typeIndex = new ArrayEntries<int>(reader, EntryType.FieldDescriptions_TypeIndex, ConversionFunctions.ToInt32);
isStatic = new ArrayEntries<bool>(reader, EntryType.FieldDescriptions_IsStatic, ConversionFunctions.ToBoolean);
}
public uint GetNumEntries()
{
return fieldDescriptionName.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeMemoryLabelEntries
{
public ArrayEntries<string> memoryLabelName { get; }
internal NativeMemoryLabelEntries(MemorySnapshotFileReader reader)
{
memoryLabelName = new ArrayEntries<string>(reader, EntryType.NativeMemoryLabels_Name, ConversionFunctions.ToString);
}
public uint GetNumEntries()
{
return memoryLabelName.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeRootReferenceEntries
{
public ArrayEntries<long> id { get; }
public ArrayEntries<string> areaName { get; }
public ArrayEntries<string> objectName { get; }
public ArrayEntries<ulong> accumulatedSize { get; }
internal NativeRootReferenceEntries(MemorySnapshotFileReader reader)
{
id = new ArrayEntries<long>(reader, EntryType.NativeRootReferences_Id, ConversionFunctions.ToInt64);
areaName = new ArrayEntries<string>(reader, EntryType.NativeRootReferences_AreaName, ConversionFunctions.ToString);
objectName = new ArrayEntries<string>(reader, EntryType.NativeRootReferences_ObjectName, ConversionFunctions.ToString);
accumulatedSize = new ArrayEntries<ulong>(reader, EntryType.NativeRootReferences_AccumulatedSize, ConversionFunctions.ToUInt64);
}
public uint GetNumEntries()
{
return id.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeAllocationEntries
{
public ArrayEntries<int> memoryRegionIndex { get; }
public ArrayEntries<long> rootReferenceId { get; }
public ArrayEntries<long> allocationSiteId { get; }
public ArrayEntries<ulong> address { get; }
public ArrayEntries<ulong> size { get; }
public ArrayEntries<int> overheadSize { get; }
public ArrayEntries<int> paddingSize { get; }
internal NativeAllocationEntries(MemorySnapshotFileReader reader)
{
memoryRegionIndex = new ArrayEntries<int>(reader, EntryType.NativeAllocations_MemoryRegionIndex, ConversionFunctions.ToInt32);
rootReferenceId = new ArrayEntries<long>(reader, EntryType.NativeAllocations_RootReferenceId, ConversionFunctions.ToInt64);
allocationSiteId = new ArrayEntries<long>(reader, EntryType.NativeAllocations_AllocationSiteId, ConversionFunctions.ToInt64);
address = new ArrayEntries<ulong>(reader, EntryType.NativeAllocations_Address, ConversionFunctions.ToUInt64);
size = new ArrayEntries<ulong>(reader, EntryType.NativeAllocations_Size, ConversionFunctions.ToUInt64);
overheadSize = new ArrayEntries<int>(reader, EntryType.NativeAllocations_OverheadSize, ConversionFunctions.ToInt32);
paddingSize = new ArrayEntries<int>(reader, EntryType.NativeAllocations_PaddingSize, ConversionFunctions.ToInt32);
}
public uint GetNumEntries()
{
return memoryRegionIndex.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeMemoryRegionEntries
{
public ArrayEntries<string> memoryRegionName { get; }
public ArrayEntries<int> parentIndex { get; }
public ArrayEntries<ulong> addressBase { get; }
public ArrayEntries<ulong> addressSize { get; }
public ArrayEntries<int> firstAllocationIndex { get; }
public ArrayEntries<int> numAllocations { get; }
internal NativeMemoryRegionEntries(MemorySnapshotFileReader reader)
{
memoryRegionName = new ArrayEntries<string>(reader, EntryType.NativeMemoryRegions_Name, ConversionFunctions.ToString);
parentIndex = new ArrayEntries<int>(reader, EntryType.NativeMemoryRegions_ParentIndex, ConversionFunctions.ToInt32);
addressBase = new ArrayEntries<ulong>(reader, EntryType.NativeMemoryRegions_AddressBase, ConversionFunctions.ToUInt64);
addressSize = new ArrayEntries<ulong>(reader, EntryType.NativeMemoryRegions_AddressSize, ConversionFunctions.ToUInt64);
firstAllocationIndex = new ArrayEntries<int>(reader, EntryType.NativeMemoryRegions_FirstAllocationIndex, ConversionFunctions.ToInt32);
numAllocations = new ArrayEntries<int>(reader, EntryType.NativeMemoryRegions_NumAllocations, ConversionFunctions.ToInt32);
}
public uint GetNumEntries()
{
return memoryRegionName.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeAllocationSiteEntries
{
public ArrayEntries<long> id { get; }
public ArrayEntries<int> memoryLabelIndex { get; }
public ArrayEntries<ulong[]> callstackSymbols { get; }
internal NativeAllocationSiteEntries(MemorySnapshotFileReader reader)
{
id = new ArrayEntries<long>(reader, EntryType.NativeAllocationSites_Id, ConversionFunctions.ToInt64);
memoryLabelIndex = new ArrayEntries<int>(reader, EntryType.NativeAllocationSites_MemoryLabelIndex, ConversionFunctions.ToInt32);
callstackSymbols = new ArrayEntries<ulong[]>(reader, EntryType.NativeAllocationSites_CallstackSymbols, ConversionFunctions.ToUInt64Array);
}
public uint GetNumEntries()
{
return id.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
public class NativeCallstackSymbolEntries
{
public ArrayEntries<ulong> symbol { get; }
public ArrayEntries<string> readableStackTrace { get; }
internal NativeCallstackSymbolEntries(MemorySnapshotFileReader reader)
{
symbol = new ArrayEntries<ulong>(reader, EntryType.NativeCallstackSymbol_Symbol, ConversionFunctions.ToUInt64);
readableStackTrace = new ArrayEntries<string>(reader, EntryType.NativeCallstackSymbol_ReadableStackTrace, ConversionFunctions.ToString);
}
public uint GetNumEntries()
{
return symbol.GetNumEntries();
}
}
[Obsolete("This API is outdated and will be removed. Please check out the Memory Profiler Package (https://docs.unity3d.com/Packages/com.unity.memoryprofiler@latest/)")]
internal class ConversionFunctions
{
public static VirtualMachineInformation ToVirtualMachineInformation(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(int) * 6)
{
throw new IOException("Invalid virtual machine information data");
}
VirtualMachineInformation result = new VirtualMachineInformation();
result.pointerSize = BitConverter.ToInt32(data, sizeof(int) * 0);
result.objectHeaderSize = BitConverter.ToInt32(data, sizeof(int) * 1);
result.arrayHeaderSize = BitConverter.ToInt32(data, sizeof(int) * 2);
result.arrayBoundsOffsetInHeader = BitConverter.ToInt32(data, sizeof(int) * 3);
result.arraySizeOffsetInHeader = BitConverter.ToInt32(data, sizeof(int) * 4);
result.allocationGranularity = BitConverter.ToInt32(data, sizeof(int) * 5);
return result;
}
public static UnityEngine.HideFlags ToHideFlags(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(uint))
{
throw new IOException("Invalid data entry");
}
return (UnityEngine.HideFlags)BitConverter.ToUInt32(data, (int)startIndex);
}
public static ObjectFlags ToObjectFlags(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(uint))
{
throw new IOException("Invalid data entry");
}
return (ObjectFlags)BitConverter.ToUInt32(data, (int)startIndex);
}
public static TypeFlags ToTypeFlags(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(uint))
{
throw new IOException("Invalid data entry");
}
return (TypeFlags)BitConverter.ToUInt32(data, (int)startIndex);
}
public static short ToInt16(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(short))
{
throw new IOException("Invalid data entry");
}
return BitConverter.ToInt16(data, (int)startIndex);
}
public static int ToInt32(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(int))
{
throw new IOException("Invalid data entry");
}
return BitConverter.ToInt32(data, (int)startIndex);
}
public static long ToInt64(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(long))
{
throw new IOException("Invalid data entry");
}
return BitConverter.ToInt64(data, (int)startIndex);
}
public static ushort ToUInt16(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(ushort))
{
throw new IOException("Invalid data entry");
}
return BitConverter.ToUInt16(data, (int)startIndex);
}
public static uint ToUInt32(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(uint))
{
throw new IOException("Invalid data entry");
}
return BitConverter.ToUInt32(data, (int)startIndex);
}
public static ulong ToUInt64WithMask(byte[] data, uint startIndex, uint numBytes)
{
const ulong bitMask = ulong.MaxValue >> 1;
if (numBytes != sizeof(ulong))
{
throw new IOException("Invalid data entry");
}
ulong res = BitConverter.ToUInt64(data, (int)startIndex);
res = res & bitMask;
return res;
}
public static ulong ToUInt64(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(ulong))
{
throw new IOException("Invalid data entry");
}
return BitConverter.ToUInt64(data, (int)startIndex);
}
public static bool ToBoolean(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes != sizeof(bool))
{
throw new IOException("Invalid data entry");
}
return BitConverter.ToBoolean(data, (int)startIndex);
}
public static byte[] ToByteArray(byte[] data, uint startIndex, uint numBytes)
{
byte[] result = new byte[numBytes];
Array.Copy(data, startIndex, result, 0, numBytes);
return result;
}
public static int[] ToInt32Array(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes % sizeof(int) != 0)
{
throw new IOException("Invalid data entry");
}
uint length = numBytes / sizeof(int);
int[] result = new int[length];
for (uint i = 0; i < length; i++)
{
result[i] = ToInt32(data, startIndex + sizeof(int) * i, sizeof(int));
}
return result;
}
public static long[] ToInt64Array(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes % sizeof(long) != 0)
{
throw new IOException("Invalid data entry");
}
uint length = numBytes / sizeof(long);
long[] result = new long[length];
for (uint i = 0; i < length; i++)
{
result[i] = ToInt64(data, startIndex + sizeof(long) * i, sizeof(long));
}
return result;
}
public static ulong[] ToUInt64Array(byte[] data, uint startIndex, uint numBytes)
{
if (numBytes % sizeof(ulong) != 0)
{
throw new IOException("Invalid data entry");
}
uint length = numBytes / sizeof(ulong);
ulong[] result = new ulong[length];
for (uint i = 0; i < length; i++)
{
result[i] = ToUInt64(data, startIndex + sizeof(ulong) * i, sizeof(ulong));
}
return result;
}
public static string ToString(byte[] data, uint startIndex, uint numBytes)
{
var result = new string('A', (int)numBytes);
unsafe
{
fixed(char* resultPtr = result)
{
fixed(byte* dataPtr = data)
{
UnsafeUtility.MemCpyStride(resultPtr, UnsafeUtility.SizeOf<char>(), dataPtr + startIndex, UnsafeUtility.SizeOf<byte>(), UnsafeUtility.SizeOf<byte>(), (int)numBytes);
}
}
}
return result;
}
}
}