- Joined
- Jul 10, 2007
- Messages
- 6,306
One of the nice things about Warcraft 3 was that it didn't have memory limits. SC2 on the other hand does have memory limits.
Now let us consider struct allocation and deallocation. Warcraft 3 vjass simply used a stack to spew out and recycle unique instances of a given struct. In SC2, the instances can be declared on the fly, but only globally declared instances may be kept (no structrefs allowed). This is problematic as a map may have many units, thus requiring many structs, thus running into the memory cap.
If one were to use 8192 as the limit for each struct, the cap would be reached after 10-20 structs.
One can use the data table to allocate sets of data, but this is extremely, extremely, extremely slow and extremely clunky.
So then what is the solution?
Thoughts and opinions please, I am trying to solve this ^_^.
Consider a map with 12 players and 600 units for each player with 30 structs (with multiple instances of each struct) containing lots of data for each and every unit. Impossible for SC2 to handle?
The above is a very realistic scenario for me (from combat system and AI alone), so I really need to nail down a good way to do object allocation in SC2.
I look forward to hearing people's feedback ^_-.
edit
Look at the below code for a first hand look at how most things just really aren't possible in SC2 atm (unless we can figure out a good way to do the above)
edit
Template support, either in a 3rd party language or in Galaxy, would be a step in the right direction.
Now let us consider struct allocation and deallocation. Warcraft 3 vjass simply used a stack to spew out and recycle unique instances of a given struct. In SC2, the instances can be declared on the fly, but only globally declared instances may be kept (no structrefs allowed). This is problematic as a map may have many units, thus requiring many structs, thus running into the memory cap.
If one were to use 8192 as the limit for each struct, the cap would be reached after 10-20 structs.
One can use the data table to allocate sets of data, but this is extremely, extremely, extremely slow and extremely clunky.
So then what is the solution?
Thoughts and opinions please, I am trying to solve this ^_^.
Consider a map with 12 players and 600 units for each player with 30 structs (with multiple instances of each struct) containing lots of data for each and every unit. Impossible for SC2 to handle?
The above is a very realistic scenario for me (from combat system and AI alone), so I really need to nail down a good way to do object allocation in SC2.
I look forward to hearing people's feedback ^_-.
edit
Look at the below code for a first hand look at how most things just really aren't possible in SC2 atm (unless we can figure out a good way to do the above)
Code:
const int LIST_SIZE = 100;
struct List {
int[LIST_SIZE] next;
int[LIST_SIZE] prev;
};
void addToList(structref<List> list, int node) {
list.prev[node] = list.prev[0];
list.next[node] = 0;
list.next[list.prev[0]] = node;
list.prev[0] = node;
}
void removeFromList(structref<List> list, int node) {
list.prev[list.next[node]] = list.next[node];
list.next[list.prev[node]] = list.prev[node];
}
const int QUEUE_SIZE = 100;
struct Queue {
int[QUEUE_SIZE] next;
int last;
};
void pushOnQueue(structref<Queue> queue, int node) {
queue.next[queue.last] = node;
queue.last = node;
queue.next[node] = 0;
}
void popFromQueue(structref<Queue> queue) {
queue.next[0] = queue.next[queue.next[0]];
}
const int MAX_ALLOC = 100;
typedef int[MAX_ALLOC] recyclerARR;
struct Recycler {
recyclerARR stack;
int instanceCount;
};
int allocate(structref<Recycler> recycler) {
int pointer = recycler.stack[0];
if (!pointer) {
if (recycler.instanceCount == MAX_ALLOC) {
TriggerDebugOutput(1, StringToText("ALLOCATION OVERFLOW"), true);
return 0;
} //if
pointer = recycler.instanceCount + 1;
recycler.instanceCount = pointer;
} //if
else {
recycler.stack[0] = recycler.stack[pointer];
recycler.stack[pointer] = -1;
} //else
return pointer;
} //allocate
void deallocate(structref<Recycler> recycler, int pointer) {
if (recycler.stack[pointer] != -1) {
TriggerDebugOutput(1, StringToText("ATTEMPT TO DEALLOCATE NULL POINTER"), true);
return;
} //if
recycler.stack[pointer] = recycler.stack[0];
recycler.stack[0] = pointer;
}
//Stack: count++, count--, very simple
//example
//
// Recycler listRecycler
// List list;
// int node = allocate(listRecycler);
// addToList(list, node);
// removeFromList(list, node);
// deallocate(listRecycler, node);
edit
Template support, either in a 3rd party language or in Galaxy, would be a step in the right direction.
Last edited: