AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Simple Slots Reservation (https://forums.alliedmods.net/showthread.php?t=231839)

Jhob94 10-13-2014 16:02

Re: Simple Slots Reservation
 
Quote:

Originally Posted by Arkshine (Post 2210466)
Some thoughts while I'm passing here:
  • Use formatex. Actually since you don't use arguments, I don't see why you're using vformat.
  • No reason to use static on admins.
  • This would be welcomed you add some comments in your plugin about what does the plugin, listing/explaining cvars.

Made even better :up:

Arkshine 10-13-2014 16:10

Re: Simple Slots Reservation
 
Well, if I had one last complaint, is PLUGIN and VERSION are used three times, you should use new const here. Just better memory management. :mrgreen:

Jhob94 10-13-2014 16:17

Re: Simple Slots Reservation
 
Quote:

Originally Posted by Arkshine (Post 2210725)
Well, if I had one last complaint, is PLUGIN and VERSION are used three times, you should use new const here. Just better memory management. :mrgreen:

I never really understood the difference between using define and const for this things. I know this isn't a scripting help forum, but can you explain me or pm why?
Once i used scripting help forum and i got solution but then someone asked why i did like that and not the other way and i didn't knew why. Since that day i like to know the whys. Some people got "spammed" with stupid scripting questions :twisted:

Edit:
Updated! And i have a feeling that i am gonna get banned :mrgreen:

Backstabnoob 10-13-2014 16:46

Re: Simple Slots Reservation
 
It's simple, define is a preprocessor directive which is replaced during compilation. So if you #define SOME_STRING "some_string" and use it either in a function that is called frequently or on multiple places, the memory will be allocated (and free'd) each time the string is used, which is a waste of computing power (not that it really matters, though).

Where as with a constant, the memory is allocated only once when the constant is initialized and stays in memory until it is free'd. Using the constant will point to the memory rather than reallocate it, which can potentionally save memory operations at the cost of constant memory usage.

Arkshine 10-13-2014 16:51

Re: Simple Slots Reservation
 
Code:
#define PLUGIN "Simple Slots Reservation" #define VERSION "0.0.6"

After compilation, same string is replaced everywhere.
Compiler allocates 3 times the same string:

Code:
public plugin_init() {     register_plugin("Simple Slots Reservation", "0.0.6", "Jhob94")     register_cvar("Simple Slots Reservation", "0.0.6", FCVAR_SPONLY|FCVAR_SERVER)     set_cvar_string("Simple Slots Reservation", "0.0.6") }


VS


Code:
new const PLUGIN[] = "Simple Slots Reservation"; new const VERSION[] = "0.0.6";

After compilation, string is allocated one time and this will use references
anywhere string is repeated.

Code:
public plugin_init() {     register_plugin(referenceString_1, referenceString_2, "Jhob94")     register_cvar(referenceString_1, referenceString_2, FCVAR_SPONLY|FCVAR_SERVER)     set_cvar_string(referenceString_1, referenceString_2) }


Basically, if you have a string which is referenced more than one time, this is good idea to use new const


EDIT: Shit, ninja'd! \o/

Though I'm not sure to agree to
Quote:

the memory will be allocated (and free'd) each time the string is used, which is a waste of computing power (not that it really matters, though).
Maybe I've misunderstood, but string is allocated one time and is referenced anyway by an address ; the point is just for a same string repeated x times, plugin will allocate x times with a x addresses.

Jhob94 10-13-2014 16:58

Re: Simple Slots Reservation
 
Roger that, thanks both :)

Updated

Backstabnoob 10-13-2014 17:00

Re: Simple Slots Reservation
 
Quote:

Originally Posted by Arkshine
Maybe I've misunderstood, but string is allocated one time and is referenced anyway by an address ; the point is just for a same string repeated x times, plugin will allocate x times with a x addresses.

That's good information, thanks.

Arkshine 10-13-2014 17:01

Re: Simple Slots Reservation
 
While you are on it, here the french translation with accents:

Code:

[fr]
DROPPED_RES = Désolé, un admin vient de prendre sa place réservée, tu as été éjecté du serveur.


Jhob94 10-13-2014 17:05

Re: Simple Slots Reservation
 
Quote:

Originally Posted by Arkshine (Post 2210753)
While you are on it, here the french translation with accents:

Code:

[fr]
DROPPED_RES = Désolé, un admin vient de prendre sa place réservée, tu as été éjecté du serveur.


This is ML from default amxx system. I don't think it's a good idea to change it here, people shouldn't be forced to replace it. I just uploaded for the case someone lost the file somehow.

Arkshine 10-13-2014 17:24

Re: Simple Slots Reservation
 
Ah. Then you should not attach it, because if file is changed upstream (which is going to be the case), people will think it's the right version and will replace it. There is no reason to attach it really. Don't bother with it. :P


All times are GMT -4. The time now is 01:03.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.