-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathIntroLargeAddressAware.cs
More file actions
40 lines (38 loc) · 1.13 KB
/
IntroLargeAddressAware.cs
File metadata and controls
40 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
namespace BenchmarkDotNet.Samples
{
[MemoryDiagnoser]
[Config(typeof(Config))]
[UseLocalJobOnly]
public class IntroLargeAddressAware
{
private class Config : ManualConfig
{
public Config()
{
AddJob(Job.Default
.WithRuntime(ClrRuntime.Net462)
.WithPlatform(Platform.X86)
.WithLargeAddressAware(value: RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
.WithId("Framework"));
}
}
[Benchmark]
public void AllocateMoreThan2GB()
{
const int oneGB = 1024 * 1024 * 1024;
const int halfGB = oneGB / 2;
byte[] bytes1 = new byte[oneGB];
byte[] bytes2 = new byte[oneGB];
byte[] bytes3 = new byte[halfGB];
GC.KeepAlive(bytes1);
GC.KeepAlive(bytes2);
GC.KeepAlive(bytes3);
}
}
}