Creating and Deleting Variables at run time?
Hey
Is there any way to create and delete variable at run time? Similar to malloc in C/C++ The plugin I am working on makes two different query_client_cvar calls and then prints the results to console on the same line. As far as I can tell this means that I have to store the results from the first call in a global variable until the second one has been done and then print both results at the same time. I would prefer to find a way to avoid using global variables since they will only be used very rarely and will just waste space the rest of the time. Thoughts? |
Re: Creating and Deleting Variables at run time?
Global Variables take up about 4 bytes more of memory then local variables. The only reason to use global over local is because global variables are 0'd on load of the plugin , while local's have to be 0'd during running. (correct me someone if im wrong )
ADDED : which meens that using global variables are less CPU exspensive. |
Re: Creating and Deleting Variables at run time?
pRED* | NZ: you can't remove a global variable from memory once it has been allocated. There's nothing horrible about global variables, they're much more hospitable than the plague even, get used to them.
The Specialist: from experience, I would say that every variable, when created, if not assigned a value, is assumed a value of 0 (or false). You don't need to assign it anything specifically, even if it's local. |
Re: Creating and Deleting Variables at run time?
I just thought having about 6 global variables that are only used rarely, permanently taking up memory space was a waste.
But if it's not really an issue i'll just leave it as is. Works fine as it is. :up: Thanks |
Re: Creating and Deleting Variables at run time?
First of all , HI:) .
2nd , Thats not what i was saying http://wiki.amxmodx.org/index.php/Optimizing_Plugins I was correct , global variables are 0'd on loading , and local variables are 0'd dynamical . read the global variable VS local variable part. :wink: |
Re: Creating and Deleting Variables at run time?
Quote:
Quote:
Globals permanently occupy memory space as long as the plugin is running (so 24/7 for most servers) and may only be in use for about 30 seconds total per day.. |
Re: Creating and Deleting Variables at run time?
but your missing the point , read the link i just posted here is a qoute from it . Dyamicly is a bad thing for varaibles , its slow an tedious (quote)
Code:
|
Re: Creating and Deleting Variables at run time?
Yes I understand that.
Local Variables = More cpu time when the function is run due to allocating memory, 0'ing it and then releasing it after the function is completed. Global Variables = More memory permanently taken up when it isn't needed. I was weighing up the two options and thought that locals would be preferable since the plugin would probably be called once an hour or most likely less. But don't worry since it isn't possible since query_client_cvar always returns the cvar value to a separate function. Thanks for the help though. :up: |
Re: Creating and Deleting Variables at run time?
np. :)
|
Re: Creating and Deleting Variables at run time?
Just to clarify thought in case ive missed something (first time doing pawn)
Code:
Thats the function that gets called by query_client_cvar and copies that cvar value into a global function. Theres no way to get that cvar value (const value[]) back into the main function without using a global variable? |
| All times are GMT -4. The time now is 22:19. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.