mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
b02427417c
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5614 21ef857c-d57f-4fe0-8362-d861dc6d29cd
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using ProcessHacker.Common;
|
|
|
|
namespace ProcessHacker.Native
|
|
{
|
|
public class AlignedMemoryAlloc : MemoryAlloc
|
|
{
|
|
private IntPtr _realMemory;
|
|
|
|
public AlignedMemoryAlloc(int size, int alignment)
|
|
{
|
|
// Make sure the alignment is positive and a power of two.
|
|
if (alignment <= 0 || Utils.CountBits(alignment) != 1)
|
|
throw new ArgumentOutOfRangeException("alignment");
|
|
|
|
// Since we are going to align our pointer, we need to account for
|
|
// any padding at the beginning.
|
|
_realMemory = MemoryAlloc.PrivateHeap.Allocate(0, size + alignment - 1);
|
|
|
|
// aligned memory = (memory + alignment - 1) & ~(alignment - 1)
|
|
this.Memory = _realMemory.Align(alignment);
|
|
this.Size = size;
|
|
}
|
|
|
|
protected override void Free()
|
|
{
|
|
MemoryAlloc.PrivateHeap.Free(0, _realMemory);
|
|
}
|
|
|
|
public override void Resize(int newSize)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|