12.02.2014, 17:59
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:
And here is what I taught might help:
Now, after about 2 hours of googling for such function, I was disappointed and I started to work on my own:
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!
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");
Код:
ReportInfo[reportid][rPoster] = setlen(dini_Get(file, "rPoster"), 24);
Код:
setlen(str[], len) { new output[len]; format(output, len, "%s", str); return output; }
Could someone please help me and just write that little snippet that would do the job and change the string size?
Thanks very much!