right use of a pointer

I am not a skilled programmer and usually i search for a solution and try to “mostly blindly” apply to my sketch.
I needed to do a command parser for my http page served by my mega and ethernet shield, i googled and found a way, all is ok but i have a doubt.

i use the strtok_r to put every command in a pointer (*aa *bb *cc and so on)
since i create these posters in every function call the arduino is allocating it every time, can this lead to memory fragmentation and in long term a crash?
what is the maximum size of the characters in the single pointer? how can i be sure that i am not doing an overflow on used memory? (in this particular case i think it’s not a big problema since the userMsg is a 160 chars (yes it was taken from my gsm sketch :wink:

This function is very simplified and only looks for the “data” string as first command, but i actually use it in another page with multiple args without a problem.

the first 2 strtok_r on the aa pointers are not an error, i can’t correctly filter out the “a” character in the initial string without taking it out on the second, so i overwrite it, it works ok.

Every suggestion is welcome!

void servePage(void)
{
  char *aa, *bb, *cc, *dd,*ee, *i;
  byte x = 0;


  client = server.available();
  if (client)
  {
    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();

        if (readString.length() < 100)
        {
          readString += c;
          userMsg[x++] = c;
          userMsg[x] = '\0'; // Keep string NULL terminate

        }
        if (c == '\n')
        {
          aa = strtok_r(userMsg, " +=GET/?", &i);
          aa = strtok_r(NULL, " +=/", &i);
          Serial.println(aa);
          bb = strtok_r(NULL, " +/", &i);
          Serial.println(bb);
          cc = strtok_r(NULL, " +/", &i);
          Serial.println(cc);
          dd = strtok_r(NULL, " +/", &i);
          Serial.println(dd);
          ee = strtok_r(NULL, " +/", &i);
          Serial.println(ee);
          
          if (strcmp(bb, "data") == 0)
          {
            drawAuxPage();
          }
          else
          {
            drawMainPage();
          }
        }
      }
    }
  }
}

Using the string class on the Arduino is poison.

it is actually a residue of the old implementation, i think i can skip it since it is used only in the if to check if there is more data.

Can you suggest something?
Thanks

Storage for variables that you declare inside a function is released when the function exits.

Local (function) variables reside in the stack, so there is no chance of fragmentation.

Ok that's perfect, and for the size? not in this case but generally, how much can you fill it? sure it depends on the type of arduino, but say for the uno, is there a risk of overflow maybe on other pointers?

Whandall:
Local (function) variables reside in the stack, so there is no chance of fragmentation.

If the stack meets the heap, the game is over.

If need to keep all the pointers you will have to store them somewhere.
Maybe you can process each token directly after parsing, then you could use one pointer.

Pointers have the same size as ints, half the size of longs or floats.