|
???iOS????????????????????????Devlin?????????????????????
????
????????????????????????????iOS????????????????XCode???????UnityInternalProfile?????Mono????????
??????
??XCode????????UnityInternalProfile???????XCode??????????????????????????????????????????????????????????????
????UnityInternalProfile???????mach_base_task_info??resident_size?????????
?????????????????????????????xcode??????resident_size?
??????????????
resident_size??????????????????????????????????????????MacOS????????????????iOS??task_vm_info ???????????compress???
????compress????????????!
??????????????resident_size????????????compress???????
????
????????????? = resident + compress???????iOS??????????????
?????????????????????????????????????memorywarning??????60%???Q?App?
????
?????????task_vm_info??resident ? compress ?????App?????????????Unity??????????Native?C#??,?????????????????
?XCodePostProcess::OnPostProcessBuild()??????????Unity???XCode????????Native???
XClass AppRender = new XClass(pathToBuiltProject + "/Classes/UnityAppController+Rendering.mm");
if( AppRender != null)
{
string TCode = "";
TCode += "#include <mach/mach_time.h>\n";
TCode += "#include <mach/mach.h>\n";
TCode += "#include <mach/mach_host.h>\n";
TCode += "#include <mach/task_info.h>\n";
TCode += "#include <mach/task.h>\n";
TCode += "static float GetTotalPhysicsMemory( )\n";
TCode += "{\n";
TCode += " kern_return_t kr;\n";
TCode += " mach_msg_type_number_t info_count = TASK_VM_INFO_COUNT;\n";
TCode += " task_vm_info_data_t vm_info;\n";
TCode += " kr = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)&vm_info, &info_count);\n";
TCode += " if (kr == KERN_SUCCESS) return (float)(vm_info.compressed + vm_info.resident_size) / 1024.0 / 1024.0;\n";
TCode += " return 0;\n";
TCode += "}\n";
TCode += "extern \"C\" float _Get_Profiler_TotalPhysicMemory(){return _fLockStepPhysicMemory;}\n";
TCode += "extern \"C\" void UnityRepaint()";
AppRender.Replace("extern \"C\" void UnityRepaint()",TCode );
}
?UnityC#???????????? Get_Profiler_TotalPhysicMemory??????????????
#if ( UNITY_IPHONE && !UNITY_EDITOR )
[DllImport("__Internal")]
static extern float _Get_Profiler_TotalPhysicMemory( );
public static float Get_Profiler_TotalPhysicMemory( )
{
return _Get_Profiler_TotalPhysicMemory( );
}
#endif
????
????????????????1???????????????????16k????????????????????????????????XCode??????????????????????????
???????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????
https://gwb.tencent.com/cn/tutor
?/ Devlin
?????GWB????
???https://mp.weixin.qq.com/s/s4tXl7KnjrDSnftbQSeiDg
|
|