Beispiel #1
0
 public RawDataResource(ResourceVolatility volatility, int size)
     : base(volatility)
 {
     Size           = size;
     permanentArray = new UnmanagedArray(size);
     getStream      = () => new UnmanagedMemoryStream((byte *)permanentArray.Data, size);
 }
Beispiel #2
0
 private static void CheckEmptyArray(IUnmanagedArray <int> array)
 {
     Equal(0, array.Length);
     Equal(Array.Empty <int>(), array);
     Equal(Array.Empty <int>(), array.ToArray());
     Equal(Stream.Null, array.AsStream());
     True(array.BitwiseEquals(Array.Empty <int>()));
     Equal(0, array.BitwiseCompare(Array.Empty <int>()));
     Empty(array);
     True(array.Pointer.IsNull);
     array = (IUnmanagedArray <int>)array.Clone();
     Equal(0, array.Length);
     Equal(Array.Empty <int>(), array);
     Equal(Array.Empty <int>(), array.ToArray());
     Equal(Stream.Null, array.AsStream());
 }
Beispiel #3
0
        public IntPtr Map()
        {
            if (permanentArray != null)
            {
                return(permanentArray.Data);
            }
            Interlocked.Increment(ref mapCount);
            if (temporaryArray != null)
            {
                return(temporaryArray.Data);
            }
            temporaryArray = new UnmanagedArray(Size);
            var readStream = new UnmanagedMemoryStream((byte *)temporaryArray.Data, Size);

            using (var writeStream = getStream())
                writeStream.CopyTo(readStream);
            return(temporaryArray.Data);
        }
Beispiel #4
0
 public void Unmap(bool wasModified)
 {
     if (permanentArray != null)
     {
         if (wasModified)
         {
             OnModified(null);
         }
         return;
     }
     if (wasModified)
     {
         throw new InvalidOperationException("Was trying to modify a stream-based RawDataResource");
     }
     Interlocked.Decrement(ref mapCount);
     if (mapCount != 0)
     {
         return;
     }
     temporaryArray?.Dispose();
     temporaryArray = null;
 }