jjzjj

MemoryStream

全部标签

c# - 填充 MemoryStream : 256MB allocation on 16GB system 时出现 OutOfMemoryException

我在我的开发IIS服务器(来自VS2010IDE)上运行以下方法,在64位Windows7机器上安装了16GB内存:publicstaticMemoryStreamcopyStreamIntoMemoryStream(Streamstream){longuiLen=stream.Length;byte[]buff=newbyte[0x8000];intnSz;MemoryStreamms=newMemoryStream();try{while((nSz=stream.Read(buff,0,buff.Length))!=0){ms.Write(buff,0,nSz);}}finally

c# - 在使用中包装 MemoryStream

有人告诉我System.IO.MemoryStream不需要包装在usingblock中,因为没有底层资源,这有点违背我一直被告知的流(“如有疑问,请使用using”)。这是真的吗?那么为什么MSDNexample使用一个(总结如下)?using(MemoryStreammemStream=newMemoryStream(100)){//dostuff} 最佳答案 C#的习惯用法是,如果对象实现了IDisposable,那么您将使用usingblock。这将允许正确处理对象使用的所有资源。您应该不知道MemoryStream的实现细

c++ - 我可以将 stringstream 用作 C# 中的 `MemoryStream` 之类的内存流吗?

在C/C++中,字符串以NULL结尾。我可以像C#中的MemoryStream那样使用stringstream作为内存流吗?内存流的数据中间可能有\0值,但C++字符串以NULL结尾。 最佳答案 当在std::string中存储字符序列时,您可以包含空字符。相应地,std::stringstream也可以处理嵌入的空字符。但是,流上的各种格式化操作不会通过空字符。此外,当使用内置字符串为std::string赋值时,空字符很重要,即,您需要使用各种重载,将字符序列的大小作为争论。你到底想达到什么目的?可能有一种比在字符串流中旅行更简

c# - 如果发送了很多消息,如何写入 MemoryStream

下面是我现在如何从我的流中读取数据:publicListclients=newList();while(true){Update();}privatevoidUpdate(){//Console.WriteLine("Call");if(!serverStarted){return;}foreach(ServerClientcinclients.ToList()){//Istheclientstillconnected?if(!IsConnected(c.tcp)){c.tcp.Close();disconnectList.Add(c);Console.WriteLine(c.conn

c# - 从 MemoryStream 反序列化对象时出错

我正在尝试将序列化对象从客户端发送到服务器,服务器会将其作为字节数组读取,使用字节数组创建内存流,然后使用内存流反序列化。它第一次正常工作,但是当第一个客户端断开连接而第二个客户端连接并发送对象时,我得到了这个:二进制流“0”不包含有效的BinaryHeader。或没有对象类型“”的程序集ID。这是错误发生的地方:privatestaticasyncvoidHandleClient(TcpClienttcpClient){NetworkStreamnetworkStream;try{networkStream=tcpClient.GetStream();byte[]buff=newby

c# - Python 中的 MemoryStream 模拟

Python中是否存在C#MemoryStream的一些类似物(这可以让我将来自某些源的二进制数据直接写入内存)?我将如何使用它? 最佳答案 StringIO是一种可能性:http://docs.python.org/library/stringio.htmlThismoduleimplementsafile-likeclass,StringIO,thatreadsandwritesastringbuffer(alsoknownasmemoryfiles).Seethedescriptionoffileobjectsforopera

c# - 如何通过 Redis 服务器转换具有多种数据类型的 MemoryStream

我正在尝试跨Redis服务器提交信息,我正在VS中使用C#创建控制台应用程序,并使用由Long、String、Int和Double组成的MemoryStream。在运行ubuntu的虚拟机上,我使用MonoDevelop读取我从VS的MemoryStream写入的信息我对跨服务器传输数据相当陌生,到目前为止,我已经尝试将我的MemoryStream转换为字节数组,然后从该字节数组转换为字符串,因为redis只接受字符串数据,然后我是尝试在我的UbuntuVM上的其他控制台上将其转换回原始流。publicvoidSaveBigData(){varcache=RedisConnectorH

c# - 处置后调用 MemoryStream.ToArray() 是否危险?

在下面的代码中,GC是否有可能清除MemoryStream以便ToArray失败,因为它在using语句之外?privatestaticbyte[]getBytes(){MemoryStreamms=null;using(ms=newMemoryStream()){//...}returnms.ToArray();} 最佳答案 不,这不可能。这样做是安全的-MemoryStream保持对字节数组的强引用。我会看看是否可以找到任何关于保证的文档...编辑:有点……来自MemoryStream.Close:Thebufferisstil

c# - 在 c# wpf 中从 Memorystream 获取图像源

如何使用C#在WPF中从MemoryStream获取ImageSource?或者将MemoryStream转换为ImageSource以在wpf中将其显示为图像? 最佳答案 using(MemoryStreammemoryStream=...){varimageSource=newBitmapImage();imageSource.BeginInit();imageSource.StreamSource=memoryStream;imageSource.EndInit();//AssigntheSourcepropertyofyou

c# - StreamWriter 写入 MemoryStream

我的印象是,当您在StreamWriter对象中调用Flush()时,它会写入基础流,但显然我的代码不是这种情况。它不会写入我的文件,而不会写入任何内容。我哪里出错了?publicFileResultDownloadEntries(intid){Competitioncompetition=dataService.GetCompetition(id);IQueryableentries=dataService.GetAllCompetitionEntries().Where(e=>e.CompetitionId==competition.CompetitionId);MemoryStr