/// <summary> /// The writer uses unmanaged memory for its data buffer. Dispose /// needs to be called to free this resource. /// </summary> public void Dispose() { #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel); #endif UnsafeUtility.Free(m_Data->buffer, m_Allocator); UnsafeUtility.Free(m_Data, m_Allocator); m_Data = (StreamData *)0; }
public DataStreamWriter(int length, Allocator allocator) { m_Allocator = allocator; m_Data = (StreamData *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <StreamData>(), UnsafeUtility.AlignOf <StreamData>(), m_Allocator); m_Data->capacity = length; m_Data->length = 0; m_Data->buffer = (byte *)UnsafeUtility.Malloc(length, UnsafeUtility.AlignOf <byte>(), m_Allocator); #if ENABLE_UNITY_COLLECTIONS_CHECKS #if UNITY_2018_3_OR_NEWER DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 1, m_Allocator); #else DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 1); #endif #endif }
public DataStreamWriter(int capacity, Allocator allocator) { m_Allocator = allocator; m_Data = (StreamData *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <StreamData>(), UnsafeUtility.AlignOf <StreamData>(), m_Allocator); m_Data->capacity = capacity; m_Data->length = 0; m_Data->buffer = (byte *)UnsafeUtility.Malloc(capacity, UnsafeUtility.AlignOf <byte>(), m_Allocator); m_Data->bitBuffer = 0; m_Data->bitIndex = 0; #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 1, m_Allocator); #endif uint test = 1; unsafe { byte *test_b = (byte *)&test; IsLittleEndian = test_b[0] == 1; } }