private void Sync() { if (m_dirty) { // Console.WriteLine("Calling sync"); if (!Mapper.IsAllocated(m_array)) { throw new InvalidOperationException("Array cannot be dirty and not allocated"); } Mapper.Sync(m_array); PinnedArrayTracker.Release(); m_dirty = false; } }
public void Allocate() { if (Mapper.IsAllocated(m_array)) { if (m_data == null) { //Console.WriteLine("Copy data from C land"); //In this case, data resides in C land, // so we copy it back to CIL and free it in C land m_data = new TData[m_size]; using (var t = NewFromEmpty((ulong)m_size)) { Mapper.SetData(t, PinnedArrayTracker.CreatePinnedArray(m_data)); Mapper.Copy(t, m_array); Mapper.Sync(t); m_array.Dispose(); PinnedArrayTracker.Release(); } m_dirty = false; } else { //Data resides in CIL so detach the data and release the array //Console.WriteLine("Release data in C land"); Sync(); Mapper.SetData(m_array, IntPtr.Zero); m_array.Dispose(); } } else { //Console.WriteLine("Accessed array that was never in any operation"); Sync(); if (m_data == null) { m_data = new TData[m_size]; } } }