iosfreak
iosfreak

Reputation: 5238

Dealing with large Strings/ Arrays?

I need to parse a lot of data. When I mean a lot, I'm talking around 5,000 - 10,000 characters. Right now, my code works with 285ish pieces of data. I'm using the Arduino prototyping platform. Here's my loop() in my sketch:

void loop() {

    if (client.available()) {
        char inChar = client.read();
        currentLine += inChar;
        if (inChar == '\n') { currentLine = ""; }

        if (currentLine.endsWith("[start]")) {
            readingData = true;
            theData = "";
        }

        if (readingData) {
            if (inChar != '[') {
                 theData += inChar;
                 //Serial.println("something!");
            }
            else {
                readingData = false;
                int count = theData.length()-0;
                theData = theData.substring(1, count);
                Serial.println(theData);
                doAction(100,count,theData);
                client.stop();
            }
        }
    }

    if (!client.connected()) {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();
        for(;;)
            ;
    }
}

Should I split it up into 20+ strings and put them in an array? I'm not sure if my 2KB of RAM will be able to handle that.

Upvotes: 1

Views: 317

Answers (1)

With 2 kilobytes of RAM you can have no more than 2000 bytes of data (and in reality, significantly less, for example, perhaps only 1500 bytes, because of stack and global spaces).

If you need to process 20 kilobytes of data in memory, buy a bigger microcontroller.... (or program your Arduino to transmit the data to your PC which will process it).

Upvotes: 4

Related Questions