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


C# UnmanagedMemoryStream.Close方法代码示例

本文整理汇总了C#中System.IO.UnmanagedMemoryStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# UnmanagedMemoryStream.Close方法的具体用法?C# UnmanagedMemoryStream.Close怎么用?C# UnmanagedMemoryStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.UnmanagedMemoryStream的用法示例。


在下文中一共展示了UnmanagedMemoryStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Unmanaged

        unsafe public IHttpActionResult Unmanaged()
        {
            //使用 UnmanagedMemoryStream 类读取和写入非托管内存。 使用 Marshal 类分配和解除分配非托管内存块。
            // Create some data to read and write.
            byte[] message = UnicodeEncoding.Unicode.GetBytes("Hello Angkor");

            // Allocate a block of unmanaged memory and return an IntPtr object.	
            IntPtr memIntPtr = Marshal.AllocHGlobal(message.Length);

            // Get a byte pointer from the IntPtr object.
            byte* memBytePtr = (byte*)memIntPtr.ToPointer();

            // Create an UnmanagedMemoryStream object using a pointer to unmanaged memory.
            UnmanagedMemoryStream writeStream = new UnmanagedMemoryStream(memBytePtr, message.Length, message.Length, FileAccess.Write);

            // Write the data.
            writeStream.Write(message, 0, message.Length);
            // Close the stream.
            writeStream.Close();
            // Create another UnmanagedMemoryStream object using a pointer to unmanaged memory.
            UnmanagedMemoryStream readStream = new UnmanagedMemoryStream(memBytePtr, message.Length, message.Length, FileAccess.Read);
            // Create a byte array to hold data from unmanaged memory.
            byte[] outMessage = new byte[message.Length];
            // Read from unmanaged memory to the byte array.
            readStream.Read(outMessage, 0, message.Length);
            // Close the stream.
            readStream.Close();
            // Display the data to the console.

            var msg = UnicodeEncoding.Unicode.GetString(outMessage);
            // Free the block of unmanaged memory.
            Marshal.FreeHGlobal(memIntPtr);
            return Json(msg);


        }
开发者ID:wjkhappy14,项目名称:aspnetwebstack,代码行数:36,代码来源:IOController.cs

示例2: Position_Stream_Closed

		public void Position_Stream_Closed ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length);
			ums.Close();
			try {
				long x = ums.Position;
				Assert.Fail ("#1: " + x);
			} catch (ObjectDisposedException) {
			}

			try {
				ums.Position = 0;
				Assert.Fail ("#2");
			} catch (ObjectDisposedException) {
			}
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:17,代码来源:UnmanagedMemoryStreamTest.cs

示例3: Open

        public override void Open(string filePath)
        {
            _content = File.ReadAllText(filePath);

            int i = _content.IndexOf("%!");

            if (i > 0)
            {
                _content = _content.Substring(i, _content.Length - i - 1);
            }

            i = _content.IndexOf("%%EOF");

            if (i > -1)
            {
                _content = _content.Substring(0, i + 5);
            }

            if (this.Viewer.EPSClip)
            {
                unsafe
                {
                    fixed (char* p = _content)
                    {
                        UnmanagedMemoryStream ums = new UnmanagedMemoryStream((byte*)p, _content.Length);
                        DSCTokenizer tokenizer = new DSCTokenizer(ums, true, BitConverter.IsLittleEndian);

                        DSCToken token = null;

                        while ((token = tokenizer.GetNextDSCKeywordToken()) != null)
                        {
                            if (token.Text == "%%BoundingBox:")
                            {
                                try
                                {
                                    DSCToken v1 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v2 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v3 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v4 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);

                                    this.BoundingBox = new GhostscriptRectangle(
                                            float.Parse(v1.Text, System.Globalization.CultureInfo.InvariantCulture),
                                            float.Parse(v2.Text, System.Globalization.CultureInfo.InvariantCulture),
                                            float.Parse(v3.Text, System.Globalization.CultureInfo.InvariantCulture),
                                            float.Parse(v4.Text, System.Globalization.CultureInfo.InvariantCulture));
                                }
                                catch { }

                                break;
                            }
                        }

                        tokenizer.Dispose(); tokenizer = null;
                        ums.Close(); ums.Dispose(); ums = null;
                    }
                }
            }

            this.FirstPageNumber = 1;
            this.LastPageNumber = 1;
        }
开发者ID:illgamer,项目名称:Ghostscript.NET,代码行数:61,代码来源:GhostscriptViewerEpsFormatHandler.cs

示例4: getImage

        //returns bitmap image converted from the PANGU stream
        public Bitmap getImage(float x, float y, float z, float yaw, float pitch, float roll , float fov)
        {
            try
            {
                unsafe
                {
                    pan_protocol_set_aspect_ratio(sock, 1);     //sets aspect ratio
                    pan_protocol_set_boulder_view(sock, 1, 0);  //view boulders
                    pan_protocol_set_field_of_view(sock, fov);  //set field of view

                    ulong t = 1024;
                    char* img;
                    img = pan_protocol_get_viewpoint_by_angle(sock, x, y, z, yaw, pitch, roll, &t); //gets the image
                    UnmanagedMemoryStream readStream = new UnmanagedMemoryStream((byte*)img, (long)t);

                    Bitmap bitmap = fetchImage(readStream);
                    readStream.Close();
                    readStream.Dispose();
                    return bitmap;
                }
            }
            catch
            {
                return null; //Error at PANGU end.
            }
        }
开发者ID:Stewart-Taylor,项目名称:DynamicPathPlanner,代码行数:27,代码来源:PANGU_Connector.cs

示例5: SetLength_Capacity_Exceeded

		public void SetLength_Capacity_Exceeded ()
		{
			UnmanagedMemoryStream ums = new UnmanagedMemoryStream(mem_byteptr,
				length, capacity, FileAccess.ReadWrite);
			try {
				ums.SetLength (capacity + 1);
				Assert.Fail ("#1");
			} catch (IOException ex) {
				// Unable to expand length of this stream beyond its capacity
				Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
			}
			ums.Close();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:15,代码来源:UnmanagedMemoryStreamTest.cs

示例6: WriteByte_Stream_ReadOnly

		public void WriteByte_Stream_ReadOnly ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length);
			try {
				ums.WriteByte (testStreamData [0]);
				Assert.Fail ("#1");
			} catch (NotSupportedException ex) {
				// Stream does not support writing
				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
			}
			ums.Close ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:15,代码来源:UnmanagedMemoryStreamTest.cs

示例7: WriteByte_Stream_Closed

		public void WriteByte_Stream_Closed ()
		{
			UnmanagedMemoryStream ums = new UnmanagedMemoryStream(mem_byteptr,
				length, length, FileAccess.Write);
			ums.Close();
			ums.WriteByte(0x12);
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:7,代码来源:UnmanagedMemoryStreamTest.cs

示例8: Write_Stream_Closed

		public void Write_Stream_Closed ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length);
			ums.Close();
			ums.Write(testStreamData, 0, length);
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:7,代码来源:UnmanagedMemoryStreamTest.cs

示例9: Read_EndOfStream

		public void Read_EndOfStream ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length, length * 2, FileAccess.ReadWrite);
			ums.Write (testStreamData, 0, testStreamData.Length);
			Assert.AreEqual (0, ums.Read (readData, 0, 1), "#1");
			ums.Seek(length + 1, SeekOrigin.Begin);
			Assert.AreEqual (0, ums.Read (readData, 0, 1), "#2");
			ums.Seek(length - 3, SeekOrigin.Begin);
			Assert.AreEqual (3, ums.Read (readData, 0, 5), "#3");
			ums.Seek(capacity + 1, SeekOrigin.Begin);
			Assert.AreEqual (0, ums.Read (readData, 0, 1), "#4");
			ums.Close ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:14,代码来源:UnmanagedMemoryStreamTest.cs

示例10: Read

		public void Read ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length, capacity, FileAccess.ReadWrite);
			ums.Write (testStreamData, 0, testStreamData.Length);
			ums.Position = 0;

			Assert.AreEqual (length / 2, ums.Read (readData, 0, (length / 2)), "#1");
			VerifyTestData ("#2", readData, 0, (length / 2));
			Assert.AreEqual (length / 2, ums.Position, "#3");
			
			//Seek back to begining
			ums.Seek (0, SeekOrigin.Begin);
			
			//Read complete stream
			Assert.AreEqual (length, ums.Read (readData, 0, length), "#4");
			VerifyTestData ("#5", readData, 0, length);
			Assert.AreEqual (length, ums.Position, "#6");
			
			//Seek to mid of the stream and read till end
			ums.Seek ((length / 2), SeekOrigin.Begin);
			ums.Read (readData, 0, (length / 2));
			VerifyTestData ("#7", readData, (length / 2), (length / 2));
			Assert.AreEqual (length, ums.Position, "#8");
			ums.Close ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:26,代码来源:UnmanagedMemoryStreamTest.cs

示例11: CanWrite_Stream_Closed

		public void CanWrite_Stream_Closed ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length, capacity, FileAccess.ReadWrite);
			Assert.IsTrue (ums.CanWrite, "#1");
			ums.Close ();
			Assert.IsFalse (ums.CanWrite, "#2");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:8,代码来源:UnmanagedMemoryStreamTest.cs

示例12: CanWrite

		public void CanWrite ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length, capacity, FileAccess.ReadWrite);
			Assert.IsTrue (ums.CanWrite, "#1");
			ums.Seek (length, SeekOrigin.Begin);
			Assert.IsTrue (ums.CanWrite, "#2");
			ums.Seek (capacity, SeekOrigin.Begin);
			Assert.IsTrue (ums.CanWrite, "#3");
			ums.Seek (capacity + 1, SeekOrigin.Begin);
			Assert.IsTrue (ums.CanWrite, "#4");
			ums.Seek (0, SeekOrigin.Begin);
			Assert.IsTrue (ums.CanWrite, "#5");
			ums.Close ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:15,代码来源:UnmanagedMemoryStreamTest.cs

示例13: Flush_Stream_Closed

		public void Flush_Stream_Closed ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length);
			ums.Close();
			ums.Flush();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:7,代码来源:UnmanagedMemoryStreamTest.cs

示例14: Constructor2

		public void Constructor2 ()
		{
			UnmanagedMemoryStream ums;

			ums = new UnmanagedMemoryStream(mem_byteptr,
				length, 999, FileAccess.Read);
			Assert.IsTrue (ums.CanRead, "#A1");
			Assert.IsTrue (ums.CanSeek, "#A2");
			Assert.IsFalse (ums.CanWrite, "#A3");
			Assert.AreEqual (999, ums.Capacity, "#A4");
			Assert.AreEqual (length, ums.Length, "#A5");
			Assert.AreEqual (0, ums.Position, "#A6");
			ums.Close ();

			ums = new UnmanagedMemoryStream(mem_byteptr,
				length, 666, FileAccess.Write);
			Assert.IsFalse (ums.CanRead, "#B1");
			Assert.IsTrue (ums.CanSeek, "#B2");
			Assert.IsTrue (ums.CanWrite, "#B3");
			Assert.AreEqual (666, ums.Capacity, "#B4");
			Assert.AreEqual (length, ums.Length, "#B5");
			Assert.AreEqual (0, ums.Position, "#B6");
			ums.Close ();

			ums = new UnmanagedMemoryStream(mem_byteptr,
				0, 0, FileAccess.ReadWrite);
			Assert.IsTrue (ums.CanRead, "#C1");
			Assert.IsTrue (ums.CanSeek, "#C2");
			Assert.IsTrue (ums.CanWrite, "#C3");
			Assert.AreEqual (0, ums.Capacity, "#C4");
			Assert.AreEqual (0, ums.Length, "#C5");
			Assert.AreEqual (0, ums.Position, "#C6");
			ums.Close ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:34,代码来源:UnmanagedMemoryStreamTest.cs

示例15: PositionPointer_Stream_Closed

		public void PositionPointer_Stream_Closed ()
		{
			UnmanagedMemoryStream ums = new 
				UnmanagedMemoryStream(mem_byteptr, length);
			ums.Close();
			try {
				byte* bptr = ums.PositionPointer;
				Assert.Fail ("#1");
			} catch (ObjectDisposedException) {
			}

			try {
				// position pointer to somewhere within the capacity
				ums.PositionPointer = (byte*) (capacity - 1);
				Assert.Fail ("#2");
			} catch (ObjectDisposedException) {
			}
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:18,代码来源:UnmanagedMemoryStreamTest.cs


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