Simple changing of string size
#1

Hey guys!
I am currently optimizing my gamemode as I recently read some topics about using 256 as string length is a bad idea, so I am stuck here with a problem.

I use Dini to save and read data from files, and we all know that Dini has that annoying problem with string sizes but I am too lazy to change all 100+ saves/loads in my gm.

One of the things I am loading are reports from my own system. I use enum and arrays to store data about reports and everything works fine, but I don't want my rPoster (name of the player who posted the report) to be 256 length array, because I have a limit of 20k reports and that's why my .amx is over 70Mb big..

One of the ideas I got is to change the MAX_STRING value, but I also use it for different purposes in my whole script and I'm afraid it would cause too much trouble.
Next thing that came to my mind is to smaller the string to the length of the destination array. But, it would be much complicated to do it with, as I already said, over 100+ occurrences. So I have an idea of making my own string smaller function or stock.

Here's what I currently use and it throws errors:
Код:
ReportInfo[reportid][rPoster]  = dini_Get(file, "rPoster");
And here is what I taught might help:
Код:
ReportInfo[reportid][rPoster]  = setlen(dini_Get(file, "rPoster"), 24);
Now, after about 2 hours of googling for such function, I was disappointed and I started to work on my own:
Код:
setlen(str[], len)
{
	new output[len];
	format(output, len, "%s", str);
	return output;
}
This looks very simple, but unfortunately, doesn't work. It throws me errors something like the value should be constant etc.

Could someone please help me and just write that little snippet that would do the job and change the string size?

Thanks very much!
Reply
#2

I'm not able to help, but I advise you to use, Y_ini , it's simple and nice. Otherwise, I don't see a problem with having an array of 256 length, because the names won't reach 256 length, player's name would fill some of the arrays, some on them would stay empty I think, it would take + 1 octets at maximum :P
Reply
#3

Pawn does not support dynamic array sizes. You cannot use variables to set the size of, or to initialize an array. If you're concerned with optimizations, then by all means stop using dini. It's probably the slowest method to date.
Reply
#4

Well, I don't feel like switching to anything right now, cause the script is working normally and I just wanted to make the amx smaller.. Anyways, if I had choosen to rewrite the load/save system, I would use MySQL for sure, so I would intergrate my server with the web portal and forum. Does anybody have some suggestions on what plugins to use for MySQL, cause I have never really worked with it from Pawn.. Thanks in advice!
Reply
#5

BlueG's worked like a charm for me and it's really easy to use; also offers great optimization with threaded and multiple threaded queries.
Reply
#6

Thank you. I am gonna check it out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)