Large per player strings
#1

I have encountered a situation when I needed a "MAX_PLAYERS" string with a length of about 500 characters.
Normally I'd never even create more than a single per player string but no matter how I do this, in the end I find myself needing such a string. I thought of simply storing the text in files (file for each player) and access the files instead of accessing any variables, but it's really really slow when I will do this multiple times for different players at once.
There's another way I thought of which would be PVars, I don't really get their memory usage, also they seem really comfortable as they don't increase the amx size at all.

Anyway, how should I create a per-player ~500 character string?
Thanks.
Reply
#2

pVars is the way to go

EDIT:

pawn Код:
//top
#undef MAX_PLAYERS
#define MAX_PLAYERS 500//change 500 to your server slot count

new string[MAX_PLAYERS] = 0;


//code
string[playerid] = 1;

//etc etc
Is that what u mean?
Reply
#3

This might be useful: https://sampwiki.blast.hk/wiki/SetPVarString
Reply
#4

Quote:
Originally Posted by The.Sandman
Посмотреть сообщение
pVars is the way to go
I completely disagree. Why sacrifice speed for pvars if the variable isnt used by other scripts?


There's nothing wrong with creating that many strings if you have the memory. Though if you dont want to, you could just use ONE global string for each player. PAWN is single threaded, so there will never be a time when two players need the same string. You can simply format the single string with the information for said player before using it.
Reply
#5

I'm talking about a better version of:

new string[MAX_PLAYERS][500];


Which is just crazy.
Is there a way to store such things without wasting so much memory? Is PVar the best way?
Reply
#6

Quote:
Originally Posted by Miguel
Посмотреть сообщение
No, this isn't..
PVar's isn't so useful.. and not recommended
Reply
#7

Quote:
Originally Posted by Kyosaur
Посмотреть сообщение
I completely disagree. Why sacrifice speed for pvars if the variable isnt used by other scripts?


There's nothing wrong with creating that many strings if you have the memory. Though if you dont want to, you could just use ONE global string for each player. PAWN is single threaded, so there will never be a time when two players need the same string. You can simply format the single string with the information for said player before using it.
I use these strings globally, and access them randomly during commands and such- each string of mine stores other data of the player.
Reply
#8

Still need help please.
Reply
#9

new string[MAX_PLAYERS][500];
According to my calculations, this string will use 1mb of ram Is it so bad for you?
Reply
#10

Quote:
Originally Posted by Incubator
Посмотреть сообщение
each string of mine stores other data of the player.
You can't really store it in any other way better than variables. Why should you give up speed just because of 2kilobites of memory (amx file)?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)