Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

CLR_E_OUT_OF_MEMORY


  • Please log in to reply
4 replies to this topic

#1 blubblub

blubblub

    Member

  • Members
  • PipPip
  • 10 posts

Posted 18 December 2010 - 10:47 PM

Hello,
I'm trying to load an xml file residing on the SD Card. The original file is 82kb in size and will not load. But if I reduce the file's size to 1kb it works. The error "CLR_E_OUT_OF_MEMORY" occurs when attempting to load the 82kb file. Does a limitation exist that I'm not aware of? Thanks in advance!!! My code below:

using (StreamReader r = new StreamReader("\\SD\\test.xml"))
                {
                    if (r.BaseStream.Length > 0)
                    {
                        do
                        {
                            
                            string line = r.ReadToEnd();
                            Debug.Print(line);
                            r.Close();


                        } while (!r.EndOfStream);
                    }
       
                }



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 December 2010 - 11:00 PM

Hi blubblub, In the world of microcontroller programming, you'll generally want to break things down into chunks. Your Netduino Plus has about 28KB of available RAM--so reading an 82KB file in one chunk will not fit... If you create a buffer of, say, 1024 bytes and read the file in chunks does that work for you? Welcome to the Netduino community, Chris

#3 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 18 December 2010 - 11:02 PM

Hello,
I'm trying to load an xml file residing on the SD Card. The original file is 82kb in size and will not load. But if I reduce the file's size to 1kb it works. The error "CLR_E_OUT_OF_MEMORY" occurs when attempting to load the 82kb file. Does a limitation exist that I'm not aware of? Thanks in advance!!! My code below:

using (StreamReader r = new StreamReader("\\SD\\test.xml"))
                {
                    if (r.BaseStream.Length > 0)
                    {
                        do
                        {
                            
                            string line = r.ReadToEnd();
                            Debug.Print(line);
                            r.Close();


                        } while (!r.EndOfStream);
                    }
       
                }


The problem is that your file is too big for the netduino to store on 'line'. try this:

using (StreamReader r = new StreamReader("\\SD\\test.xml"))
                {
                    if (r.BaseStream.Length > 0)
                    {
                        do
                        {
                            Debug.Print(r.ReadLine());
                        } while (!r.EndOfStream);
                        r.Close();

                    }
       
                }


Each line should be small enough that the netduino can store it in RAM. Let me know if that works out.

EDIT:
You win again Chris ;)... What Chris said is a good idea too, in case the lines are longer than expected.

By the way, coolest name ever! 'blubblub' :D nice

#4 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 19 December 2010 - 12:22 AM

Consider storing your data in JSON format instead of XML to save space.

#5 blubblub

blubblub

    Member

  • Members
  • PipPip
  • 10 posts

Posted 19 December 2010 - 05:54 AM

Oz, I tried "the quick fix" but received an IndexOutOfRangeException. In the end what Chris said about chunking the data works for this project. After the code below creates string chunks I'll trim the ends and make them xml. I should be able to grab the attributes I'm looking for from each element. The JSON idea makes sense but I'm working on xml files purposed for something else. I'm open to suggestions. I want to learn! That was a great first lesson. Thanks again!
FileStream fs = new FileStream("\\SD\\test.xml", FileMode.Open, FileAccess.Read);

            int nBits = 512;
            byte[] ByteArray = new byte[nBits];
            int nBytesRead = fs.Read(ByteArray, 0, nBits);
            string strLine = "";
            char[] CharArray = Encoding.UTF8.GetChars(ByteArray);
            foreach (char i in CharArray)
            {
                strLine = strLine + i;
            }

            Debug.Print(strLine);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.