Categories > Coding > C++ >

Get size of occupants in array

Alternate

stop take my rice

vip

Posts: 712

Threads: 113

Joined: Mar, 2022

Reputation: 40

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?

  • 0

we are dead

SeizureSalad

i love femboys

Posts: 1159

Threads: 79

Joined: Mar, 2021

Reputation: 40

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 

  • 0

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Alternate

stop take my rice

vip

Posts: 712

Threads: 113

Joined: Mar, 2022

Reputation: 40

Replied

@SeizureSalad

I'm not dumb lol, just so you know that returns the total size of elements in the array (occupied or not)

  • 0

we are dead

Posts: 7

Threads: 1

Joined: Aug, 2022

Reputation: 0

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.

  • 0

Alternate

stop take my rice

vip

Posts: 712

Threads: 113

Joined: Mar, 2022

Reputation: 40

Replied

I meant one million, still a lot but it will store over a hundred thousand elements

  • 0

Added

@_realnickk

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.

  • 0

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.

  • 0

we are dead

Posts: 7

Threads: 1

Joined: Aug, 2022

Reputation: 0

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.

  • 0

Alternate

stop take my rice

vip

Posts: 712

Threads: 113

Joined: Mar, 2022

Reputation: 40

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.

  • 0

Added

@_realnickk

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?

  • 0

Added

@_realnickk

Alright, thanks!

  • 0

we are dead

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )