New allocates memory for new variable, sets allocated memory to 0's and then, after function is over, frees memory (destroyes variable). It does so every time function is called.
Static allocates memory just once and keeps variable.
If your function is used often or you allocate big amount of data (and function is used more than at least once) its wiser to use static.
If your function isn't used often it's better to use new, so memory used by variables from your function, when function done executing will be freed.
I don't know about pawn, but using new in extremly oftenly called functions will cause memory fragmentation in some languages, not to mention perfomance reduction. On other hand, the more static you use, the more memory your plugin will use for sure.
I prefer to go with static in most cases.
Here is small example. Like in regular functions, variables declared in for(){} statement are destroyed after statement done executing:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your code here...
for (new i=0;i<100;i++)
server_print("\n%d",i)
server_print("%d",i) // You will get Error: Undefined symbol "i" on line 17, because "i" is already freed (destroyed)
}
The only difference between for(){} and regular functions is that you can't use static in it. Same goes for while (){} statement.
__________________