Hello,
I'm Netduino beginner,i just want read a small html file and put it in a string.
I can read 5 or 6 lines of the html file and an error occurs....
In a post a read similar bug resolved with patch but the link is dead...
Can you help me ??
Not easy netduino....
thk
merci
the code:
string result = "";
string line="";
FileStream fs2 = new FileStream("\\SD\\index.html", FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs2);
while ((line = sr.ReadLine()) != null)
{
result = result + line;
Debug.Print(line);
}
sr.Close();
fs2.Close();
Debug messages:
Could not allocate 87 blocks, 1044 bytes. Compacting memory.
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####
#### Message:
#### System.IO.StreamReader::ReadLine [IP: 000a] ####
#### WebServerHome.Utils::getPage [IP: 0031] ####
#### WebServerHome.WebServer::ListenForRequest [IP: 011a] ####
#### WebServerHome.WebServer::.ctor [IP: 004c] ####
#### WebServerHome.Program::Main [IP: 0004] ####
Une exception de première chance de type 'System.OutOfMemoryException' s'est produite dans System.IO.dll
read file in SD card : OutOfMemoryException
Started by clx, Sep 15 2011 04:09 PM
2 replies to this topic
#1
Posted 15 September 2011 - 04:09 PM
#2
Posted 16 September 2011 - 02:37 PM
Welcome to the forum!
Interesting… I didn’t find any troubles like that. A few simple tests I ran on memory pretty much let me allocate up to the amount of available Ram. I couldn’t tell from your post if your sample code is ALL of the program or just a small subset. The obvious first check might be… are you running a large program that only has 1044 bytes available after the program has been loaded? Or you might try doing a simple ten line program and see what kind of memory you are able to allocate.
That being said… if you plan on a full-blown application, most of the sample web servers I messed with used a fixed buffer of 1024 bytes and will only load that partial buffer before sending it out the socket and then loading the next portion of the file... etc… until they finish the file.
Doing my best to keep the smoke in the little black boxes.
If my message helped you... how 'bout giving me a
www.MessingWithReality.com
If my message helped you... how 'bout giving me a
www.MessingWithReality.com
#3
Posted 16 September 2011 - 03:18 PM
How big are the lines you are loading?
Check with Debug.GC(true) how much ram is available.
Check with Debug.GC(true) how much ram is available.
using (var sr = new StreamReader(filePath)) { String line; String content; while ((line = sr.ReadLine()) != null) { content += line; if (sr.EndOfStream) break; } }
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users