最新の更新情報

2012年2月
« 1月    
 1234
567891011
12131415161718
19202122232425
26272829  

本ブログのURL

qrcode.png

雨雲の動き

お天気

 
 
吟遊詩人の戯言 内専用の記事検索...
 
 

C#向けのメモリ管理クラス


キーワード(クリックで関連記事が読めます) →

関連記事



 
 

をちょろっと作ってみた@アンマネージメモリ
でも、そんな仰々しいものじゃなく、単純に、Marshalのメソッドを呼び出してみただけ(笑)


Marshal.AllocHGlobal()で確保したメモリと
Marshal.AllocCoTaskMem()で確保したメモリ

どっちがアクセスが速いかは、気が向いたら、計測しておきますわぁ~
でもなんとなく、Marshal.AllocHGlobal()のほうが速い気がするけど...

C#:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5.  
  6. namespace bMountLib.Objects
  7. {
  8.     //アンマネージメモリ管理クラス
  9.     public class CommonMethedMemory
  10.     {
  11.         #region APIs
  12.         [DllImport("Kernel32.dll", EntryPoint="RtlMoveMemory")]
  13.         private static extern void CopyMemory(IntPtr Destination, IntPtr Source, [MarshalAs(UnmanagedType.U4)] int Length);
  14.         #endregion
  15.  
  16.         //-------------------------------------------
  17.         //alooc
  18.         //
  19.         //-------------------------------------------
  20.         static public IntPtr MemAlloc(int size)
  21.         {
  22.             #region
  23.             return Marshal.AllocHGlobal(size);
  24.             #endregion
  25.         }
  26.  
  27.         //-------------------------------------------
  28.         //free
  29.         //
  30.         //-------------------------------------------
  31.         static public void   MemFree(IntPtr pt)
  32.         {
  33.             #region
  34.             Marshal.FreeHGlobal(pt);
  35.             #endregion
  36.         }
  37.  
  38.         //-------------------------------------------
  39.         //コピー
  40.         //
  41.         //-------------------------------------------
  42.         static public void   MemCopy(IntPtr d, IntPtr s, int l)
  43.         {
  44.             #region
  45.             CopyMemory(d, s, l);
  46.             #endregion
  47.         }
  48.     }
  49. }

 
 
 
 

コメントを残す

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">