@@ -513,66 +513,5 @@ private static void Verify(Array input, ArrayRecord arrayRecord, Array output,
513513 }
514514 }
515515
516- #if ! NETFRAMEWORK
517- // GC.GetAllocatedBytesForCurrentThread() is not available on Full Framework.
518- [ Theory ]
519- [ InlineData ( SerializationRecordType . ArraySingleObject ) ]
520- [ InlineData ( SerializationRecordType . ArraySingleString ) ]
521- [ InlineData ( SerializationRecordType . BinaryArray ) ]
522- public void GetArray_AllowNullsFalse_DoesNotAllocateLargeArray_WhenMultipleNullRecordIsPresent ( SerializationRecordType recordType )
523- {
524- // The test needs to ensure that 2GB+ array does not get allocated.
525- // 200k is enough to get the job done and avoid getting false positives.
526- const long AllocationThreshold = 200_000 ;
527-
528- using MemoryStream stream = new ( ) ;
529- BinaryWriter writer = new ( stream , Text . Encoding . UTF8 ) ;
530-
531- WriteSerializedStreamHeader ( writer ) ;
532-
533- writer . Write ( ( byte ) recordType ) ;
534- writer . Write ( 1 ) ; // object ID
535-
536- if ( recordType is SerializationRecordType . BinaryArray )
537- {
538- writer . Write ( ( byte ) BinaryArrayType . Single ) ;
539- writer . Write ( 1 ) ; // rank
540- writer . Write ( Array . MaxLength ) ; // length
541- writer . Write ( ( byte ) 3 ) ; // BinaryType.SystemClass
542- writer . Write ( "System.Exception" ) ; // element type name
543- }
544- else
545- {
546- writer . Write ( Array . MaxLength ) ; // length
547- }
548-
549- writer . Write ( ( byte ) SerializationRecordType . ObjectNullMultiple ) ;
550- writer . Write ( Array . MaxLength ) ; // null count
551- writer . Write ( ( byte ) SerializationRecordType . MessageEnd ) ;
552-
553- stream . Position = 0 ;
554-
555- SerializationRecord serializationRecord = NrbfDecoder . Decode ( stream ) ;
556- Assert . Equal ( recordType , serializationRecord . RecordType ) ;
557-
558- long before = GC . GetAllocatedBytesForCurrentThread ( ) ;
559-
560- Assert . Throws < SerializationException > ( ( ) =>
561- {
562- if ( serializationRecord is SZArrayRecord < string > arrayOfStrings )
563- {
564- arrayOfStrings . GetArray ( allowNulls : false ) ;
565- }
566- else
567- {
568- ( ( SZArrayRecord < SerializationRecord > ) serializationRecord ) . GetArray ( allowNulls : false ) ;
569- }
570- } ) ;
571-
572- long after = GC . GetAllocatedBytesForCurrentThread ( ) ;
573-
574- Assert . InRange ( after , before , before + AllocationThreshold ) ;
575- }
576- #endif
577516 }
578517}
0 commit comments