I have designed what should be a simple and hopefully working "variables" system, which stores information on objects in a simple, flexible way.
The system works something like this:
"Variables" contain two separate variables: A key and a value. The key is an integer which gives the variable a unique identifier (I opted against Strings for the sake of speed), while the value is what that key "points to".
To achieve this, there is a single command: AddVariable.
This command takes two arguments: A Key variable, and a Value variable. The Key variable is actually a pointer to a Global variable, while the Value is a string/pointer/int.
Of course, as is obvious, that method of storing variable keys as integers has a problem: How can the developer or the program keep track of this? Normally, would have to be all manually declared as constants when the program starts. The keys would all need to be manually given different values, etc.
This would not be in any way enjoyable and would not work well for an Extension system, for example.
To solve this, the AddVariable function is rather a magical function. As I said, the key argument is a pointer to a Global variable. What this function does is it gives that Key a unique identifier automatically. If that key already has an identifier, it can be assumed that a variable with this key already exists for something else so the key is left as-is. (This is built for having multiple Variable lists for different objects, I should add; the idea is mainly so that Extensions can have their own settings that any other code can access in as quiet a way as possible. For example, to create a file loader, you may have a "Variable" which stores what kind of file that Extension will load under a FileType key).
Okay, so that's all sorted... my question!
I have a choice here: Store Variables in a List (which has many methods and things that I probably won't use), or in an Array.
I would need to resize the Array continually via that Slices stuff, whereas the List could just be added to endlessly. Recalling Keys from the array would be easy (just set whatever index to the value; the keys already act perfectly as array indexes), while recalling them from the List would be a bit slower (it looks like I would have to use Search, which goes through every link until it finds one).
Naturally, they seem to both have their strengths and weaknesses. Which do you think is more suited to this?
What kind of performance hit is there with using Arrays and Slicing them compared to using Lists and Searching them?
The system works something like this:
"Variables" contain two separate variables: A key and a value. The key is an integer which gives the variable a unique identifier (I opted against Strings for the sake of speed), while the value is what that key "points to".
To achieve this, there is a single command: AddVariable.
This command takes two arguments: A Key variable, and a Value variable. The Key variable is actually a pointer to a Global variable, while the Value is a string/pointer/int.
Of course, as is obvious, that method of storing variable keys as integers has a problem: How can the developer or the program keep track of this? Normally, would have to be all manually declared as constants when the program starts. The keys would all need to be manually given different values, etc.
This would not be in any way enjoyable and would not work well for an Extension system, for example.
To solve this, the AddVariable function is rather a magical function. As I said, the key argument is a pointer to a Global variable. What this function does is it gives that Key a unique identifier automatically. If that key already has an identifier, it can be assumed that a variable with this key already exists for something else so the key is left as-is. (This is built for having multiple Variable lists for different objects, I should add; the idea is mainly so that Extensions can have their own settings that any other code can access in as quiet a way as possible. For example, to create a file loader, you may have a "Variable" which stores what kind of file that Extension will load under a FileType key).
Okay, so that's all sorted... my question!
I have a choice here: Store Variables in a List (which has many methods and things that I probably won't use), or in an Array.
I would need to resize the Array continually via that Slices stuff, whereas the List could just be added to endlessly. Recalling Keys from the array would be easy (just set whatever index to the value; the keys already act perfectly as array indexes), while recalling them from the List would be a bit slower (it looks like I would have to use Search, which goes through every link until it finds one).
Naturally, they seem to both have their strengths and weaknesses. Which do you think is more suited to this?
What kind of performance hit is there with using Arrays and Slicing them compared to using Lists and Searching them?