Answer the question
In order to leave comments, you need to log in
How does an infinite loop use RAM?
Guys, I don’t rummage in the mat part from the word at all, so I want to ask the experts here. I wanted to write an antiAfk program that would move the mouse every 5 seconds, I implemented this process through an endless while (true) loop. It will not harm the PC system and load the RAM if the program runs for a long time? I just don’t know how it all happens inside
import java.awt.*;
public class MouseMoving {
public static int currentX;
public static int currentY;
public static int a = 0;
public static int b = 10;
public static void main(String[] args) throws AWTException {
Robot robot = new Robot();
while(true) {
robot.mouseMove(getDirectionX(), getDirectionY());
robot.delay(5000);
}
}
public static int getDirectionX(){
Point startLocation = MouseInfo.getPointerInfo().getLocation();
currentX = startLocation.x;
int randNum1 = a +(int) (Math.random()*b);
int newX = currentX + randNum1;
return newX;
//int newY = currentX + randNum2;
}
public static int getDirectionY() {
Point startLocation = MouseInfo.getPointerInfo().getLocation();
currentY = startLocation.y;
int randNum2 = a +(int) (Math.random()*b);
int newY = currentY + randNum2;
return newY;
}
}
Answer the question
In order to leave comments, you need to log in
Should not affect the RAM in any way. By the way, RAM is Random Access Memory (RAM). That is, there is definitely no load on the RAM.
The impact would be if in each iteration of the loop a new memory would be allocated for something. And this is not happening. Your variables are either static or on the stack (that is, temporary). In theory, variables on the stack can overflow the stack if you use recursion (that's when a function calls itself), but you don't use it, so that's fine.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question