Talk:Optimizing Plugins (AMX Mod X Scripting)

From AlliedModders Wiki
Revision as of 01:54, 1 February 2006 by BAILOPAN (talk | contribs)
Jump to: navigation, search

Is there evidence that when something is const it's faster? I think this might be to the contrary, as the compiler has to copy it into the heap first to ensure that it isn't modified. -- BAILOPAN 00:54, 1 February 2006 (EST)

Whether or not const variables/arrays are copied to the heap depends on the situation:
For a function that has an array argument with a default value, the compiler allocates space for
the default array value on the heap. However, if the array argument (with a default value) is
also const, the pawn compiler passes the default array directly (there is no need to make a copy
on the heap here, as the function will not attempt to change the array argument and, thereby,
overwrite the default value).
The arguments of a function that has "variable arguments" (denoted with the ... operator, see
the pawn booklet "The Language") are always passed by reference. For constants and expressions
that are not lvalues, the compiler copies the values to a cell that is allocated from the heap,
and it passes the address of the cell to the function.
-Page 106 (PDF page 108) of "The Implentor's Guide"
Function insert copies in the other direction and it does not change its function argument item.
In such a case, it is advised to mark the function argument as "const". This helps the pawn parser
to both check for errors and to generate better (more compact, quicker) code.
-Page 21 (PDF page 23) of "The Language Guide"
--cybermind 01:24, 1 February 2006 (EST)


I see, thanks for the clarification. Twilight, I'd amend your part somewhat to mirror that. -- BAILOPAN 02:54, 1 February 2006 (EST)