Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

54 wiersze
1.3 KiB

  1. // <copyright file="AllocatedMemory.cs" company="Nick Lowe">
  2. // Copyright © Nick Lowe 2009
  3. // </copyright>
  4. // <author>Nick Lowe</author>
  5. // <email>nick@int-r.net</email>
  6. // <url>http://processprivileges.codeplex.com/</url>
  7. namespace ProcessPrivileges
  8. {
  9. using System;
  10. using System.Diagnostics.CodeAnalysis;
  11. using System.Runtime.InteropServices;
  12. internal sealed class AllocatedMemory : IDisposable
  13. {
  14. [SuppressMessage("Microsoft.Reliability",
  15. "CA2006:UseSafeHandleToEncapsulateNativeResources",
  16. Justification = "Not pointing to a native resource.")]
  17. private IntPtr pointer;
  18. internal AllocatedMemory(int bytesRequired)
  19. {
  20. this.pointer = Marshal.AllocHGlobal(bytesRequired);
  21. }
  22. ~AllocatedMemory()
  23. {
  24. this.InternalDispose();
  25. }
  26. internal IntPtr Pointer
  27. {
  28. get
  29. {
  30. return this.pointer;
  31. }
  32. }
  33. public void Dispose()
  34. {
  35. this.InternalDispose();
  36. GC.SuppressFinalize(this);
  37. }
  38. private void InternalDispose()
  39. {
  40. if (this.pointer != IntPtr.Zero)
  41. {
  42. Marshal.FreeHGlobal(this.pointer);
  43. this.pointer = IntPtr.Zero;
  44. }
  45. }
  46. }
  47. }