04.04.2016, 15:13
Hey!
I just realized something which may save some memory in my server. I don't know though, so I'm asking you.
Currently I have this on OnGameModeInit:
Then LoadBuilding looks like this:
I realized I'm actually sending a new query for every row in the database. Would it be better to send one query and use the loop to store data in the array like this?
I just realized something which may save some memory in my server. I don't know though, so I'm asking you.
Currently I have this on OnGameModeInit:
pawn Код:
for(new i=0; i <= MAX_BUILDINGS; i++) {
new query[100];
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `buildings` WHERE `ID`='%d'", i);
mysql_tquery(mysql, query, "LoadBuilding", "i", i);
}
pawn Код:
forward LoadBuilding(building);
public LoadBuilding(building) {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(!rows) return 1;
cache_get_field_content(0, "Name", BuildingInfo[building][bName], mysql, 64);
BuildingInfo[building][bOwner] = cache_get_field_content_int(0, "Owner");
BuildingInfo[building][bOwnedBy] = cache_get_field_content_int(0, "OwnedBy");
BuildingInfo[building][bInterior] = cache_get_field_content_int(0, "Interior");
BuildingInfo[building][bVirtualWorld] = cache_get_field_content_int(0, "VirtualWorld");
BuildingInfo[building][bSale] = cache_get_field_content_int(0, "Sale");
BuildingInfo[building][bPrice] = cache_get_field_content_int(0, "Price");
BuildingInfo[building][bID] = cache_get_field_content_int(0, "ID");
BuildingInfo[building][bEntreX] = cache_get_field_content_float(0, "EntreX");
BuildingInfo[building][bEntreY] = cache_get_field_content_float(0, "EntreY");
BuildingInfo[building][bEntreZ] = cache_get_field_content_float(0, "EntreZ");
BuildingInfo[building][bIntX] = cache_get_field_content_float(0, "IntX");
BuildingInfo[building][bIntY] = cache_get_field_content_float(0, "IntY");
BuildingInfo[building][bIntZ] = cache_get_field_content_float(0, "IntZ");
CreateBuildingPickup(building);
return 1;
}
I realized I'm actually sending a new query for every row in the database. Would it be better to send one query and use the loop to store data in the array like this?
pawn Код:
mysql_tquery(mysql, "SELECT * FROM `buildings`", "LoadBuilding");
pawn Код:
forward LoadBuilding();
public LoadBuilding() {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(!rows) return 1;
for(new i = 0; i <= rows; i++) {
cache_get_field_content(i, "Name", BuildingInfo[building][bName], mysql, 64);
BuildingInfo[i][bOwner] = cache_get_field_content_int(i, "Owner");
BuildingInfo[i][bOwnedBy] = cache_get_field_content_int(i, "OwnedBy");
BuildingInfo[i][bInterior] = cache_get_field_content_int(i, "Interior");
BuildingInfo[i][bVirtualWorld] = cache_get_field_content_int(i, "VirtualWorld");
BuildingInfo[i][bSale] = cache_get_field_content_int(i, "Sale");
BuildingInfo[i][bPrice] = cache_get_field_content_int(i, "Price");
BuildingInfo[i][bID] = cache_get_field_content_int(i, "ID");
BuildingInfo[i][bEntreX] = cache_get_field_content_float(i, "EntreX");
BuildingInfo[i][bEntreY] = cache_get_field_content_float(i, "EntreY");
BuildingInfo[i][bEntreZ] = cache_get_field_content_float(i, "EntreZ");
BuildingInfo[i][bIntX] = cache_get_field_content_float(i, "IntX");
BuildingInfo[i][bIntY] = cache_get_field_content_float(i, "IntY");
BuildingInfo[i][bIntZ] = cache_get_field_content_float(i, "IntZ");
CreateBuildingPickup(i);
}
return 1;
}