File tree Expand file tree Collapse file tree 6 files changed +24
-13
lines changed
src/Microsoft.Data.Analysis
test/Microsoft.Data.Analysis.Tests Expand file tree Collapse file tree 6 files changed +24
-13
lines changed Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+ // See the LICENSE file in the project root for more information.
4+
5+ using System ;
6+ using System . Collections . Generic ;
7+ using System . Text ;
8+
9+ namespace Microsoft . Data . Analysis
10+ {
11+ internal static class ArrayUtility
12+ {
13+ // Maximum size of one-dimensional array.
14+ // See: https://msdn.microsoft.com/en-us/library/hh285054(v=vs.110).aspx
15+ // Polyfilling Array.MaxLength API for netstandard2.0
16+ public const int ArrayMaxSize = 0X7FEFFFFF ;
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ public void EnsureCapacity(int numberOfValues)
8080 if ( newLength > Capacity )
8181 {
8282 //Double buffer size, but not higher than MaxByteCapacity
83- var doubledSize = ( int ) Math . Min ( ( long ) ReadOnlyBuffer . Length * 2 , MaxCapacityInBytes ) ;
83+ var doubledSize = ( int ) Math . Min ( ( long ) ReadOnlyBuffer . Length * 2 , ArrayUtility . ArrayMaxSize ) ;
8484 var newCapacity = Math . Max ( newLength * Size , doubledSize ) ;
8585
8686 var memory = new Memory < byte > ( new byte [ newCapacity ] ) ;
Original file line number Diff line number Diff line change @@ -36,11 +36,7 @@ public ReadOnlyMemory<T> RawReadOnlyMemory
3636
3737 protected int Capacity => ReadOnlyBuffer . Length / Size ;
3838
39- //The maximum size in any single dimension for byte array is 0x7FFFFFc7 - 2147483591
40- //See https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element
41- public const int MaxCapacityInBytes = 2147483591 ;
42-
43- public static int MaxCapacity => MaxCapacityInBytes / Size ;
39+ public static int MaxCapacity => ArrayUtility . ArrayMaxSize / Size ;
4440
4541 public ReadOnlySpan < T > ReadOnlySpan
4642 {
Original file line number Diff line number Diff line change @@ -18,9 +18,7 @@ namespace Microsoft.Data.Analysis
1818 /// <remarks> Is NOT Arrow compatible </remarks>
1919 public partial class StringDataFrameColumn : DataFrameColumn , IEnumerable < string >
2020 {
21- //The maximum size in any single dimension for array containing other types than byte or single byte structure is 0X7FEFFFFF - 2146435071
22- //See https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element
23- public static int MaxCapacity = 2146435071 / Unsafe . SizeOf < IntPtr > ( ) ; // Size of pointer
21+ public static int MaxCapacity = ArrayUtility . ArrayMaxSize / Unsafe . SizeOf < IntPtr > ( ) ; // Max Size in bytes / size of pointer (8 bytes on x64)
2422
2523 private readonly List < List < string > > _stringBuffers = new List < List < string > > ( ) ; // To store more than intMax number of strings
2624
Original file line number Diff line number Diff line change @@ -18,9 +18,8 @@ namespace Microsoft.Data.Analysis
1818 /// </summary>
1919 public partial class VBufferDataFrameColumn < T > : DataFrameColumn , IEnumerable < VBuffer < T > >
2020 {
21- //The maximum size in any single dimension for array containing other types than byte or single byte structure is 0X7FEFFFFF - 2146435071
22- //See https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element
23- public static int MaxCapacity = 2146435071 / Unsafe . SizeOf < VBuffer < T > > ( ) ;
21+
22+ public static int MaxCapacity = ArrayUtility . ArrayMaxSize / Unsafe . SizeOf < VBuffer < T > > ( ) ;
2423
2524 private readonly List < List < VBuffer < T > > > _vBuffers = new List < List < VBuffer < T > > > ( ) ; // To store more than intMax number of vbuffers
2625
Original file line number Diff line number Diff line change @@ -457,7 +457,7 @@ public void TestAppend_SizeMoreThanMaxBufferCapacity()
457457 [ X64Fact ( "32-bit dosn't allow to allocate more than 2 Gb" ) ]
458458 public void TestAppendMany_SizeMoreThanMaxBufferCapacity ( )
459459 {
460- const int MaxCapacityInBytes = 2147483591 ;
460+ const int MaxCapacityInBytes = 0X7FEFFFFF ;
461461
462462 //Check appending values with extending column size over MaxCapacity of ReadOnlyDataFrameBuffer
463463 PrimitiveDataFrameColumn < byte > intColumn = new PrimitiveDataFrameColumn < byte > ( "Byte1" , MaxCapacityInBytes - 5 ) ;
You can’t perform that action at this time.
0 commit comments