Elevators - Best method?
#1

Hi! Which method is better for elevator moving?

- Every time elevator reaches wanted position, it opens a file and read the next position
- Load all positions at server start and then just move elevator, which gets positions from arrays

I'm asking because I think that first method will lag because of opening, reading files again and again, and second method will lag because of so much data stored in memory?
Reply
#2

Well the x and y of the elevator are constants because they never should change if it's simply going up and down. The way I did it was just use a variable to store the elevator's current floor and when it changes, use switch case to see what z the next floor will be on.
Reply
#3

Well the thing is that I have more complex elevators... They move up, down, left and right (they are programmed) ... So I must get all three coordinates + move time and wait time till the next 'move'.
Reply
#4

Well you could still do switch case. That would probably use less memory. Definitely don't do the file thing though lol. Arrays would be much faster.
Reply
#5

But I still think file thing will be faster because it reads only one line and store it into memory (when elevator reaches its position, the next position override previous)... I have around 5 diffrent elevator positions for each of 20 elevators... If we load 5 positions (x,y,z) and their move & wait times into arrays for 20 elevators (we get 100 diffrent positions + 40 times and thats 340 values meant to be stored into arrays)... This is a lot of data! .
Reply
#6

Like Backwardsman97 already said use arrays

It doesnt matter how much data you store in the memory the speed is always the same

About the memory aspect, what the heck are 340 cells ?, not much at all, only (340 * 4 / 1024) kB ~ 1,328125 kB

If you want to make it dynamic you should start using SQL instead of files, files are mostly used to store data and load it again at startup
Reply
#7

Thanks, I guess I will use arrays now ... I'm already using SQL (MySQLl) but just for storing user data
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)