General advice on using large char[] buffers

Hi Guys,

I have written some code which talks to a modem. At first I used large char arrays attached to a modem object to get it to work.

I have been reading up more on object orientated design (Yes I understand this is an embedded platform!), and I refactored the code to be a bit more generic, and encapsulated.

I made a modem interaction class which has the buffer, and all the information for sending a command to the modem and receiving the response. The TX buffer is a char[128], and the rx buffer is a char[256] circular buffer.

Now my question is, that is every time a new function is called, I have to create a new Modem Interaction object, which has these large buffers. What kind of overhead is it for the micro? I would probably have at max 2 of these objects instantiated at any given time. I really only need 1, but 2 due to the function calls.

At first I was dynamically allocating and freeing up memory, but after reading up a bit on this forum,it seems to be discouraged due to fragmentation so I moved away from that.
I was thinking of making the Modem_Interaction class static, but I see C++ does not support static classes.
Alternatively one could pass the Modem_Interaction object between each function, but I feel this just makes all the function calls verbose.
I was thinking of making the Modem object have one instance of the Modem_Interaction (composition), is this the way to go?

Any advice on the above?

mangelozzi:
Now my question is, that is every time a new function is called, I have to create a new Modem Interaction object,

No, you don't have to do that, pass the object as a reference.

mangelozzi:
Alternatively one could pass the Modem_Interaction object between each function, but I feel this just makes all the function calls verbose.

You probably could make the functions member functions/methods.

mangelozzi:
I was thinking of making the Modem_Interaction class static, but I see C++ does not support static classes.

You could make the buffers static, or even all attributes/methods of the class.

You should use (much) smaller buffers, a standard UNO only has 2048 bytes tolal RAM.

every time a new function is called, I have to create a new Modem Interaction object

That sounds wrong

Compare that with the way that the Servo library works, for example. A global Servo object is created then used throughout the program. How does that differ from your Modem object ?