@@ -38,7 +38,7 @@ public ref struct SpanOwner<T>
3838 /// </remarks>
3939 [ EditorBrowsable ( EditorBrowsableState . Never ) ]
4040 [ CLSCompliant ( false ) ]
41- public static int StackallocThreshold { get ; } = 1 + ( LibrarySettings . StackallocThreshold / Unsafe . SizeOf < T > ( ) ) ;
41+ public static int StackallocThreshold { get ; } = 1 + Features . StackallocThreshold / Unsafe . SizeOf < T > ( ) ;
4242
4343 private readonly object ? owner ;
4444 private readonly Span < T > memory ;
@@ -137,7 +137,7 @@ static unsafe Span<T> Allocate(int length)
137137 private static bool IsNaturalAlignment => Intrinsics . AlignOf < T > ( ) <= nuint . Size ;
138138
139139 private static bool UseNativeAllocation
140- => LibrarySettings . UseNativeAllocation && ! RuntimeHelpers . IsReferenceOrContainsReferences < T > ( ) ;
140+ => Features . UseNativeAllocation && ! RuntimeHelpers . IsReferenceOrContainsReferences < T > ( ) ;
141141
142142 /// <summary>
143143 /// Gets the rented memory.
@@ -216,4 +216,31 @@ public void Dispose()
216216
217217 this = default ;
218218 }
219+ }
220+
221+ file static class Features
222+ {
223+ private const string UseNativeAllocationFeature = "DotNext.Buffers.NativeAllocation" ;
224+
225+ // TODO: [FeatureSwitchDefinition(EnableNativeAllocationFeature)]
226+ internal static bool UseNativeAllocation
227+ => LibraryFeature . IsSupported ( UseNativeAllocationFeature ) ;
228+
229+ internal static int StackallocThreshold
230+ {
231+ get
232+ {
233+ const string environmentVariableName = "DOTNEXT_STACK_ALLOC_THRESHOLD" ;
234+ const string configurationParameterName = "DotNext.Buffers.StackAllocThreshold" ;
235+ const int defaultValue = 511 ;
236+ const int minimumValue = 14 ;
237+
238+ if ( AppContext . GetData ( configurationParameterName ) is not int result )
239+ {
240+ int . TryParse ( Environment . GetEnvironmentVariable ( environmentVariableName ) , out result ) ;
241+ }
242+
243+ return result > minimumValue ? result : defaultValue ;
244+ }
245+ }
219246}
0 commit comments