Hi everyone! Quick question. Can I make an array of an unknown size? I seem to be having some issues making a dynamic array that changes based off the amount of data I put in it.
Lets say before setup I have this:
payload;
Then I set a variable in my program to say the payload will be payload[9]. Then after it loops, the array may be payload[15]. Sure I can add the max number of places within the array but if I dont fill it all I will have "white space" or zero's at the end of the array.
brolly759:
but if I dont fill it all I will have "white space" or zero's at the end of the array.
So what? Why can't you have that?
Dynamic memory allocation on a micro controller is something probably best left alone unless you really really know what you're doing. If you have to ask this question then you aren't there.
Its Delta the memory police! Well if we are being technical, I should be using AVR studio or some type of ICE to program and view memory/code correctly instead of the Arduino platform.
To answer your question, why can't I have that? Well because the longer the payload, the longer it takes to transmit the data over a wireless connection. Its wasted energy (using a coin cell). There is more compiling code on the other side I need to do at the "hub" to omit the ending zero's rather than just sending the correct data to begin with.
@ sterretje its all numerical values. Cant add anything "extra". I have an algarthem that uses pairs. So [0] is the Identifier, [1] is the dataset. [2] Identifier, [3] dataset, so on and so forth.
@arg, I think I know what you are talking about. I was doing it backwards by trying to start with limiting the array size and then loading the info in, rather than just counting the amounts of data I am adding to each array position and only calling the total array fields that I put into it, and NOT the maximum allowable space. I will try that and see what happens!
@ sterretje its all numerical values. Cant add anything "extra". I have an algarthem that uses pairs. So [0] is the Identifier, [1] is the dataset. [2] Identifier, [3] dataset, so on and so forth.
OK, so this relates to communication and not to arrays You can't add anything extra because you did not tell us what you were doing
brolly759:
Its Delta the memory police! Well if we are being technical, I should be using AVR studio or some type of ICE to program and view memory/code correctly instead of the Arduino platform.
To answer your question, why can't I have that? Well because the longer the payload, the longer it takes to transmit the data over a wireless connection. Its wasted energy (using a coin cell). There is more compiling code on the other side I need to do at the "hub" to omit the ending zero's rather than just sending the correct data to begin with.
So just send the part with useful data. There's no law that says you have to send the whole array.
And your police comment is way way off. I won't stop you. Just giving friendly advice. If you want to play with fire go right ahead. You're only going to burn yourself.