mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
7bd28e4357
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2304 21ef857c-d57f-4fe0-8362-d861dc6d29cd
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using System;
|
|
using ProcessHacker.Native.Api;
|
|
|
|
namespace ProcessHacker.Native
|
|
{
|
|
/// <summary>
|
|
/// Represents a LocalAlloc() memory allocation.
|
|
/// </summary>
|
|
public sealed class LocalMemoryAlloc : MemoryAlloc
|
|
{
|
|
public LocalMemoryAlloc(IntPtr memory)
|
|
: this(memory, true)
|
|
{ }
|
|
|
|
public LocalMemoryAlloc(IntPtr memory, bool owned)
|
|
: base(memory, owned)
|
|
{ }
|
|
|
|
public LocalMemoryAlloc(int size)
|
|
: this(size, AllocFlags.LPtr)
|
|
{ }
|
|
|
|
public LocalMemoryAlloc(int size, AllocFlags flags)
|
|
{
|
|
this.Memory = Win32.LocalAlloc(flags, size);
|
|
|
|
if (this.Memory == IntPtr.Zero)
|
|
throw new OutOfMemoryException();
|
|
|
|
this.Size = size;
|
|
}
|
|
|
|
protected override void Free()
|
|
{
|
|
Win32.LocalFree(this);
|
|
}
|
|
|
|
public override void Resize(int newSize)
|
|
{
|
|
IntPtr newMemory;
|
|
|
|
newMemory = Win32.LocalReAlloc(this, AllocFlags.LMemFixed, newSize);
|
|
|
|
if (newMemory == IntPtr.Zero)
|
|
throw new OutOfMemoryException();
|
|
|
|
this.Memory = newMemory;
|
|
this.Size = newSize;
|
|
}
|
|
}
|
|
}
|