Categories > Coding > C++ >
Get size of occupants in array
Posted
I am programming something where I need to combine elements in an array to create a result, but I also need to get the size of occupated spaces in that array.
The array size itself is set to one million* so that a huge number of elements can be added to the array continuisly, but I need to get the size of occupated spaces in the array. Is this possible?
we are dead
Replied
Array.length I guess I honestly can't tell what you're trying to do tho
edit: also why do you have an array with the length of one billion are you just asking for memory issues
Cancel
Post
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
Replied
I'm not dumb lol, just so you know that returns the total size of elements in the array (occupied or not)
Cancel
Post
we are dead
Replied
Instead of using an array use a vector ( I am assuming you want it to grow indefinitely), should do what you want easily. To achieve the behaviour you want with arrays is basically impossible except if you want to check a billion elements and you're also crossing to undefined behaviour territory.
Cancel
Post
Replied
Cancel
Post
Added
Coding a large software that's gonna run a house with an Arduino, someone is paying me to do it.
The specific part I'm working on right now is a even logger. It logs every command the Arduino sends so I can troubleshoot and maintain it.
Cancel
Post
Added
The reason I don't use vectors is because even though Arduino for the most part is the same syntax as C++, it's been modified in ways, some of which including it not having vector. I'll look into it though.
Cancel
Post
we are dead
Replied
Run a house with an arduino.. you do know how much ram arduino have, right? You cant do 100000 element array let alone initialize a million element one. You do embedded programming with arduinos and such not systems programming that big.
My suggestion is to try with and Rpi (if thats possible) as it can handle a much heavier workload and be mindful of your resources.
Cancel
Post
Replied
I'm not that stupid, using multiple Arduinos to correspond to certain systems. I've gotten the array system to work for the most part, I just need to get the size of occupants so I can make the Arduino send the information to a computer.
Cancel
Post
Added
I have a Raspberry Pi 3 laying around, but I think I can get it to work with an Arduino (surprisingly). Should I just switch to the Raspberry Pi?
Cancel
Post
we are dead
Users viewing this thread:
( Members: 0, Guests: 2, Total: 2 )
Cancel
Post