public void CreateSpan() { ulong msize = (ulong)(ArraySize * JemUtil.SizeOfStruct <T>()); IntPtr ptr = Jem.Malloc(msize); unsafe { Span <T> s = new Span <T>(ptr.ToPointer(), ArraySize); } Jem.Free(ptr); }
public void FillSpan() { T fill = GetArrayFillValue(); ulong msize = (ulong)(ArraySize * JemUtil.SizeOfStruct <T>()); IntPtr ptr = Jem.Malloc(msize); Span <T> s = JemUtil.PtrToSpan <T>(ptr, ArraySize); s.Fill(fill); T r = s[ArraySize / 2]; Jem.Free(ptr); }
protected override void Dispose(bool disposing) { if (disposing && referenceCount > 0) { throw new InvalidOperationException($"This buffer cannot be disposed until all references are released. Reference count is {referenceCount}."); } if (ptr != null) { Jem.Free(ptr); } ptr = IntPtr.Zero; disposed = disposing; }
public void CanMallocandFree() { long size = 100 * 1000 * 1000; Assert.True(init_privateMemorySize < size); Assert.True(init_allocated < (ulong)size); IntPtr p = Jem.Malloc((ulong)size); string stats = Jem.MallocStatsPrint(); ulong allocated = Jem.GetMallCtlUInt64("stats.allocated"); CurrentProcess.Refresh(); Assert.True((CurrentProcess.PrivateMemorySize64 - init_privateMemorySize) >= size); Assert.True(allocated > (ulong)size); Jem.Free(p); }