protected internal virtual Allocator <T> SuggestAllocator <T>(ArenaOptions options) => null; // use defaults /// <summary> /// Suggest an allocator for a blittable type /// </summary> protected internal virtual Allocator <T> SuggestBlittableAllocator <T>(ArenaOptions options) where T : unmanaged { // if the user prefers unmanaged: we don't need to do anything - the arena will already select this if (options.HasFlag(ArenaFlags.PreferUnmanaged)) { return(null); } // if we're talking about bytes, then we *might* want to switch to a pinned allocator if // the user hasn't disabled padded blittables if (typeof(T) == typeof(byte) && options.HasFlag(ArenaFlags.BlittablePaddedSharing)) { return(PinnedArrayPoolAllocator <T> .Shared); } // and if the user hasn't disabled same-size shared blittables, again we should prefer pinned if (options.HasFlag(ArenaFlags.BlittableNonPaddedSharing)) { return(PinnedArrayPoolAllocator <T> .Shared); } return(null); }
/// <summary> /// Create a new Arena instance /// </summary> public Arena(ArenaOptions options = null, AllocatorFactory factory = null) { Options = options ?? ArenaOptions.Default; Factory = factory ?? AllocatorFactory.Default; }
/// <summary> /// Suggest an allocator for any type /// </summary> protected internal virtual Allocator <T> SuggestAllocator <T>(ArenaOptions options) => null; // use defaults
/// <summary> /// Suggest a per-type block size (in bytes) to use for allocations /// </summary> protected internal virtual int SuggestBlockSizeBytes <T>(ArenaOptions options) => options?.BlockSizeBytes ?? 0;