Buffering embedded resources

I recently ran into a problem of returning my index.html site upon http request. The problem was that the file size was small enough to fit into flash but too big to fit into RAM available at runtime. When we load a resource file we call:


var file = Resources.GetString(Resources.StringResources.SomeFile);

The begginers guide only mentions that a buffer read can be done to do streaming but no specifics. Is this available ? I ran into a this problem on Netduino Plus (since i don’t have a WIZnet board to try it with Domino). On Netduino Plus if you try to allocate to many consecutive pages of memory (like in this example) you get a OutOfMemoryException (not always) even though you have enough free RAM (maybe not consecutive since GC is doing some remaping before the exception). Did anyone run into this on USBizi?

You are talking about 2 different problems…

  1. If you fail to allocate buffer but you know you have free ram then the problem is fragmentation in heap. You can solve this by calling Debug.GC(true);
    Microsoft is aware if this inconvenience and they are updating it on next NETMF release.

  2. Loading large resources is not friendly in current implementation because you have to read the whole binary resource in one chunk. What we need is a way to be able to load part of the resource. Then you can read parts of it in a loop till you have processed the whole binary resource.
    Microsoft is aware if this inconvenience too and they are updating it on next NETMF release.

Indeed i found this workaround somewhere on the web but it only minimizes the chance of getting this exception. At least this is what i get.

And i was curious if there is any way to read parts of resources is there is no enough RAM available. Guess we have to wait for MS then :confused: I have divided my index.html into separate files and included them into resources. It will have to do for now.

If you have SD card, you can store your content there and use File io instead of embedding everything as resources.

I was aware of it but too lazy to buy one after work :wink: Also since GHI has such a great community i decided to clarify this.