Allocators.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using ARMeilleure.Common;
  2. using System;
  3. using System.Runtime.CompilerServices;
  4. namespace ARMeilleure
  5. {
  6. static class Allocators
  7. {
  8. [ThreadStatic] private static ArenaAllocator _default;
  9. [ThreadStatic] private static ArenaAllocator _operands;
  10. [ThreadStatic] private static ArenaAllocator _operations;
  11. [ThreadStatic] private static ArenaAllocator _references;
  12. public static ArenaAllocator Default => GetAllocator(ref _default, 256 * 1024, 4);
  13. public static ArenaAllocator Operands => GetAllocator(ref _operands, 64 * 1024, 8);
  14. public static ArenaAllocator Operations => GetAllocator(ref _operations, 64 * 1024, 8);
  15. public static ArenaAllocator References => GetAllocator(ref _references, 64 * 1024, 8);
  16. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17. private static ArenaAllocator GetAllocator(ref ArenaAllocator alloc, uint pageSize, uint pageCount)
  18. {
  19. if (alloc == null)
  20. {
  21. alloc = new ArenaAllocator(pageSize, pageCount);
  22. }
  23. return alloc;
  24. }
  25. public static void ResetAll()
  26. {
  27. Default.Reset();
  28. Operands.Reset();
  29. Operations.Reset();
  30. References.Reset();
  31. }
  32. }
  33. }