问题标签 [memorystream]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2029 浏览

wpf - 使用没有默认构造函数的 XamlWriter 序列化 WPF 组件

我发现你可以序列化一个 wpf 组件,在我的例子中 a FixedDocument,使用XamlWriter和 a MemoryStream

然后将其取回:

但是,现在我也需要能够序列化 a DocumentPage。它缺少一个默认构造函数,这使得XamlReader.Load调用抛出异常。

有没有办法在没有默认构造函数的情况下序列化 wpf 组件?

0 投票
1 回答
2891 浏览

vb.net - 在 VB.NET 中将内存流渲染到浏览器

在 VB.NET 中,如何将内存流写入浏览器。我的内存流对象具有构建 PDF 文件的数据。现在我希望它在浏览器上呈现。怎么做?

0 投票
2 回答
5620 浏览

c# - 性能:在 MemoryStream 上使用 BinaryReader 读取字节数组,还是直接读取?

我想知道在从字节数组()创建的aBinaryReader上使用 a 是否会显着降低性能。MemoryStreambyte[]

我想读取二进制数据,并将该数据作为字节数组获取。我目前正在选择两种读取数据的方法,并且必须相应地实现许多读取方法。在每次读取操作之后,我需要读取数据之后的位置,因此我正在考虑使用BinaryReader. 第一种,非 BinaryReader 方法:

第二种方法:

这样Read()的方法将被非常频繁地调用,在相同的数据上连续调用,直到所有数据都被读取。

那么,使用 aBinaryReader感觉更自然,但对性能有很大影响吗?

0 投票
2 回答
628 浏览

xml - 内存中 XML 操作

我正在尝试在已打开的OpenXMLword 文档中进行查找和替换MemoryStream

这行不通。我不知道为什么,但是以这种方式操作文档似乎对MemoryStream.

我发现了 Eric White 的这个博客,它做了类似的事情,但我还是不太明白。他使用一个XDocument,所以我有如下内容:

这会在我的文档中找到正确的节点,但问题是现在我无法弄清楚如何更改文本。我以这种System.Xml.Linq.XNodes方式最终得到的(而不是DocumentFormat.OpenXml.Wordprocessing.Text我真正想要的节点)没有InnerTextorValue属性或类似的东西。我看不到任何从节点获取文本或更新它们的方法。我尝试投射节点,但没有编译。

我是否朝着正确的方向前进?或者有没有更简单的方法?任何指针将不胜感激,谢谢。

0 投票
4 回答
7358 浏览

c# - C# StreamWriter 和 StreamReader 内存管理问题,为什么内存使用不释放?

因此,我使用了一个 StreamReader,它使用 MemoryStream 写入 StreamWriter 和此应用程序内部,但内存使用量增加了 300mb(来自较大的输入之一),并且在我完成使用后不会取消分配:

在此之前和之后,我得到了 RAM 使用量,之前它比之后少 300 mb,但我不知道为什么。考虑到这里唯一发生的事情是来自阅读器的数据被放置在文本文件中,我已经做了我能想到的一切来释放该内存我不明白为什么甚至需要使用任何大量内存暂时地。我有什么遗漏吗?...谢谢。

0 投票
1 回答
1742 浏览

c# - Deserializing a MemoryStream - unexpected behaviour

At the moment I am experiencing a very frustrating problem. I will try to abstract the problem to make it a bit easier. It has to with serializing my custom object to a database in one process and deserializing it in another process.

I have two assemlies; AppToDB.dll and AppFromDB.dll. I have a 3rd assembly - MyCustomObject.dll - which both of these assemblies contain a reference to. The MyCustomObject.dll extends MarshalByRefObject.

In my AppToDB.dll I execute the following code:

In AppFromDB.dll I execute this code:

OK, so in both pieces of code you can see a MemoryStream object. In the first AppToDB it is created and if I look at its contents it contains 707 bytes. Fine. I write it to the database and save it there as a BLOB. Now in AppFromDB I retrieve the BLOB and store it in a byte[] array. I write the byte[] array to a MemoryStream again, and see that my MemoryStream objects contains 707 bytes, all of which are in place like the original. It seems I have transferred the object with success!

Now the problem lies with object temp = oBFormatter.Deserialize(dbStream);. As soon as I try to deserialize, my object is a Transparent Proxy and I am unable to cast to MyCustomObject!! How do I get my original object back? How in #@&'s name can I have a MemoryStream object....IN memory...ready to be serialized...and suddenly it's a Transparent Proxy again.

I am at loss. Help is appreciated. I will pray to #@& for the one who has the answer ;)

Edit 1 OK, I must say things are starting to make sense now (although the problem persists). My problem: I have an object (including state) on one side and I need to store it in the database so I can use it days later by another process on the other side.

My object is not serializable, because it wraps a 3rd party object which is not marked as serializable. So my only option seems to be to marshal, which returns an ObjRef, which in turn IS serializable. But of course - days later - the object I am deserializing is merely the reference and my original object is gone.

How do I solve my problem? More people must have encountered this and I just can't seem to find the answer...

Edit 2 OK, I guess I am going to write my own serializable class isomorphic to the 3rd party object. Then run through the whole 3rd party object and, store/wrap its state info etc. Then serialize my object to the database...Seems to be my only option.

Edit 3 Starting on this problem again after a while. Just realized though that solution posted in Edit 2 won't work. I have to deserialize into an object the 3rd party assembly knows, since it will continue to perform operations on it.

0 投票
4 回答
1018 浏览

c# - 将正确的 BytesArray 传递到 MemoryStream for Image

如果我想从字节数组中创建一个图像,有一种方法可以确定我将正确的字节数组传递给 MemoryStream。

如果可能,我如何更正byteArray 它是图像的有效 byteArray?

0 投票
9 回答
133473 浏览

c# - 如何从 .NET 中的流中获取 MemoryStream?

我有以下构造方法,它MemoryStream从文件路径打开一个:

我需要将其更改为接受 aStream而不是文件路径。MemoryStreamStream对象中获取 a 的最简单/最有效的方法是什么?

0 投票
5 回答
2068 浏览

c# - 对象序列化和 IDisposable

这是来自 - http://geekswithblogs.net/paulwhitblog/archive/2007/07/20/114076.aspx

有没有办法在不需要重新分配 memoryStream 对象的情况下编写这个?它不应该被处理(包装在 using 块中)吗?然后重新分配的 memoryStream 是什么?

0 投票
1 回答
394 浏览

c# - 自定义 SimpleSyncProvider 创建零字节文件

我有一个FileSyncProvider并且我编写了 FullEnumerationSimpleSyncProvider 的自定义实现。当文件从FullEnumerationSimpleSyncProvider同步到FileSyncProvider时,它们是正确创建的,但是是零字节。

当在另一个方向(FileSyncProvider 作为源)同步时,一切都按预期工作。

这是我的IFileDataRetriever实现。我在FileStream属性 setter 和 getter 上放置了断点,并且Stream的Size属性始终正确,从不为零。实际的Stream本身是一个MemoryStream,这会导致任何问题吗?

更新:

如果作为实验,我将代码修改如下,则会创建一个 5 字节的文件:

所以这告诉我它应该与 MemoryStream 一起正常工作。如果我在 getter 上放置一个断点,它在被调用时总是看起来有效 - 它具有正确的大小等,而不是 0 作为大小。