Add MemoryUtil for Apple external.

This commit is contained in:
MAJigsaw77
2025-09-08 13:02:48 -04:00
committed by Eric
parent f3ff132e90
commit 7d714ecfeb
7 changed files with 48 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
package funkin.external.apple;
#if (ios || macos)
#if ((ios || macos) && cpp)
/**
* A utility class to manage the audio session on apple devices.
*/
+20
View File
@@ -0,0 +1,20 @@
package funkin.external.apple;
#if ((ios || macos) && cpp)
/**
* A utility class to get information about the mem usage.
*/
@:build(funkin.util.macro.LinkerMacro.xml('project/Build.xml'))
@:include('MemoryUtil.hpp')
@:unreflective
extern class MemoryUtil
{
/**
* Retrieves the current process's resident set size (RSS) in bytes on Apple platforms.
*
* @return The resident set size (RSS) in bytes if successful; otherwise, returns 0 on failure.
*/
@:native('Apple_MemoryUtil_GetCurrentProcessRss')
static function getCurrentProcessRss():cpp.SizeT;
}
#end
+1 -1
View File
@@ -1,6 +1,6 @@
package funkin.external.apple;
#if (ios || macos)
#if ((ios || macos) && cpp)
/**
* A utility class to get screen related informations on apple devices.
*/
+2 -1
View File
@@ -13,8 +13,9 @@
<files id="external-apple">
<compilerflag value="-I${this_dir}/include" />
<file name="${this_dir}/src/ScreenUtil.mm" />
<file name="${this_dir}/src/AudioSession.mm" />
<file name="${this_dir}/src/MemoryUtil.mm" />
<file name="${this_dir}/src/ScreenUtil.mm" />
</files>
<target id="haxe">
@@ -0,0 +1,8 @@
#pragma once
/**
* Retrieves the current process's resident set size (RSS) in bytes on Apple platforms.
*
* @return The resident set size (RSS) in bytes if successful; otherwise, returns 0 on failure.
*/
size_t Apple_MemoryUtil_GetCurrentProcessRss();
+13
View File
@@ -0,0 +1,13 @@
#import "MemoryUtil.hpp"
#include <mach/mach.h>
size_t Apple_MemoryUtil_GetCurrentProcessRss()
{
task_basic_info info;
if (task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &TASK_BASIC_INFO_COUNT) != KERN_SUCCESS)
return 0;
return info.resident_size;
}
+3 -1
View File
@@ -47,7 +47,7 @@ class MemoryUtil
public static function supportsTaskMem():Bool
{
#if ((windows && cpp) || linux || android)
#if ((cpp && (windows || ios || macos)) || linux || android)
return true;
#else
return false;
@@ -58,6 +58,8 @@ class MemoryUtil
{
#if (windows && cpp)
return funkin.external.windows.WinAPI.getProcessMemoryWorkingSetSize();
#elseif ((ios || macos) && cpp)
return funkin.external.apple.MemoryUtil.getCurrentProcessRss();
#elseif (linux || android)
try
{