をちょろっと作ってみた@アンマネージメモリ
でも、そんな仰々しいものじゃなく、単純に、Marshalのメソッドを呼び出してみただけ(笑)
Marshal.AllocHGlobal()で確保したメモリと
Marshal.AllocCoTaskMem()で確保したメモリ
どっちがアクセスが速いかは、気が向いたら、計測しておきますわぁ~
でもなんとなく、Marshal.AllocHGlobal()のほうが速い気がするけど...
C#:
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace bMountLib.Objects
- {
- //アンマネージメモリ管理クラス
- public class CommonMethedMemory
- {
- #region APIs
- [DllImport("Kernel32.dll", EntryPoint="RtlMoveMemory")]
- private static extern void CopyMemory(IntPtr Destination, IntPtr Source, [MarshalAs(UnmanagedType.U4)] int Length);
- #endregion
- //-------------------------------------------
- //alooc
- //
- //-------------------------------------------
- static public IntPtr MemAlloc(int size)
- {
- #region
- return Marshal.AllocHGlobal(size);
- #endregion
- }
- //-------------------------------------------
- //free
- //
- //-------------------------------------------
- static public void MemFree(IntPtr pt)
- {
- #region
- Marshal.FreeHGlobal(pt);
- #endregion
- }
- //-------------------------------------------
- //コピー
- //
- //-------------------------------------------
- static public void MemCopy(IntPtr d, IntPtr s, int l)
- {
- #region
- CopyMemory(d, s, l);
- #endregion
- }
- }
- }



