- Joined
- Jan 21, 2007
- Sythe Gold
- 1,234
- Messages
- 14,211
- Discord Unique ID
- 203283096668340224
Hey anyone with knowledge of threads, I need some help (aka I'm too lazy to use Google). I've got this code from my fractal program (only giving a small chunk because the whole program is fairly large)
Now, every time the fractal is changed I need to reset it (which just erases the ArrayList squares and puts back the initial seed square into it) and iterate back up to the iteration number that the fractal is on (up to 9 times).
The only speed issue on my computer (fairly good i7) is that when you go to undo multiple things it lags up (because with each undo it has to clear the fractal and iterate 9 times if I'm looking at the 9th generation which is default).
What I'm thinking is that if I create another method iterate(int gen) that will iterate from the start (aka reset the fractal) to the generation (number of iterations) I give in gen, I could split it into a number of different threads on like the 2nd or third generation where there will be like 4 or 16 squares. Then each of those 4 to 16 threads would iterate one square, which turns into 4 and then those 4, etc, etc until it is finished.
I'm not sure it will improve speed (which is really fast anyways) but I'd love to make it just a bit faster to stop the catch on undo. Anyone want to explain the general gist of how I'd go about doing that? I've never really worked with threads before so I really only have a slight clue on what the hell I'm doing.
Thanks
Code:
public void iterate()
{
ArrayList<Square> temp = new ArrayList<Square>();
for (int a = squares.size() - 1; a >= 0; a--)
{
Square[] b = squares.get(a).iterate();
for (Square c : b)
{
temp.add(c);
}
squares.remove(a);
}
squares = temp;
}
Now, every time the fractal is changed I need to reset it (which just erases the ArrayList squares and puts back the initial seed square into it) and iterate back up to the iteration number that the fractal is on (up to 9 times).
The only speed issue on my computer (fairly good i7) is that when you go to undo multiple things it lags up (because with each undo it has to clear the fractal and iterate 9 times if I'm looking at the 9th generation which is default).
What I'm thinking is that if I create another method iterate(int gen) that will iterate from the start (aka reset the fractal) to the generation (number of iterations) I give in gen, I could split it into a number of different threads on like the 2nd or third generation where there will be like 4 or 16 squares. Then each of those 4 to 16 threads would iterate one square, which turns into 4 and then those 4, etc, etc until it is finished.
I'm not sure it will improve speed (which is really fast anyways) but I'd love to make it just a bit faster to stop the catch on undo. Anyone want to explain the general gist of how I'd go about doing that? I've never really worked with threads before so I really only have a slight clue on what the hell I'm doing.
Thanks








