Array of Integers Read in Runtime?

Robin2:
Yet another approach is always to send the maximum number of groups with the "unwanted" groups just containing 0s. That has the benefit of always over-writing all of the data elements.

And, of course, it is possible to send the data in binary form and just copy it straight into an array of ints. But that makes debugging harder and I would only do it if it was essential for performance reasons.

...R

Thanks for all the input! The way I have it working now is a Serial.ReadStringUntil("/r") which has worked reliably for me so far. I am trying to keep the code simple for now to isolate any issues before I start improving the way the string is read, though all of the information on maintaining data integrity for serial is very helpful and interesting.

I described in a larger reply (#18) the current state of the code, with a link to the full current .ino file. As it stands now, all I have read online as solutions to my current issue are solutions I don't often see on the Arduino forums or documentation - malloc() and pointers. Is there a workaround people use for variably sized arrays and returning arrays from functions in Arduino code?

Thanks!!!!!!

You have posted 3 long Replies in succession without waiting for a response to any of them. There is just too much stuff there for my little brain.

If you ask a specific question I will try to answer it.

One thing that caught my eye was

The problem I have run into now is that there is no way to return this array from within a function.

Just put it in a global variable and there is no need to return it - all the program will have access to it.

...R

Robin2:
You have posted 3 long Replies in succession without waiting for a response to any of them. There is just too much stuff there for my little brain.

If you ask a specific question I will try to answer it.

One thing that caught my eye was Just put it in a global variable and there is no need to return it - all the program will have access to it.

...R

Apologies for the verbose posts, as concisely as possible, my current question is:

How can I most efficiently "return" an array from a function in C?

Thanks!

ArduinoBoiSashaAyyy:
Apologies for the verbose posts, as concisely as possible, my current question is:

How can I most efficiently "return" an array from a function in C?

And you have my Reply in the piece of my Post that you quoted.

Think about the underlying process for a moment. There are, broadly speaking, two options. Either function can "have" the array of data and can send information to its calling function that enables the calling function to make its own copy of the data. That process requires that there are two copies of the data - at least for some short period of time. Or there is a single copy of the data and the function sends "the address" of the data to the calling function. (More likely the calling function would have passed the address to the subsidiary function in the first place).

In the small memory of a microprocessor it is IMHO only the second system that makes any sense. And by far the simplest way to implement that second system is by making the array a global variable.

...R