本文整理汇总了C#中System.IO.UnmanagedMemoryStream类的典型用法代码示例。如果您正苦于以下问题:C# UnmanagedMemoryStream类的具体用法?C# UnmanagedMemoryStream怎么用?C# UnmanagedMemoryStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnmanagedMemoryStream类属于System.IO命名空间,在下文中一共展示了UnmanagedMemoryStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadPrefix
public override int ReadPrefix(string shortSha, out ObjectId id, out UnmanagedMemoryStream data, out ObjectType objectType)
{
id = null;
data = null;
objectType = default(ObjectType);
ObjectId matchingKey;
int ret = ExistsPrefix(shortSha, out matchingKey);
if (ret != (int)ReturnCode.GIT_OK)
{
return ret;
}
ret = Read(matchingKey, out data, out objectType);
if (ret != (int)ReturnCode.GIT_OK)
{
return ret;
}
id = matchingKey;
return (int)ReturnCode.GIT_OK;
}
示例2: GetData_ReturnArrayOfStructs
public void GetData_ReturnArrayOfStructs()
{
unsafe
{
short[] @in = new short[50];
for (int i = 0; i < 50; i++)
{
@in[i] = (short)i;
}
int inSize = 100; // 50 x 2 bytes per short
// Allocate a block of unmanaged memory and return an IntPtr object.
IntPtr memIntPtr = Marshal.AllocHGlobal(inSize);
// Get a byte pointer from the IntPtr object.
byte* memBytePtr = (byte*)memIntPtr.ToPointer();
var stream = new UnmanagedMemoryStream(memBytePtr, inSize);
// Set the data
stream.SetData(@in);
// Get the data back out
short[] @out = stream.GetData<short>();
Assert.AreEqual(@in.Length, @out.Length);
for (int i = 0; i < 50; i++)
{
Assert.AreEqual(@in[i], @out[i]);
}
}
}
示例3: LoadFromMemory
public unsafe static Image LoadFromMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle)
{
using (var memoryStream = new UnmanagedMemoryStream((byte*)pSource, size))
using (var bitmap = (Bitmap)BitmapFactory.DecodeStream(memoryStream))
{
var bitmapData = bitmap.LockPixels();
var image = Image.New2D(bitmap.Width, bitmap.Height, 1, PixelFormat.B8G8R8A8_UNorm, 1, bitmap.RowBytes);
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
// Directly load image as RGBA instead of BGRA, because OpenGL ES devices don't support it out of the box (extension).
CopyMemoryBGRA(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
#else
Utilities.CopyMemory(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
#endif
bitmap.UnlockPixels();
if (handle != null)
handle.Value.Free();
else if (!makeACopy)
Utilities.FreeMemory(pSource);
return image;
}
}
示例4: Write
public unsafe void Write(Stream value)
{
if (value.Length > _availableLength)
throw new ArgumentException("Value is too long.");
var buffer = new byte[4096];
var lengthToWrite = value.Length;
while (lengthToWrite > 0)
{
using (var stream = new UnmanagedMemoryStream(_currentPointer.Value.Ptr, _currentPointer.Value.AvailableLength, _currentPointer.Value.AvailableLength, FileAccess.ReadWrite))
{
do
{
var read = value.Read(buffer, 0, Math.Min(buffer.Length, _currentPointer.Value.AvailableLength));
stream.Write(buffer, 0, read);
lengthToWrite -= read;
_currentPointer.Value.AvailableLength -= read;
}
while (_currentPointer.Value.AvailableLength > 0 && lengthToWrite > 0);
_currentPointer = _currentPointer.Next;
}
}
}
示例5: MumbleLink
// Constructor
public MumbleLink()
{
unsafe
{
_memSize = Marshal.SizeOf(typeof(MumbleLinkedMemory));
_mappedFile = NativeMethods.OpenFileMapping(FileMapAccess.FileMapRead, false, Name);
if (_mappedFile == IntPtr.Zero)
{
_mappedFile = NativeMethods.CreateFileMapping(IntPtr.Zero, IntPtr.Zero, FileMapProtection.PageReadWrite, 0,
_memSize, Name);
if (_mappedFile == IntPtr.Zero)
{
throw new Exception("Unable to create file Mapping");
}
}
_mapView = NativeMethods.MapViewOfFile(_mappedFile, FileMapAccess.FileMapRead, 0, 0, _memSize);
if (_mapView == IntPtr.Zero)
{
throw new Exception("Unable to map view of file");
}
_buffer = new byte[_memSize];
_bufferHandle = GCHandle.Alloc(_buffer, GCHandleType.Pinned);
byte* p = (byte*)_mapView.ToPointer();
_unmanagedStream = new UnmanagedMemoryStream(p, _memSize, _memSize, FileAccess.Read);
}
}
示例6: ResourceReader
internal ResourceReader(Stream stream, Dictionary<string, ResourceLocator> resCache)
{
this._resCache = resCache;
this._store = new BinaryReader(stream, Encoding.UTF8);
this._ums = stream as UnmanagedMemoryStream;
this.ReadResources();
}
示例7: UnpackBigEndian
private void UnpackBigEndian(string path)
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
int count = *(bint*)(_source.Address + 0x08);
for (int i = 0; i < count; i++)
stringOffsets.Add(*(bint*)(_source.Address + (i * 0x04) + 0x10));
for (int i = 0; i < count; i++)
dataOffsets.Add(*(bint*)(_source.Address + (stringOffsets.Count * 4) + (i * 4) + 0x10));
for (int i = 0; i < count; i++)
sizes.Add(*(bint*)(_source.Address + (stringOffsets.Count * 4) + (dataOffsets.Count * 4) + (i * 4) + 0x10));
foreach (int off in stringOffsets)
strings.Add(new String((sbyte*)_source.Address + off));
for (int i = 0; i < count; i++)
{
byte[] _fileData = new byte[sizes[i]];
using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte*)(_source.Address + dataOffsets[i]), sizes[i]))
stream.Read(_fileData, 0, (int)stream.Length);
try
{
File.WriteAllBytes(path+"/" + strings[i], _fileData);
}
catch (Exception x) { Console.WriteLine(x.Message); }
}
}
示例8: Add
//Adds the sound we want to play
public void Add(int index, UnmanagedMemoryStream stream)
{
_soundStreams[index] = new SoundStream(stream);
_audioBuffers[index] = new AudioBuffer();
_audioBuffers[index].Stream = _soundStreams[index].ToDataStream();
_audioBuffers[index].AudioBytes = (int) _soundStreams[index].Length;
_audioBuffers[index].Flags = BufferFlags.EndOfStream;
_sourceVoices[index] = new SourceVoice(_audio, _soundStreams[index].Format);
}
示例9: playSoundEffect
public static void playSoundEffect(UnmanagedMemoryStream soundFile)
{
if (soundFlag == true)
{
Stream stream = soundFile;
sp = new System.Media.SoundPlayer(stream);
sp.Play();
}
}
示例10: on_trace_data_collected
private void on_trace_data_collected(cef_trace_client_t* self, byte* fragment, UIntPtr fragment_size)
{
CheckSelf(self);
using (var stream = new UnmanagedMemoryStream(fragment, (long)fragment_size))
{
OnTraceDataCollected(stream);
}
}
示例11: Add
public void Add(int index, UnmanagedMemoryStream sourceStream)
{
streams[index] = new SoundStream(sourceStream);
buffers[index] = new AudioBuffer();
buffers[index].Stream = streams[index].ToDataStream();
buffers[index].AudioBytes = (int)streams[index].Length;
buffers[index].Flags = BufferFlags.EndOfStream;
voices[index] = new SourceVoice(audio, streams[index].Format);
}
示例12: WriterWorkItem
public WriterWorkItem(FileStream fileStream, UnmanagedMemoryStream memStream, MD5 md5)
{
_fileStream = fileStream;
_memStream = memStream;
_workingStream = (Stream)fileStream ?? memStream;
Buffer = new MemoryStream(8192);
BufferWriter = new BinaryWriter(Buffer);
MD5 = md5;
}
示例13: GetImageFileMachineType
/// <summary>
/// Gets the image file machine type.
/// </summary>
/// <param name="buffer">Memory buffer representing native library.</param>
/// <returns>Image file machine type.</returns>
public static unsafe ushort GetImageFileMachineType(byte[] buffer)
{
fixed(byte *ptr = buffer)
{
using(UnmanagedMemoryStream ums = new UnmanagedMemoryStream(ptr, buffer.Length))
{
return GetImageFileMachineType(ums);
}
}
}
示例14: write
/// <summary>
/// Write raw binary data.
/// </summary>
private int write(cef_write_handler_t* self, /*const*/ void* ptr, int size, int n)
{
ThrowIfObjectDisposed();
long length = size * n;
using (var m_stream = new UnmanagedMemoryStream((byte*)ptr, size * n, size * n, FileAccess.Read))
{
return this.Write(m_stream, size, n);
}
}
示例15: read
private UIntPtr read(cef_read_handler_t* self, void* ptr, UIntPtr size, UIntPtr n)
{
CheckSelf(self);
var length = (long)size * (long)n;
using (var stream = new UnmanagedMemoryStream((byte*)ptr, length, length, FileAccess.Write))
{
return (UIntPtr)Read(stream, length);
}
}