Optimization Related Question
#1

Before I proceed, I'd like to point out this isn't a post asking for scripting help. My purpose here is to get a firmer grasp on PAWN's logic (specifically in the area of resource usage).

Anyway, I had written out a function to load up a bunch of rows from a MySQL database. Naturally, this information was dropped into a variable for use elsewhere. Now, that works fine, but I wanted to try and make it work more dynamically. So, for example's sake, let's say I was loading up houses or something like that. I'd probably save it in something that looks like:

Код:
#define MAX_STUFF 100 //Because 100..

enum sInfo {
	Float:X,
	Float:Y,
	Float:Z,
	interior
	//etc
}

new info[MAX_STUFF][sInfo];
Well, it occurred to me that I may or may not go over 100 at some point. I could set "MAX_STUFF" to a larger number, but my idea was to try and set it up so that I could add more while the gm is running. So then I tried doing this for the hell of it:

Код:
new info[][sInfo];
So my question comes down to this I guess:

What are the implications of making a variable like this? (In both how it works and how it will affect server resources)

..and incidentally, I went through the pawn manual in an attempt to understand this, but I found the information to be lacking.
Reply
#2

Pawn does not support dynamically sizable arrays; what you're trying to do is impossible. Hence the lack of information.
Reply
#3

Yeah, these arrays take their space during the compilation (and have it allocated when your script fires up), and cannot be resized at runtime.

However the direction you're looking at is good. There are many cool plugins these days (such as GVars, CSTL for vector/map support, and the latest memory allocation plugin) which will help you out with dynamic memory allocation. Also large arrays tend to make large .amx files and larger compile times. The benefit grows if you actually may require 30 slots to be used instead of 100, but sometimes even 300.

Good luck!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)