项目作者: 10sa

项目描述 :
Provide unmanaged memory allocation, memory heap creation.
高级语言: C#
项目地址: git://github.com/10sa/Unmanaged-Memory.git
创建时间: 2018-03-13T07:34:24Z
项目社区:https://github.com/10sa/Unmanaged-Memory

开源协议:MIT License

下载


Unmanaged Memory

This library provides memory that can not be collected by the CLR gc and Memory heap allocation.

You should think twice when you need like this functions. Unmanaged Memory Allocation is isn’t REALLY good idea in GC Environment. I recommend use this code only for study. If you need reason, Reference this stackoverflow question.

Memory areas allocated using this library are not collected by gc and must be released by the programmer. A memory leak occurs when all references are disconnected without being released.

This library also uses WinAPI. It doesn’t work on non-Windows platforms.

For the WinAPI used in this library, please refer to the “List of Used WinAPIs” below.

Examples

  1. /// Allocation Unmanaged memory
  2. Memory memroy = Memory.Allocation(4); // 4Bytes Memory allocation.
  1. /// Access Memory
  2. byte data = memory[0];
  3. memory[0] = 2;
  4. byte[] datas = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF};
  5. memory.WriteBytes(datas, 0, datas.Length);
  1. /// Release Memory
  2. memory.Free();
  1. /// Since VS2017, C++ Version Memory release
  2. delete memory; // memory : Address (in C#, IntPtr type variable.)
  1. /// Dispose Free
  2. using (Memory memory = Memory.Allocation(4))
  3. {
  4. memory.IsFreeOnDispose = true; // This code will be make automatic memory release.
  5. ...
  6. }
  1. /// Allocation Memory heap and Use.
  2. Heap memoryHeap = Heap.CreateHeap();
  3. Memory memory = Memory.Allocation(memoryHeap, 8); // 8Bytes Memory allocation on "memoryHeap" Heap.
  1. /// Destory Memory heap
  2. memoryHeap.Destory();

List of Used WinAPIs

List of Data types