14.06.2018, 11:05
You're lucky the axm size isn't bigger than 5Mb.
If you take the array-size into account:
3500 indices x (256 cells for one field, 256 cells for another field) x 4 bytes per cell = 3500 x 512 x 4 = 7.168.000 bytes.
That's 6.8Mb for that array alone.
Like suggested earlier, only use the size for a playername (24 cells instead of 256).
Reducing this to it's proper size alone would give you an array of:
3500 x (24 + 24) x 4 = 3500 x 48 x 4 = 672.000 bytes or 656Kb.
It's 1/10th the size.
Or better yet:
Give every player a unique number as his ID (not the ingame playerid but an account-ID in your saving system).
Then you can replace those fields by an integer.
Your array would shrink to this size:
3500 indices x (1 cell for the first ID, 1 cell for the second ID) x 4 bytes per cell = 3500 x 2 x 4 = 28.000 bytes = 27Kb.
That's 256 times smaller than before and it still contains the same information.
Not the name of the player per se, but still his ID, which you can use to get the name from.
To make this effective, you should convert to MySQL.
It's not that hard to learn and it's faster and more flexible than ini-files.
In the beginning, I also didn't wanna learn MySQL because I thought my own saving system was good enough.
But once I learned the advantages of MySQL, I'll never go back to using files.
And don't worry over a few Mb of RAM nowadays.
Any modern pc has at least 4Gb of RAM onboard, servers even have more RAM.
My own pc has 12Gb of RAM.
Also, most modern games are at least 4Gb on your harddrive.
If you compare it to those games, what's 5Mb?
But still, even with so much RAM, you shouldn't waste it unneccessarily.
Only use what you need (24 cells for a playername, not 256), or go for account-id's instead if you use a database.
Looking at the code further down:
Look at the last 4 lines posted here.
It makes a variable "name" of 256 cells, it gets the playername (which is only 24 bytes for "pName"), stores it into "name" and copies it to the array.
If you reduce the field-size in the array to MAX_PLAYER_NAME instead of 256, you can use the code above.
There might be more places in that code where you make make such improvements.
If you take the array-size into account:
3500 indices x (256 cells for one field, 256 cells for another field) x 4 bytes per cell = 3500 x 512 x 4 = 7.168.000 bytes.
That's 6.8Mb for that array alone.
Like suggested earlier, only use the size for a playername (24 cells instead of 256).
Reducing this to it's proper size alone would give you an array of:
3500 x (24 + 24) x 4 = 3500 x 48 x 4 = 672.000 bytes or 656Kb.
It's 1/10th the size.
Or better yet:
Give every player a unique number as his ID (not the ingame playerid but an account-ID in your saving system).
Then you can replace those fields by an integer.
Your array would shrink to this size:
3500 indices x (1 cell for the first ID, 1 cell for the second ID) x 4 bytes per cell = 3500 x 2 x 4 = 28.000 bytes = 27Kb.
That's 256 times smaller than before and it still contains the same information.
Not the name of the player per se, but still his ID, which you can use to get the name from.
To make this effective, you should convert to MySQL.
It's not that hard to learn and it's faster and more flexible than ini-files.
In the beginning, I also didn't wanna learn MySQL because I thought my own saving system was good enough.
But once I learned the advantages of MySQL, I'll never go back to using files.
And don't worry over a few Mb of RAM nowadays.
Any modern pc has at least 4Gb of RAM onboard, servers even have more RAM.
My own pc has 12Gb of RAM.
Also, most modern games are at least 4Gb on your harddrive.
If you compare it to those games, what's 5Mb?
But still, even with so much RAM, you shouldn't waste it unneccessarily.
Only use what you need (24 cells for a playername, not 256), or go for account-id's instead if you use a database.
Looking at the code further down:
Код:
public PutDown(playerid) { PlayerPutDown[playerid] = false; FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; GetPlayerPos(playerid, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ]); FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] -= 1.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] = GetPlayerVirtualWorld(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fInt] = GetPlayerInterior(playerid); new name[256],pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); format(name, sizeof(name), "%s",pName); FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner]=name;
It makes a variable "name" of 256 cells, it gets the playername (which is only 24 bytes for "pName"), stores it into "name" and copies it to the array.
Код:
new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner] = pName;
There might be more places in that code where you make make such improvements.