Get resource without reading it completely into memory

I have an application on the Compact Framework that has some large embedded resources (some of them are several megabytes). I am calling assembly.GetManifestResourceStream(...) which returns a Stream object. However, I noticed that on some devices this call not only takes quite a while but causes the device to run out of available memory. Eventually I used reflector to look at the code for this method on the compact framework and it uses an internal method to get a byte[] of the resource data. It then returns this data wrapped in a MemoryStream .

Is there any way to retrieve a resource without using this call since it will always read everything into memory? Ideally I'd like to work with a Stream that I can get random access to without having to read the whole thing into memory (similar to how a FileStream works). It would be pretty neat if I could simply open a FileStream on the assembly and start reading at the appropriate offset, but I doubt this is how resources are embedded.


Don't use an embedded resource. Add it as a content file and open it off disk with a file stream.


我发现了一个开放源代码工具,它公开了大量的元程序元,并允许我手动调入资源:http://www.jbrowse.com/products/asmex/

链接地址: http://www.djcxy.com/p/9080.html

上一篇: 将字符串数组转换为List <string>

下一篇: 获取资源时不会将其完全读入内存