Talk:Optimizing Plugins (AMX Mod X Scripting)

From AlliedModders Wiki
Revision as of 10:03, 10 September 2007 by BAILOPAN (talk | contribs) (Talk:Optimizing Plugins moved to Talk:Optimizing Plugins (AMX Mod X Scripting))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Let's say i have Float:{233.594378, 345.634256, 1234.756464} array and i need reindex it two times. Two example:

if (array[0] > some_float_variable)
      x = 1.2 + array[0]

or

y = array[1] * array[1]

Would it be more efficient (in fact)?

new Float:temp = array[0]
if (temp > some_float_variable)
      x = 1.2 + temp

or

new Float:temp = array[1]
y = temp * temp

--VEN 08:32, 3 March 2006 (EST)

The bottom two are more efficient. However, it only really matters if you're repeating this computation a lot. If this is a one-time computation it won't make a difference. -- BAILOPAN 18:25, 3 March 2006 (EST)

Regarding NiLuJe's change of '\0' to 0: while they are both the same, keeping the syntax in terms of characters would probably be better for people to understand when dealing with strings, so I reverted the changes back.

Perhaps it should be changed to '^0'... by default we don't use \ for a backtick. This is probably what he meant to correct. -- BAILOPAN 18:55, 1 March 2006 (EST)
Ah, indeed, fixing that now --cybermind 02:39, 2 March 2006 (EST)

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)