ashmind / SharpLab

.NET language playground
https://sharplab.io
BSD 2-Clause "Simplified" License
2.72k stars 199 forks source link

MemoryGuardException in .NET Framework mode is too restrictive #896

Open am11 opened 2 years ago

am11 commented 2 years ago
// var x = new int[100]; // works fine
var x = new int[101];
System.Console.WriteLine(x.Length);

This code throws:

Unbreakable.Runtime.MemoryGuardException: Total allocation limit reached (collections and strings).

in .NET Framework (x86 / x64) mode. Can this limit be relaxed, as done for NETCoreApp?

ashmind commented 2 years ago

Thanks for reporting! What is the specific case that requires array to have more than 100 elements in SharpLab context? At the moment .NET Core uses a different Run architecture -- rewriting .NET Framework to the same would take some effort.

am11 commented 2 years ago

Agreed; rewriting implementation for .NET Framework is not worth the effort. I was trying to test a lookup table (256 items) -based implementation in 32-bit mode. I've just realized that Default option in the dropdown menu refers to CoreCLR x86 and x64 refers toCoreCLR amd64. Would it make sense to reword the captions in dropdown menu? something like:

Current (where Default is x86):

Default
x64
.NET Framework x64
.NET Framework x86

Proposed (no ambiguous default option, use .NET 6 x64 option as default, unless there is a previous selection read from cookie / localStorage?):

.NET 6 x64
.NET 6 x86
.NET Framework x64
.NET Framework x86
ashmind commented 2 years ago

It's even a bit more complicated than this, since the new mode of Run in .NET 6 does not necessarily run in the same bitness as you have selected. I'll need to overhaul the whole model I think.

Ideal would be to have Run (x86)/Run (x64) and same for JIT Asm.

fowl2 commented 4 months ago

An example of something simple that currently runs into the limit on .NET Framework:

var o = new { a = 0, b = 0 };
Inspect.MemoryGraph(new { x = o, y = o });