unity3d 获取使用内存大小 android and ios
来源:互联网 发布:什么手机支持双频网络 编辑:程序博客网 时间:2024/05/16 15:44
获取的是应用在移动设备上面的实时允许是的进程使用内存大小和你直接在移动设备上查看进程的内存使用一模一样,绝对精确,废话不说上代码,你懂的
C#
public static int GetUseMemory() { int memory = -1;#if UNITY_ANDROID try { AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); AndroidJavaClass unityPluginLoader = new AndroidJavaClass("java类全名"); float tempMemory = unityPluginLoader.CallStatic<float>("GetMemory", currentActivity); memory = (int)tempMemory; } catch (System.Exception e) { ILog.Info("com.moba.unityplugin.AndroidUtile GetMemory: " + e.Message); }#elif UNITY_IOS memory = (int)_IOS_GetTaskUsedMemeory();#endif return memory; }
android
public static float GetMemory(Activity currentActivity) { float memory = -1; try { int pid = android.os.Process.myPid(); ActivityManager mActivityManager = (ActivityManager) currentActivity .getSystemService(Context.ACTIVITY_SERVICE); Debug.MemoryInfo[] memoryInfoArray = mActivityManager.getProcessMemoryInfo(new int[] { pid }); memory = (float) memoryInfoArray[0].getTotalPrivateDirty() / 1024; } catch (Exception e) { if (Utile.isDebug()) Utile.LogError(e.toString()); } return memory; }
ios
long _IOS_GetTaskUsedMemeory() { task_basic_info_data_t taskInfo; mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT; kern_return_t kernReturn = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount); if (kernReturn == KERN_SUCCESS) { long usedMemory = taskInfo.resident_size/1024.0/1024.0; return usedMemory; } return 0; }
阅读全文
0 0
- unity3d 获取使用内存大小 android and ios
- unity3d 获取剩余空间大小 android and ios
- unity3d 获取电量电池状态等 android and ios
- IOS代码获取内存大小
- android 获取手机内存大小
- Android 获取可用内存大小
- Android 如何获取App内存大小
- iOS小demo之获取内存大小
- android 获取机身内存、sdcard内存大小
- Android获取应用所占内存大小
- Android学习文档之获取内存大小
- 获取内存大小
- Unity3d Line 分享接入代码 android and ios
- Unity3d whatsapp 分享接入代码 android and ios
- unity3d 判断是否安装指定app android and ios
- unity3d 判断url是否正常 android and ios
- Android Studio修改虚拟机使用的内存大小
- android 获取Bitmap位图所占用的内存大小
- 高可用架构-- MySQL主从复制的配置
- servlet+ajax搜索智能提示demo(原生js)
- DeepLearning——感知器
- 11月份 chrome 标签整理
- CMRR在测量差分小信号时的重要性——输出误差分析
- unity3d 获取使用内存大小 android and ios
- 聚合支付”为什么很多游戏商家选择他
- KEIL5,STM32工程建立注意事项
- Wake Your Computer Up From Local Network
- Tomcat 部署项目的三种方法
- RESNET学习笔记(二)
- okhttp封装类
- 数据可视化D3-简单说
- 漫谈 Clustering (5): Hierarchical Clustering