Difference between revisions of "Talk:Optimizing Plugins (AMX Mod X Scripting)"

From AlliedModders Wiki
Jump to: navigation, search
m
m
Line 15: Line 15:
 
:-Page 106 (PDF page 108) of "The Implentor's Guide"
 
:-Page 106 (PDF page 108) of "The Implentor's Guide"
  
:<tt>Function insert copies in the other direction and it does not change its function argument item.
+
:<tt>Function <i>insert</i> 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
 
: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.</tt>
 
:to both check for errors and to generate better (more compact,  quicker) code.</tt>
 
:-Page 21 (PDF page 23) of "The Language Guide"
 
:-Page 21 (PDF page 23) of "The Language Guide"
 
:--[[User:CyberMind|cybermind]] 01:24, 1 February 2006 (EST)
 
:--[[User:CyberMind|cybermind]] 01:24, 1 February 2006 (EST)

Revision as of 01:25, 1 February 2006

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)