-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAllocatedMemory.cs
More file actions
54 lines (47 loc) · 1.32 KB
/
AllocatedMemory.cs
File metadata and controls
54 lines (47 loc) · 1.32 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// <copyright file="AllocatedMemory.cs" company="Nick Lowe">
// Copyright © Nick Lowe 2009
// </copyright>
// <author>Nick Lowe</author>
// <email>nick@int-r.net</email>
// <url>http://processprivileges.codeplex.com/</url>
namespace ProcessPrivileges
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
internal sealed class AllocatedMemory : IDisposable
{
[SuppressMessage("Microsoft.Reliability",
"CA2006:UseSafeHandleToEncapsulateNativeResources",
Justification = "Not pointing to a native resource.")]
private IntPtr pointer;
internal AllocatedMemory(int bytesRequired)
{
this.pointer = Marshal.AllocHGlobal(bytesRequired);
}
~AllocatedMemory()
{
this.InternalDispose();
}
internal IntPtr Pointer
{
get
{
return this.pointer;
}
}
public void Dispose()
{
this.InternalDispose();
GC.SuppressFinalize(this);
}
private void InternalDispose()
{
if (this.pointer != IntPtr.Zero)
{
Marshal.FreeHGlobal(this.pointer);
this.pointer = IntPtr.Zero;
}
}
}
}