RuntimeApi.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Runtime.CompilerServices;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace HybridCLR
  10. {
  11. public static class RuntimeApi
  12. {
  13. #if UNITY_EDITOR
  14. private static int s_interpreterThreadObjectStackSize = 128 * 1024;
  15. private static int s_interpreterThreadFrameStackSize = 2 * 1024;
  16. #endif
  17. /// <summary>
  18. /// 加载补充元数据assembly
  19. /// </summary>
  20. /// <param name="dllBytes"></param>
  21. /// <returns></returns>
  22. /// <exception cref="NotSupportedException"></exception>
  23. #if UNITY_EDITOR
  24. public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode)
  25. {
  26. return LoadImageErrorCode.OK;
  27. }
  28. #else
  29. [MethodImpl(MethodImplOptions.InternalCall)]
  30. public static extern LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode);
  31. #endif
  32. /// <summary>
  33. /// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
  34. /// </summary>
  35. /// <returns></returns>
  36. #if UNITY_EDITOR
  37. public static int GetInterpreterThreadObjectStackSize()
  38. {
  39. return s_interpreterThreadObjectStackSize;
  40. }
  41. #else
  42. [MethodImpl(MethodImplOptions.InternalCall)]
  43. public static extern int GetInterpreterThreadObjectStackSize();
  44. #endif
  45. /// <summary>
  46. /// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
  47. /// </summary>
  48. /// <param name="size"></param>
  49. #if UNITY_EDITOR
  50. public static void SetInterpreterThreadObjectStackSize(int size)
  51. {
  52. s_interpreterThreadObjectStackSize = size;
  53. }
  54. #else
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. public static extern void SetInterpreterThreadObjectStackSize(int size);
  57. #endif
  58. /// <summary>
  59. /// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
  60. /// </summary>
  61. /// <returns></returns>
  62. #if UNITY_EDITOR
  63. public static int GetInterpreterThreadFrameStackSize()
  64. {
  65. return s_interpreterThreadFrameStackSize;
  66. }
  67. #else
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. public static extern int GetInterpreterThreadFrameStackSize();
  70. #endif
  71. /// <summary>
  72. /// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
  73. /// </summary>
  74. /// <param name="size"></param>
  75. #if UNITY_EDITOR
  76. public static void SetInterpreterThreadFrameStackSize(int size)
  77. {
  78. s_interpreterThreadFrameStackSize = size;
  79. }
  80. #else
  81. [MethodImpl(MethodImplOptions.InternalCall)]
  82. public static extern void SetInterpreterThreadFrameStackSize(int size);
  83. #endif
  84. }
  85. }