Allocators.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. [ThreadStatic] private static ArenaAllocator _liveRanges;
  13. [ThreadStatic] private static ArenaAllocator _liveIntervals;
  14. public static ArenaAllocator Default => GetAllocator(ref _default, 256 * 1024, 4);
  15. public static ArenaAllocator Operands => GetAllocator(ref _operands, 64 * 1024, 8);
  16. public static ArenaAllocator Operations => GetAllocator(ref _operations, 64 * 1024, 8);
  17. public static ArenaAllocator References => GetAllocator(ref _references, 64 * 1024, 8);
  18. public static ArenaAllocator LiveRanges => GetAllocator(ref _liveRanges, 64 * 1024, 8);
  19. public static ArenaAllocator LiveIntervals => GetAllocator(ref _liveIntervals, 64 * 1024, 8);
  20. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  21. private static ArenaAllocator GetAllocator(ref ArenaAllocator alloc, uint pageSize, uint pageCount)
  22. {
  23. if (alloc == null)
  24. {
  25. alloc = new ArenaAllocator(pageSize, pageCount);
  26. }
  27. return alloc;
  28. }
  29. public static void ResetAll()
  30. {
  31. Default.Reset();
  32. Operands.Reset();
  33. Operations.Reset();
  34. References.Reset();
  35. }
  36. }
  37. }