.amx Size
#1

Hey all,

Just regarding the size of my .amx file ..

When I compile an 800kb script, the .amx file turns out to be just over 38mb. Would anyone be able to give me reasons as to why this happens and what I could maybe do to reduce the size of the .amx?

Appreciate it.
Reply
#2

Well, it's determined by a few things.. Are you using new string[256]; a lot, where it's not needed? Because that will dramatically increase your AMX size.
Reply
#3

What would you define as something 'Where it's not needed'?

Forgive me but I'm a beginner. Just started using strings recently.

But yes, my script does use a lot of [256] strings.
Reply
#4

It's quite alright, here, i'll give you an example.. Say you wanted to just send a message to everyone saying that someone has typed a command.

(Note: I use ZCMD, as you're a beginner, you probably made your command using OnPlayerCommandText, but it's still the base that counts.)

Correct:
pawn Code:
zcmd(test, playerid, params[])
{
    new string[128];
    new name;
    GetPlayerName(playerid, name, sizeof(name));
    SendClientMessageToAll(playerid, white, "%s has typed \"/TEST\"!", name); // The \" is used to make Quotation marks in-game, as using just " " would close your SendClientMessage.
    return 1;
}
Incorrect:
pawn Code:
zcmd(test, playerid, params[])
{
    new string[256];
    new name;
    GetPlayerName(playerid, name, sizeof(name));
    SendClientMessageToAll(playerid, white, "%s has typed \"/TEST\"!", name);
    return 1;
}
As i don't think you would need 256 cells in order to just tell everyone that someone has typed a command.

Also, consider breaking away from Strtok, and things like that, ZCMD and DCMD are the most effecient commands, and they're also very very powerful.

Example:

/SetHP using STRTOK = 19 Lines:
pawn Code:
if(strcmp(cmd, "/sethealth", true)==0||strcmp(cmd, "/sethp", true)==0)
    {
        new varhp;
        tmp=strtok(cmdtext,idx);
        if(strlen(tmp)==0) return SendClientMessage(playerid, COLOR_LB, "Syntax: /SetHP <Player ID/Part of Name> <Amount>");
        player = ReturnUser(tmp);
        tmp=strtok(cmdtext,idx);
        if(strlen(tmp)==0) return SendClientMessage(playerid, COLOR_LB, "Syntax: /SetHP <Player ID/Part of Name> <Amount>");
        varhp=strval(tmp);
        if(player != INVALID_PLAYER_ID)
        {
            if(PlayerInfo[playerid][pAdmin] >= 2)
            {
                SetPlayerHealth(player, varhp);
}
            else return SendClientMessage(playerid, COLOR_RED, "(Error): You're not an administrator! (Error Code: 45)");
}
        else return SendClientMessage(playerid, COLOR_RED, "(Error): Player does not exist.");
        return 1;
    }
/SetHP using ZCMD = 17 Lines.
pawn Code:
zcmd(sethp, playerid, params[])
{
    new player,hp;
    if(!sscanf(params, "ui", player, hp))
    {
        if(player != INVALID_PLAYER_ID)
        {
            if(PlayerInfo[playerid][pAdmin] >= 2)
            {
                SetPlayerHealth(player, hp);
            }
            else return SendClientMessage(playerid, red, "(Error): You're not an administrator!");
        }
        else return SendClientMessage(playerid, red, "(Error): Player does not exist.");
    }
    else return SendClientMessage(playerid, lb, "Syntax: /SetHP <Player ID/Part of Name> <Amount>");
    return 1;
}
Reply
#5

Quote:
Originally Posted by UberSocks
What would you define as something 'Where it's not needed'?

Forgive me but I'm a beginner. Just started using strings recently.

But yes, my script does use a lot of [256] strings.
Sorry for the double-post, but apparently my post has received the max-length, lol.

What types of commands have the [256] strings? Can you list them? (Don't copy-paste the whole command, just the syntax for it. E.G: /SetHP <Player ID/Part of Name> <Amount>)
Reply
#6

Quote:
Originally Posted by sizeof(Sky));
Quote:
Originally Posted by UberSocks
What would you define as something 'Where it's not needed'?

Forgive me but I'm a beginner. Just started using strings recently.

But yes, my script does use a lot of [256] strings.
Sorry for the double-post, but apparently my post has received the max-length, lol.

What types of commands have the [256] strings? Can you list them? (Don't copy-paste the whole command, just the syntax for it. E.G: /SetHP <Player ID/Part of Name> <Amount>)
My script is MySQL integrated, so I have used a lot of strings to send and receive data from the database such as queries etc. From skimming through the code, I have noticed that a lot of strings are used to display server information in the console, to which I have logged for several purposes.

For example, this is when a player has typed /deleteitem <Slot Number>

Code:
	new query[256];
	ConnectToDatabase();
	if(PlayerItemsInfo[playerid][slotid][piSQLId] != INVALID_SQL_ID)
	{
	  format(query,sizeof(query),"DELETE FROM players_items WHERE id=%d",PlayerItemsInfo[playerid][slotid][piSQLId]);
		if(mysql_query(query))
	  {
	    printf(" SQL: %s",query);
The only string throughout this part is query[256], and as you can see, is used to print in the server console. There are many alike throughout the entire script. Although there are others which have a different purpose in the script, they are basically used to call and receive information from the database.

Edit
---------------
I think I may have found my problem:

Code:
			new usage[100];
			format(usage, sizeof(usage), "USAGE: /recon [playername/id]");
			SendClientMessage(playerid, COLOR_WHITE, usage);
Reply
#7

Quote:
Originally Posted by UberSocks
Quote:
Originally Posted by sizeof(Sky));
Quote:
Originally Posted by UberSocks
What would you define as something 'Where it's not needed'?

Forgive me but I'm a beginner. Just started using strings recently.

But yes, my script does use a lot of [256] strings.
Sorry for the double-post, but apparently my post has received the max-length, lol.

What types of commands have the [256] strings? Can you list them? (Don't copy-paste the whole command, just the syntax for it. E.G: /SetHP <Player ID/Part of Name> <Amount>)
My script is MySQL integrated, so I have used a lot of strings to send and receive data from the database such as queries etc. From skimming through the code, I have noticed that a lot of strings are used to display server information in the console, to which I have logged for several purposes.

For example, this is when a player has typed /deleteitem <Slot Number>

Code:
	new query[256];
	ConnectToDatabase();
	if(PlayerItemsInfo[playerid][slotid][piSQLId] != INVALID_SQL_ID)
	{
	  format(query,sizeof(query),"DELETE FROM players_items WHERE id=%d",PlayerItemsInfo[playerid][slotid][piSQLId]);
		if(mysql_query(query))
	  {
	    printf(" SQL: %s",query);
The only string throughout this part is query[256], and as you can see, is used to print in the server console. There are many alike throughout the entire script. Although there are others which have a different purpose in the script, they are basically used to call and receive information from the database.
Yikes, I am not good with MySQL, haha. MySQL-wise, i'm actually not sure if you have to use that much of a string in order to send and receive the information; Sorry mate.
Reply
#8

Quote:
Originally Posted by UberSocks
Edit
---------------
I think I may have found my problem:

Code:
			new usage[100];
			format(usage, sizeof(usage), "USAGE: /recon [playername/id]");
			SendClientMessage(playerid, COLOR_WHITE, usage);
Just incase you didn't see that. But yes, I have a table for almost every aspect of my script, therefore information is being called quite often.
Reply
#9

Are you compiling with 0.3 includes? A lot of your arrays will increase because of the new limits (e.g. MAX_PLAYERS is now equal to 500, not 200), you can either decrease the max limits to a size that suits your server or live with the large AMX size :P.
Reply
#10

Quote:
Originally Posted by UberSocks
Quote:
Originally Posted by UberSocks
Edit
---------------
I think I may have found my problem:

Code:
			new usage[100];
			format(usage, sizeof(usage), "USAGE: /recon [playername/id]");
			SendClientMessage(playerid, COLOR_WHITE, usage);
Just incase you didn't see that. But yes, I have a table for almost every aspect of my script, therefore information is being called quite often.
A string isn't really needed for that, it's just taking up space. You can simply do
pawn Code:
SendClientMessage(playerid,COLOR_WHITE,"USAGE: /recon [playername/id]");
Reply
#11

good post, I sometimes messed around and created an infite loop (however it did 108 calls and got the error ), the function was calling itself. This can eventually lead to same kind of stack/heap problems. Just for people to know.

Mhm I rather knew this, that is why I use the CSTL vector plugin to handle large storage.

ByTheWay, didn't I read somewhere that #pragma dynamic won't help...?
Hmm. If I get such a message I always calculated the 2n bytes, so in a case where
26894935 is required I allocated in #pragma dynamic
33554432 bytes. (2x2x2....)
Reply
#12

Quote:

ByTheWay, didn't I read somewhere that #pragma dynamic won't help...?

It does help. An array wouldn't work correctly till I added a new dynamic value.
Код:
#pragma dynamic 100000
I'd love to do the right thing and fix the stack heap conflict, but It's hard looking through so much code to find the problem function(s). I failed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)