-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasm): Add MemoryManager support
- Loading branch information
1 parent
aa3e6e9
commit 66038f1
Showing
5 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Windows.System { | ||
|
||
export class MemoryManager { | ||
|
||
static getAppMemoryUsage() { | ||
if (typeof Module === "object") { | ||
|
||
// Returns an approximate memory usage for the current wasm module. | ||
// Initial buffer size is determine by the initial wasm memory defined in | ||
// emscripten. | ||
return (<any>Module).HEAPU8.length; | ||
} | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Globalization; | ||
using Uno.Foundation; | ||
|
||
namespace Windows.System | ||
{ | ||
public partial class MemoryManager | ||
{ | ||
private const string JsType = "Windows.System.MemoryManager"; | ||
|
||
public static ulong AppMemoryUsage | ||
{ | ||
get | ||
{ | ||
if(ulong.TryParse(WebAssemblyRuntime.InvokeJS( | ||
$"{JsType}.getAppMemoryUsage()"), | ||
NumberStyles.Any, | ||
CultureInfo.InvariantCulture, out var value)) | ||
{ | ||
return value; | ||
} | ||
|
||
throw new Exception($"getAppMemoryUsage returned an unsupported value"); | ||
} | ||
} | ||
|
||
public static ulong AppMemoryUsageLimit | ||
{ | ||
get | ||
{ | ||
if (Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_EMSCRIPTEN_MAXIMUM_MEMORY") == "4GB") | ||
{ | ||
return 4ul * 1024 * 1024 * 1024; | ||
} | ||
|
||
return 2ul * 1024 * 1024 * 1024; | ||
} | ||
} | ||
} | ||
} |