SRL Archive - MSI Suggestions

The use of Global arrays?


Coh3n

2010-06-30 05:53:27

Hey guys,

I'm not sure exactly where I stand on this, and this has been bounced around since MSI started. Nava was watching me do some work on MSI on the weekend, and he suggested using global arrays for things such as items, objects, script, etc. Now, up until last weekend, there was always an MSI_Item array that stored the loaded items. Up until about now, I didn't know why it was like this, but I'm starting to think that we could have kept it that way.

var
MSI_Item: array[0..(ITEM_COUNT - 1)] of TItem;
MSI_Object: array[0..(OBJECT_COUNT)] of TMSObject;
MSI_Script: array[0..(SCRIPT_COUNT)] of TScript;
This would avoid loading and freeing (TItem) all the time. Just loading everything in the memory once would probably save some time. I just wanted to see what other people think about this. Would it be better to use global arrays, or just stick with what we currently have?

Pros
  • No loading/freeing. Everthing's only loaded once.
  • To use, all that would be needed:

  • MSI_Object[OBJ_TREE_NORMAL].Colors;
Cons
  • May slow down the script by having everything already in memory (still not sure about this).

That is all,
Coh3n

marpis

2010-06-30 06:12:00

Loading them all to memory at once, hmm… Would that slow the script down on already slow computers?

Coh3n

2010-06-30 06:14:02

From: marpis
Loading them all to memory at once, hmm… Would that slow the script down on already slow computers?

Not sure. I don't see how it would make it better. If we wanted to avoid that, we would have to have isLoaded boolean arrays for each one (basically the TItem system Naum originally wrote), in which case I don't know if it would be worth it.

E: Added a pros/cons list. Also, now that I think about it, I don't think it would slow down the script. If anything it would make it faster because it doesn't load/free everything when they're used.

marpis

2010-06-30 06:34:43

Ok I changed my mind about this due to this new idea came in my mind :)
I say yes, let's have everything in separate global arrays, load them once and free them once.

Another pro:
TItems and TMSObjects would be used the same way, now they're completely different.

Coh3n

2010-06-30 08:17:28

Yeah. We wouldn't even need to free anything unless they use DTMs. Also, I'll be adding a location type for relocating when I'm done work at the end of the week (along with several other improvements posted on the forums). If you haven't read the other threads yet, I'll be looking at you TMMLocvation type and function.

I'll probably add Locations.scar and we'd then have to make:

MSI_Location: array[0..(LOCATION_COUNT - 1)] of TLocation;

Sir R. M8gic1an

2010-06-30 09:24:58

If I'm not mistaken, having an empty Type or a 'loaded' one will use up just as much memory. (unless DTMs, BMPs, TPAs)

But for loading EXP := 25 or EXP := 0, it probably uses up the same memory.

Therefore, if we're having global arrays, we might as well just load everything.

~RM

Coh3n

2010-06-30 09:27:24

Yeah that's what I was thinking. It may take a couple seconds to load everything at the beginning, but overall I think it will increase the scripts efficiency.

nickrules

2010-06-30 09:35:03

From: marpis

Another pro:
TItems and TMSObjects would be used the same way, now they're completely different.


Why would that be good? it seems that it would be easier they way they are…

Sir R. M8gic1an

2010-06-30 09:36:51

From: nickrules
Why would that be good? it seems that it would be easier they way they are…


Meaning they would use the same constant, therefore we'd only have half the constants = easier to manage.

~RM

Coh3n

2010-06-30 09:54:49

Also nick, you would no longer need to call MSI_GetItem, etc. You would only need to use MSI_Item[THE_ITEM_YOU_WANT].

nickrules

2010-06-30 14:07:29

ah, i see. well then, i'm for this idea. assuming it doesn't lag like crazy.

Nava2

2010-06-30 14:30:21

FYI, preloading the arrays, it doesn't slow down your computer. It loads them into RAM which means that there would be less available for other programs, but I can't see it being a big deal.

Coh3n

2010-07-03 22:45:14

Committed. :)

Narcle

2010-07-04 20:06:00

From: Nava2
FYI, preloading the arrays, it doesn't slow down your computer. It loads them into RAM which means that there would be less available for other programs, but I can't see it being a big deal.


Most computers now have so much ram it doesn't really matter anymore. Average RAM now is like 3-4gb.