How to allocate 1 million bytes in an array of bytes with C#

1 Answer

0 votes
using System;
 
class Program {
    static void Main() {
        byte[] barray = null;

        long beforeallocationbytes = GC.GetTotalMemory(false);
        
        // Allocate 1 million bytes 
        barray = new byte[1000 * 1000];
        barray[0] = 0;
        
        long afterllocationbytes = GC.GetTotalMemory(false);
        
        Console.WriteLine(afterllocationbytes - beforeallocationbytes);
    }
}

 
 
/*
run:
 
1000032
 
*/

 



answered May 27, 2024 by avibootz
...