[TUT] The Use of Stocks
What is a stock? Many people don't understand at all, and that's why I'm writing this.
A stock is basically a function or variable that, if not used anywhere in the script, is simply ignored by the compiler. Many people have the idea of doing this: Code:
When in fact you could achieve the same functionality through using this: Code:
So why are stocks used? Mostly for include files, where there are many functions and variables that are not used. Taken straight from engine_stocks.inc: Code:
So, let's say I use find_ent somewhere in my script (which I am not condoning, it is a deprecated function for backward compatibility with AMX). The find_ent function will be included in the overhead and execution of my script, but fakedamage will not be because it was not used anywhere. Stocks, as said twice above, can also be used on variables as such: Code:
Again, including this in your script is useless, but it is useful for an include file where a variable may or may not be used, without using a #define due to issues with pushing it onto the stack each time it is used. That's basically what stocks are and why they are useful. |
Re: The Use of Stocks
nice tut but so there is no diffrents with
Code:
Code:
|
Re: The Use of Stocks
Quote:
Not quite, I should clarify that the stock is public but the private function is not. If you use the stock outside and inside of the plugin, then make it public (ex. if you use it in set_task or query_client_cvar) However, if you just use it inside the plugin, you should always avoid using public or stock and instead just make it a private function. EDIT: What I said here is wrong, stocks are private. |
Re: The Use of Stocks
Quote:
stock variables are usefull! When you create big plugins, you declare most of the global variables at the begin. So you have many gobal variables but you aren't using all of them from begin. So when you compile it, you will get many warnings( "warning 203: symbol is never used" ) But with stock variables you will not get this warning, because the variables will not be created |
Re: The Use of Stocks
Quote:
|
Re: The Use of Stocks
then you use the variable and you get the error "error 017: undefined symbol".
But with a stock variable you will not have this problem ;) |
Re: The Use of Stocks
Stocks are not public. Furthermore, they are always parsed by the compiler ('stock' doesn't mean the compiler simply ignores it). The only difference between a stock and a normal function is that if it is unreferenced at assembly time, it is not included into the final code.
This is ideal for include files where users might not be using everything, and variables that might not be used (like Greenberet noted). |
Re: The Use of Stocks
Quote:
I don't see anything else wrong that I said other than that, and nothing wrong in the main post, so I'm not going to go through the hassle of changing anything (since editing code is still broken). |
Re: [TUT] The Use of Stocks
sorry for reviving a 4 year old thread, but what is the best to use? cause i don't understand it.
this Code:
stock something() Code:
something() |
Re: [TUT] The Use of Stocks
The only difference between a stock and a normal function is that if it is unreferenced at assembly time, it is not included into the final code.
|
All times are GMT -4. The time now is 05:41. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.