private static ReadOnlyMemoryContent CreateContent(int contentLength, bool useArray, out Memory <byte> memory, out MemoryManager <byte> ownedMemory)
        {
            if (useArray)
            {
                memory      = new byte[contentLength];
                ownedMemory = null;
            }
            else
            {
                ownedMemory = new NativeMemoryManager(contentLength);
                memory      = ownedMemory.Memory;
            }

            new Random(contentLength).NextBytes(memory.Span);

            return(new ReadOnlyMemoryContent(memory));
        }
Example #2
0
        public async Task NonEmptyWriteAsync_CustomMemoryManager_WritesExpectedData()
        {
            using (var mem = new NativeMemoryManager(TestBuffer.Length))
                using (var fs = CreateFileStream(GetTestFilePath(), FileMode.Create))
                {
                    new Memory <byte>(TestBuffer).CopyTo(mem.Memory);

                    await fs.WriteAsync(mem.Memory);

                    Assert.Equal(TestBuffer.Length, fs.Length);
                    Assert.Equal(TestBuffer.Length, fs.Position);

                    fs.Position = 0;
                    var buffer = new byte[TestBuffer.Length];
                    Assert.Equal(TestBuffer.Length, await fs.ReadAsync(new Memory <byte>(buffer)));
                    Assert.Equal(TestBuffer, buffer);
                }
        }
Example #3
0
            public override void OnUpdate()
            {
                PageControl.Controls["NetMemory"].Text = GC.GetTotalMemory(false).ToString("N0");

                int totalAllocatedMemory = 0;
                int totalAllocationCount = 0;

                for (int n = 0; n < (int)NativeMemoryAllocationType.Count; n++)
                {
                    NativeMemoryAllocationType allocationType = (NativeMemoryAllocationType)n;

                    int allocatedMemory;
                    int allocationCount;
                    NativeMemoryManager.GetStatistics(allocationType, out allocatedMemory,
                                                      out allocationCount);

                    string typeString = allocationType.ToString();

                    PageControl.Controls[typeString + "Allocations"].Text =
                        allocationCount.ToString("N0");
                    PageControl.Controls[typeString + "Memory"].Text =
                        allocatedMemory.ToString("N0");

                    totalAllocatedMemory += allocatedMemory;
                    totalAllocationCount += allocationCount;
                }

                PageControl.Controls["TotalAllocations"].Text = totalAllocationCount.ToString("N0");
                PageControl.Controls["TotalMemory"].Text      = totalAllocatedMemory.ToString("N0");

                int crtAllocatedMemory;
                int crtAllocationCount;

                NativeMemoryManager.GetCRTStatistics(out crtAllocatedMemory, out crtAllocationCount);

                PageControl.Controls["CRTAllocations"].Text = crtAllocationCount.ToString("N0");
                PageControl.Controls["CRTMemory"].Text      = crtAllocatedMemory.ToString("N0");
            }
Example #4
0
 private void OnLogNativeMemoryStatistics(string arguments)
 {
     NativeMemoryManager.LogAllocationStatistics();
     Print("Done. See log file in UserSettings\\Logs folder.");
 }
Example #5
0
 void OnLogNativeMemoryStatistics(string arguments)
 {
     NativeMemoryManager.LogAllocationStatistics();
     Print("Done. See log file.");
 }