Created
March 7, 2015 23:05
-
-
Save ThuCommix/38fccaea26ca78928a94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public DataWriter(byte[] buffer) | |
{ | |
if (buffer == null) | |
throw new ArgumentNullException("buffer"); | |
GCHandle handle = GCHandle.Alloc(buffer, WhateverMode.Pinned); | |
_buffer = (byte*)handle.AddrOfPinnedObject(); | |
} | |
public void Write(int value) | |
{ | |
WriteData(&value, 4); | |
} | |
private void WriteData(void* source, int length) | |
{ | |
if (_buffer == null) | |
throw new ObjectDisposedException(this.GetType().Name); | |
if (_bufferLength < length) | |
throw new ArgumentException("Exceeding buffer boundaries."); | |
byte* cb = _buffer; | |
byte* dest = _cb + length; | |
byte* src = (byte*)source; | |
for(; cb < dest; cb++, src++) | |
cb = src; | |
} | |
private void Dispose(bool disposing) | |
{ | |
if (_buffer != null) | |
{ | |
_buffer = null; | |
_handle.Free(); | |
} | |
} | |
~DataWriter() | |
{ | |
Dispose(false); | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bei dem cb = src sollen jeweils * vor den bezeichnern stehn