Moin, habe leider das Problem das ich meine Datenbank im Script erstellen möchte und somit einen recht langen String brauche.
Um dieses String hier zu erstellen wird sehr viel vom Stack benötigt, hier nochmal die Infos dazu:
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
Header size: 2836 bytes
Code size: 71848 bytes
Data size: 59308 bytes
Stack/heap size: 16384 bytes; estimated max. usage=5051 cells (20204 bytes)
Total requirements: 150376 bytes
SERVER LOG:
[debug] Run time error 3: "Stack/heap collision (insufficient stack size)"
[debug] Stack pointer (STK) is 0xD928, heap pointer (HEA) is 0xE7AC
[debug] AMX backtrace:
[debug] #0 0000977c in ?? () in altis-life.amx
[debug] #1 00006a9c in public SSCANF_OnGameModeInit () in altis-life.amx
[debug] #2 00000e98 in public zcmd_OnGameModeInit () in altis-life.amx
[debug] #3 native CallLocalFunction () in samp-server.exe
[debug] #4 0000977c in ?? () in altis-life.amx
[debug] #5 00006a9c in public SSCANF_OnGameModeInit () in altis-life.amx
[debug] #6 00000e98 in public BCRYPT_OnGameModeInit () in altis-life.amx
[debug] #7 native CallLocalFunction () in samp-server.exe
[debug] #8 0000977c in ?? () in altis-life.amx
[debug] #9 00006a9c in public SSCANF_OnGameModeInit () in altis-life.amx
[debug] #10 00000e98 in public OnGameModeInit () in altis-life.amx
Alles anzeigen
Jemand eine Ahnung, wie man sowas Stack/heap effizienter lösen könnte, ohne den Code sehr zu verunstalten?
/*
*
* Diese Funktion erstellt die 'users' Tablle in der Datebank, falls sie noch nicht existiert
* Dieses Callback benutzt den Return-Wert nicht.
*
*/
stock CreateUserTable() {
new query[2500], query2[2500];
format(query2, sizeof(query2), "\
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'unique user id',\
`name` VARCHAR(20) NOT NULL COMMENT 'user name (unique)' COLLATE 'utf8mb4_general_ci',\
`password` VARCHAR(61) NOT NULL COMMENT 'password (bcrypt encrypted)' COLLATE 'utf8mb4_general_ci',\
`salt` VARCHAR(11) NOT NULL COMMENT 'unique salt to protect password' COLLATE 'utf8mb4_general_ci',\
`cash` INT(11) NOT NULL DEFAULT '0' COMMENT 'money (cash)',");
format(query2, sizeof(query2), "\
%s`bank` INT(11) NOT NULL DEFAULT '0' COMMENT 'money (on bank-account)',\
`skin` INT(11) NOT NULL DEFAULT '88' COMMENT 'skin model',\
`weapon0` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 0',\
`ammo0` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 0',\
`weapon1` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 1',\
`ammo1` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 1',\
PRIMARY KEY (`id`) USING BTREE", query2);
format(query2, sizeof(query2), "\
%s`weapon2` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 2',\
`ammo2` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 2',\
`weapon3` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 3',\
`ammo3` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 3',\
`weapon4` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 4',\
`ammo4` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 4',\
PRIMARY KEY (`id`) USING BTREE", query2);
format(query2, sizeof(query2), "\
%s`weapon5` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 5',\
`ammo5` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 5',\
`weapon6` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 6',\
`ammo6` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 6',\
PRIMARY KEY (`id`) USING BTREE", query2);
format(query2, sizeof(query2), "\
%s`weapon7` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 7',\
`ammo7` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 7',\
`weapon8` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 8',\
`ammo8` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 8',\
PRIMARY KEY (`id`) USING BTREE", query2);
format(query2, sizeof(query2), "\
%s`weapon9` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 9',\
`ammo9` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 9',\
`weapon10` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 10',\
`ammo10` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 10',\
PRIMARY KEY (`id`) USING BTREE", query2);
format(query2, sizeof(query2), "\
%s`weapon11` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 11',\
`ammo11` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 11',\
`weapon12` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 12',\
`ammo12` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 12',\
PRIMARY KEY (`id`) USING BTREE", query2);
printf("query2: %d", strlen(query2)); // 2311
mysql_format(dbhandle, query, sizeof(query), "CREATE TABLE IF NOT EXISTS `users` (%s)\
COMMENT='all user informations'\
COLLATE='utf8mb4_general_ci'\
ENGINE=InnoDB;", query2);
printf("query: %d", strlen(query)); // 2421
mysql_tquery(dbhandle, query);
return true;
}
Alles anzeigen
PS: Ja, ich kenne #pragma dynamic, dies würde wohl auch funktionieren, jedoch bin ich hier auf der Suche nach anderen Codeansätzen zur Umsetzung.
// EDIT
Grade gemerkt das ich auch noch nen kleinen Copy & Paste Fehler drin hatte, konnte so nun und dank der Hilfe von Kaliber den Code start reduzieren und auch den Stack somit nicht mehr allzudoll zu belasten
/*
*
* Diese Funktion erstellt die 'users' Tablle in der Datebank, falls sie noch nicht existiert
* Dieses Callback benutzt den Return-Wert nicht.
*
*/
stock CreateUserTable() {
new query[2500];
format(query, sizeof(query), "\
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'unique user id',\
`name` VARCHAR(20) NOT NULL COMMENT 'user name (unique)' COLLATE 'utf8mb4_general_ci',\
`password` VARCHAR(61) NOT NULL COMMENT 'password (bcrypt encrypted)' COLLATE 'utf8mb4_general_ci',\
`salt` VARCHAR(11) NOT NULL COMMENT 'unique salt to protect password' COLLATE 'utf8mb4_general_ci',\
`cash` INT(11) NOT NULL DEFAULT '0' COMMENT 'money (cash)',");
format(query, sizeof(query), "\
%s`bank` INT(11) NOT NULL DEFAULT '0' COMMENT 'money (on bank-account)',\
`skin` INT(11) NOT NULL DEFAULT '88' COMMENT 'skin model',\
`weapon0` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 0',\
`ammo0` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 0',\
`weapon1` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 1',\
`ammo1` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 1',", query);
format(query, sizeof(query), "\
%s`weapon2` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 2',\
`ammo2` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 2',\
`weapon3` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 3',\
`ammo3` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 3',\
`weapon4` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 4',\
`ammo4` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 4',", query);
format(query, sizeof(query), "\
%s`weapon5` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 5',\
`ammo5` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 5',\
`weapon6` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 6',\
`ammo6` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 6',\
`weapon7` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 7',\
`ammo7` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 7',", query);
format(query, sizeof(query), "\
%s`weapon8` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 8',\
`ammo8` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 8',\
`weapon9` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 9',\
`ammo9` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 9',\
`weapon10` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 10',\
`ammo10` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 10',", query);
format(query, sizeof(query), "\
%s`weapon11` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 11',\
`ammo11` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 11',\
`weapon12` INT(11) NOT NULL DEFAULT '0' COMMENT 'weapon slot 12',\
`ammo12` INT(11) NOT NULL DEFAULT '0' COMMENT 'ammo slot 12',\
PRIMARY KEY (`id`) USING BTREE", query);
mysql_format(dbhandle, query, sizeof(query), "CREATE TABLE IF NOT EXISTS `users` (%s)\
COMMENT='all user informations'\
COLLATE='utf8mb4_general_ci'\
ENGINE=InnoDB;", query);
//printf("query: %d", strlen(query)); // 2271
mysql_tquery(dbhandle, query);
return true;
}
Alles anzeigen