当前位置: 首页>>代码示例>>C#>>正文


C# IO.UnmanagedMemoryStream类代码示例

本文整理汇总了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;
        }
开发者ID:withzemi1,项目名称:libgit2sharp.voron,代码行数:26,代码来源:VoronOdbBackend.cs

示例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]);
				}
			}
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:34,代码来源:StreamExtensionsTest.cs

示例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;
            }

        }
开发者ID:Powerino73,项目名称:paradox,代码行数:25,代码来源:StandardImageHelper.Android.cs

示例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;
				}
			}
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:25,代码来源:MultiBytePointer.cs

示例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);

            }
        }
开发者ID:sidewinder94,项目名称:MumbleLink-CSharp,代码行数:36,代码来源:MumbleLink.cs

示例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();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:ResourceReader.cs

示例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); }
            }
        }
开发者ID:chrisall76,项目名称:Sm4sh-Tools,代码行数:32,代码来源:Unpacker.cs

示例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);
 }
开发者ID:quibsorg,项目名称:CsGoAimbot,代码行数:10,代码来源:SoundManager.cs

示例9: playSoundEffect

 public static void playSoundEffect(UnmanagedMemoryStream soundFile)
 {
     if (soundFlag == true)
     {
         Stream stream = soundFile;
         sp = new System.Media.SoundPlayer(stream);
         sp.Play();
     }
 }
开发者ID:atadjiki,项目名称:Underworld2171,代码行数:9,代码来源:Audio.cs

示例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);
            }
        }
开发者ID:lukeandshuo,项目名称:HydataBrowser,代码行数:9,代码来源:CefTraceClient.cs

示例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);
 }
开发者ID:nkarpey,项目名称:Zat-s-External-CSGO-Multihack,代码行数:9,代码来源:SoundManager.cs

示例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;
 }
开发者ID:danieldeb,项目名称:EventStore,代码行数:9,代码来源:WriterWorkItem.cs

示例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);
         }
     }
 }
开发者ID:jhabjan,项目名称:Ghostscript.NET,代码行数:15,代码来源:NativeLibraryHelper.cs

示例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);
            }
        }
开发者ID:yasoonOfficial,项目名称:cefglue,代码行数:13,代码来源:CefWriteHandler.Impl.cs

示例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);
            }
        }
开发者ID:whztt07,项目名称:SDK,代码行数:10,代码来源:CefReadHandler.cs


注:本文中的System.IO.UnmanagedMemoryStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。