Raised This Month: $51 Target: $400
 12% 

Solved stock vs functions


Post New Thread Reply   
 
Thread Tools Display Modes
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 10-04-2016 , 07:30   Re: stock vs functions
Reply With Quote #11

Quote:
Originally Posted by shavit View Post
I'm probably wrong, but what I remember is stock essentially 'pasting' the lines of code inside the stock to where ever I use it, so I assume that calling a function will take more time to process on the server side
You sort of got that confused.

A stock is a function typically in an .inc file that the preprocessor will just copy and paste from the inc file to your plugin. The entire function is copied (including its header), not just the body. You can have an inc file full of a bunch of stock functions and then use #include to include them in many plugins. The preprocessor will copy all those stock functions to your plugin, but won't compile them unless they are actually used (reduces code size).

The macros (also handled by the preprocessor) is what pastes the body of the code inside the function (inlines the function body).

Both of these involve some sort of copypasta but one does copypasta of the whole function and another does copypasta of just its body.

You use "public" for functions that need to be triggered by an outside source, like an extension or another plugin (think SQL_TQuery, native callbacks, or OnGameFrame), and can use stock for practically everything else.

Last edited by Potato Uno; 10-04-2016 at 07:30. Reason: fixed typo
Potato Uno is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 10-04-2016 , 10:58   Re: stock vs functions
Reply With Quote #12

Quote:
Originally Posted by Potato Uno View Post
You sort of got that confused.

A stock is a function typically in an .inc file that the preprocessor will just copy and paste from the inc file to your plugin. The entire function is copied (including its header), not just the body. You can have an inc file full of a bunch of stock functions and then use #include to include them in many plugins. The preprocessor will copy all those stock functions to your plugin, but won't compile them unless they are actually used (reduces code size).

The macros (also handled by the preprocessor) is what pastes the body of the code inside the function (inlines the function body).

Both of these involve some sort of copypasta but one does copypasta of the whole function and another does copypasta of just its body.

You use "public" for functions that need to be triggered by an outside source, like an extension or another plugin (think SQL_TQuery, native callbacks, or OnGameFrame), and can use stock for practically everything else.
"#include" is what actually has a file's contents copied into a plugin, not the "stock" keyword, basebans.sp is a good example of that.
stock is a keyword handled during that actual compile process (sp code into sp byte code process) which tells the compiler to reduce file size by excluding function IF IT's not being used.
__________________
WildCard65 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:38.


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