memorystream

C++ FILE without writing to disk

爷,独闯天下 提交于 2019-12-22 04:14:13
问题 I'm using a library that has quite a few functions that write to a FILE but none that seem to conveniently dump the same data to an object in memory. Is there any way to create a FILE object (or override it) that stores the data in memory instead of writing to disk -- I'd like to avoid the performance hit of opening/writing/reading from files over and over again. UPDATE: per Rob's suggestion, trying stringstream: ss.put(c); std::string myval = ss.str(); printf("Value: %s\n after writing: %i

Why do I get the an out of memory error when I use using?

家住魔仙堡 提交于 2019-12-22 04:09:46
问题 I have the following method, to convert a BitmapImage to a System.Drawing.Bitmap : public static Bitmap BitmapImageToBitmap(BitmapImage bitmapImage) { Bitmap bitmap; using (var ms = new MemoryStream()) { var encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmapImage)); encoder.Save(ms); bitmap = new Bitmap(ms); } return bitmap; } Whenever I try and use the returned Bitmap object, I get the following error: OutOfMemoryException occured - Out of memory. However,

DeflateStream doesnt work on MemoryStream?

拜拜、爱过 提交于 2019-12-22 03:51:03
问题 I have the following piece of code: MemoryStream resultStream = new MemoryStream(); string users = ""//Really long string goes here BinaryFormatter bFormatter = new BinaryFormatter(); using (MemoryStream assignedUsersStream = new MemoryStream()) { bFormatter.Serialize(assignedUsersStream, users); assignedUsersStream.Position = 0; using (var compressionStream = new DeflateStream(resultStream, CompressionLevel.Optimal)) { assignedUsersStream.CopyTo(compressionStream); Console.WriteLine(

Equivalent of Java's “ByteBuffer.putType()” in C#

佐手、 提交于 2019-12-21 20:28:39
问题 I am trying to format a byte array in C#, by porting a code from Java. In Java, the methods "buf.putInt(value);", buf.putShort, buf.putDouble, (and so forth) are used. However I don't know how to port this to C#. I have tried the MemoryStream class, but there is no method to put a specific type at the end of the byte array. Question: What is the equivalent of Java's "ByteBuffer.putType(value)" in C#? Thanks! 回答1: You can use a BinaryWriter and your MemoryStream: MemoryStream stream = new

FileStream not closing file

霸气de小男生 提交于 2019-12-21 04:21:28
问题 I have the following code: using (MemoryStream str = new MemoryStream()) { Program.api.GetDocument(result, str); using (FileStream fileStream = File.Create(filePath)) { str.WriteTo(fileStream); } } Whenever a file is written, it is always locked afterwards - attempting to delete it or modify it causes Windows to tell me the file is in use, even after closing my application. Am I missing something? 回答1: Your problem is most likely caused by Windows Search Indexing which is a part of Windows

Name cannot begin with the ' ' character

牧云@^-^@ 提交于 2019-12-21 03:09:08
问题 I'm parsing some XML in C#. I'm getting it from a database, and so converting it to a MemoryStream before reading it with an XmlTextReader. The problem is that I get this error: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 3. Following is my XML and my code for reading it (it's coming out of the database alright, no blank first character). Any suggestions? XML: <? xml version="1.0" encoding="utf-8" ?> <form> <e order="0" type="custom" name="test"> <fi

convert string to memory stream - Memory stream is not expandable?

寵の児 提交于 2019-12-20 17:34:42
问题 i was trying to write a string to a memory stream, but failed with the error message: Memory stream is not expandable. the line of code that produces this problem: context.Response.Filter = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(myPage)); anyone have a workaround/fix for that? stacktrace: [NotSupportedException: Memory stream is not expandable.] System.IO.MemoryStream.set_Capacity(Int32 value) +9385744 System.IO.MemoryStream.EnsureCapacity(Int32 value) +50 System.IO

Why does C# memory stream reserve so much memory?

蓝咒 提交于 2019-12-20 11:04:27
问题 Our software is decompressing certain byte data through a GZipStream , which reads data from a MemoryStream . These data are decompressed in blocks of 4KB and written into another MemoryStream . We've realized that the memory the process allocates is much higher than the actual decompressed data. Example: A compressed byte array with 2,425,536 bytes gets decompressed to 23,050,718 bytes. The memory profiler we use shows that the Method MemoryStream.set_Capacity(Int32 value) allocated 67,104

Saving an Image file to sql Server and converting byte array into image

与世无争的帅哥 提交于 2019-12-19 06:31:45
问题 I am storing images in a database and would like to convert them from byte array to image. I have no problem converting an object to byte array but I get an error of "Parameter is not valid" when trying to convert from byte array to image. The object I am passing to my method is from a dataset row. Stored procedure USE [----------------] GO /****** Object: StoredProcedure [dbo].[usp_imageloader_add_test] Script Date: 01/16/2012 09:19:46 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO

Saving an Image file to sql Server and converting byte array into image

荒凉一梦 提交于 2019-12-19 06:31:04
问题 I am storing images in a database and would like to convert them from byte array to image. I have no problem converting an object to byte array but I get an error of "Parameter is not valid" when trying to convert from byte array to image. The object I am passing to my method is from a dataset row. Stored procedure USE [----------------] GO /****** Object: StoredProcedure [dbo].[usp_imageloader_add_test] Script Date: 01/16/2012 09:19:46 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO