You can use arrays or data table to create linked lists quite easily, the former having the disadvantage of a fixed size.
Also, you can use Galaxy++, which allows classes and pointers, making the realization much easier (internally, it also uses data tables).
Your dialog approach is quite creative, however using "real" means of saving data might be more efficient. Also, internally, dialogs are just integers relative to each other, so you can easily create this the same way using integers.
You can do it if you have 3 arrays:
- The actual values (can be integers or strings or units or whatever).
- The position of the next element in the list (must be integers).
- An array of all the "open" positions in the previous arrays. This is needed to recycle the linked lists (must be integers). You will also need an integer to keep track of the number of valid open position. So for example if you have 3 free spot then the first (or, depending on your implementation, last) 3 elements in these arrays are free to use when someone needs to create a new linked list or add elements to an existing linked list.
Example with strings (I show arrays of length 4 with each of the elements separated by a ','):
["e", "q", "H", "y"]
[3, 2, 0, -1]
[1, -1, -1, -1] (Free spots: 1)
This would mean that you have a linked list at location 2, namely "Hey". You start at "H", next location is location 0 which is "e", next location is 3 which is "y", the -1 means that "y" is the last one in the list.
The location of "q" is free (there should be no "reference" to this location at this moment).
As long as you create the arrays to be big enough and you aren't scared to do your own little memory management, you can make your linked lists like this.
Using arrays means you have to allocate the data before hand, and there is no creation/release for that so you use more memory. Of course, you're trading less memory for more operations to get to your data. If you already know your maximum limit, then arrays work too. Also, it's the same at the system level, so the array index is your pointer.
I think WEU and newgenpack for war3 used arrays and syntactic sugar for structs, and that works out okay, so... eh.
In Warcraft, arrays always had a size of 8190-ish and could not be allocated with a smaller size, so it didn't matter. In SC2, where you actually can set the size of an array and there is a memory limit in place, you might want to concern yourself with the memory allocation.
So for something like a linked list, I recommend a dynamic memory allocation like provided by the data table.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Has anyone figured if they can get functioning linked lists?
I think this might work but it's really sketchy. It uses dialogs and the link is implicit via built-in functions to get the next node.
Pardon my ignorance if this code is wrong or has been tried before. I know most calls missing parameters. I've not been coding in galaxy for a while.
You can use arrays or data table to create linked lists quite easily, the former having the disadvantage of a fixed size.
Also, you can use Galaxy
++
, which allows classes and pointers, making the realization much easier (internally, it also uses data tables).Your dialog approach is quite creative, however using "real" means of saving data might be more efficient. Also, internally, dialogs are just integers relative to each other, so you can easily create this the same way using integers.
You can do it if you have 3 arrays:
- The actual values (can be integers or strings or units or whatever).
- The position of the next element in the list (must be integers).
- An array of all the "open" positions in the previous arrays. This is needed to recycle the linked lists (must be integers). You will also need an integer to keep track of the number of valid open position. So for example if you have 3 free spot then the first (or, depending on your implementation, last) 3 elements in these arrays are free to use when someone needs to create a new linked list or add elements to an existing linked list.
Example with strings (I show arrays of length 4 with each of the elements separated by a ','):
["e", "q", "H", "y"]
[3, 2, 0, -1]
[1, -1, -1, -1] (Free spots: 1)
This would mean that you have a linked list at location 2, namely "Hey". You start at "H", next location is location 0 which is "e", next location is 3 which is "y", the -1 means that "y" is the last one in the list.
The location of "q" is free (there should be no "reference" to this location at this moment).
As long as you create the arrays to be big enough and you aren't scared to do your own little memory management, you can make your linked lists like this.
Using arrays means you have to allocate the data before hand, and there is no creation/release for that so you use more memory. Of course, you're trading less memory for more operations to get to your data. If you already know your maximum limit, then arrays work too. Also, it's the same at the system level, so the array index is your pointer.
I think WEU and newgenpack for war3 used arrays and syntactic sugar for structs, and that works out okay, so... eh.
In Warcraft, arrays always had a size of 8190-ish and could not be allocated with a smaller size, so it didn't matter. In SC2, where you actually can set the size of an array and there is a memory limit in place, you might want to concern yourself with the memory allocation.
So for something like a linked list, I recommend a dynamic memory allocation like provided by the data table.