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

Noob questions...


Post New Thread Reply   
 
Thread Tools Display Modes
PartialCloning
Senior Member
Join Date: Dec 2015
Old 05-25-2017 , 03:15   Re: Noob questions...
Reply With Quote #31

Quote:
Originally Posted by KliPPy View Post
Basically you use static locals if either you want the variable to retain its value or, as an optimization step, you have an array in a function that's called often.
Often is subjective, but really, I would consider it only per-frame or even more frequently called forwards. 0.1s rate is not often.
In the global scope, "static" keyword narrows the scope of the symbol to the file scope. Quite useful for include files. I guess it's not well-known, so there are include files that try to avoid global scope polution by prepending __ or such.
What about a touch hook that's constantly called? Would I use static or new to get the value of pev_iuser1? From what I understood, PRoSToTeM@ is saying new should be used because the variable is initialized in its creation.
PartialCloning is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-25-2017 , 05:12   Re: Noob questions...
Reply With Quote #32

Quote:
Originally Posted by PartialCloning View Post
What about a touch hook that's constantly called? Would I use static or new to get the value of pev_iuser1? From what I understood, PRoSToTeM@ is saying new should be used because the variable is initialized in its creation.
Probably wouldn't matter*. But if you are going to re-initialize the variable to some value each time before using it, like:
Code:
static variable;
variable = 5;
then don't use static.

* In case of new the right hand side will be pushed to the stack, and in the case of static, it will get loaded into an address in DATA. Both operations are 1 instruction worth.

Quote:
The only difference is that for new variables is used STACK instruction, but it shouldn't has significant overhead.
I just saw this post. Actually it looks like single-cell variables use PUSH.* to allocate. But they do use STACK to free, but it's just moving the pointer, as you already said.


What I found interesting just now is that there is a ZERO instruction which zeroes an address in DATA. So if you are going to initialize a variable to 0, like
Code:
static variable;
variable = 0;
it translates to
Code:
ZERO [variable]
so it's probably a tiny tiny bit faster than PUSH.C 0 in case of new.


But in my opinion, it all comes down to: unless you need a variable to be static because of its scope or you are dealing with arrays in a frequently called function, use new.

Last edited by klippy; 05-25-2017 at 05:29.
klippy is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-25-2017 , 10:49   Re: Noob questions...
Reply With Quote #33

Code:
public F() {     new var = 7;     server_print("%d", var); } public F2() {     static var;     var = 7;     server_print("%d", var); }

Code:
 0x108       PROC                        ; F
 0x10C       BREAK     
 0x110       BREAK     
 0x114       STACK                  -0x4
 0x11C       CONST.pri               0x7
 0x124       STOR.S.pri             -0x4
 0x12C       BREAK     
 0x130       ADDR.pri               -0x4
 0x138       PUSH.pri  
 0x13C       CONST.pri             0x178   ; str_006
 0x144       PUSH.pri  
 0x148       PUSH.C                  0x8
 0x150       SYSREQ.C       server_print
 0x158       STACK                   0xC
 0x160       STACK                   0x4
 0x168       ZERO.pri  
 0x16C       RETN      

 0x170       PROC                        ; F2
 0x174       BREAK     
 0x178       BREAK     
 0x17C       BREAK     
 0x180       CONST.pri               0x7
 0x188       STOR.pri              0x184   ; var
 0x190       BREAK     
 0x194       CONST.pri             0x184   ; var
 0x19C       PUSH.pri  
 0x1A0       CONST.pri             0x188   ; str_007
 0x1A8       PUSH.pri  
 0x1AC       PUSH.C                  0x8
 0x1B4       SYSREQ.C       server_print
 0x1BC       STACK                   0xC
 0x1C4       ZERO.pri  
 0x1C8       RETN
Also:
Code:
public F() {     new var1 = 7;     new var2 = 8;     new var3 = 9;     server_print("%d", var1, var2, var3); }

Code:
 0x108       PROC                        ; F
 0x10C       BREAK     
 0x110       BREAK     
 0x114       STACK                  -0x4
 0x11C       CONST.pri               0x7
 0x124       STOR.S.pri             -0x4
 0x12C       BREAK     
 0x130       STACK                  -0x4
 0x138       CONST.pri               0x8
 0x140       STOR.S.pri             -0x8
 0x148       BREAK     
 0x14C       STACK                  -0x4
 0x154       CONST.pri               0x9
 0x15C       STOR.S.pri             -0xC
 0x164       BREAK     
 0x168       ADDR.pri               -0xC
 0x170       PUSH.pri  
 0x174       ADDR.pri               -0x8
 0x17C       PUSH.pri  
 0x180       ADDR.pri               -0x4
 0x188       PUSH.pri  
 0x18C       CONST.pri             0x178   ; str_006
 0x194       PUSH.pri  
 0x198       PUSH.C                 0x10
 0x1A0       SYSREQ.C       server_print
 0x1A8       STACK                  0x14
 0x1B0       STACK                   0xC
 0x1B8       ZERO.pri  
 0x1BC       RETN
__________________

Last edited by PRoSToTeM@; 05-25-2017 at 10:52.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-25-2017 , 11:28   Re: Noob questions...
Reply With Quote #34

That doesn't seem right. I'm sure
Code:
 0x114       STACK                  -0x4
 0x11C       CONST.pri               0x7
 0x124       STOR.S.pri             -0x4
should be
Code:
 PUSH.C 0x7
did you disable optimizations?
klippy is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-25-2017 , 12:13   Re: Noob questions...
Reply With Quote #35

Quote:
Originally Posted by KliPPy View Post
did you disable optimizations?
Nope, can you compile it yourself and upload?
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-25-2017 , 12:25   Re: Noob questions...
Reply With Quote #36

Code:
D:\Portable Programs\amxxdump>amxxpc untitled.sma
AMX Mod X Compiler 1.8.3-dev+5067
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2013 AMX Mod X Team

Header size:            176 bytes
Code size:              172 bytes
Data size:               48 bytes
Stack/heap size:      16384 bytes
Total requirements:   16780 bytes
Done.

D:\Portable Programs\amxxdump>amxxdump -d -l -j -e untitled.amxx

0x8                        PROC              ; public F()
0xC                       BREAK              ; untitled.sma:2
0x10                      BREAK              ; untitled.sma:3
                                             ; new var
0x14                     PUSH.C  0x7         ; 0x0
0x1C                      BREAK              ; untitled.sma:4
0x20                   PUSH.ADR  0xFFFFFFFC  ; var
0x28                     PUSH.C  0x14        ; "%d"
0x30                     PUSH.C  0x8
0x38                   SYSREQ.C  0x0         ; server_print
0x40                      STACK  0xC         ; free 3 cells
0x48                      STACK  0x4         ; free 1 cells
0x50                   ZERO.pri
0x54                       RETN
0x58                       PROC              ; public F2()
0x5C                      BREAK              ; untitled.sma:7
0x60                      BREAK              ; untitled.sma:8
                                             ; static var
0x64                      BREAK              ; untitled.sma:9
0x68                  CONST.pri  0x7         ; 0x0 (0.00000)
0x70                   STOR.pri  0x20        ; var
0x78                      BREAK              ; untitled.sma:10
0x7C                     PUSH.C  0x20        ; var 0x0
0x84                     PUSH.C  0x24        ; "%d"
0x8C                     PUSH.C  0x8
0x94                   SYSREQ.C  0x0         ; server_print
0x9C                      STACK  0xC         ; free 3 cells
0xA4                   ZERO.pri
0xA8                       RETN

D:\Portable Programs\amxxdump>
Also, this should really be optimized out lol:
Code:
0x40                      STACK  0xC         ; free 3 cells
0x48                      STACK  0x4         ; free 1 cells
Attached Files
File Type: sma Get Plugin or Get Source (untitled.sma - 239 views - 166 Bytes)
File Type: amxx untitled.amxx (771 Bytes, 60 views)

Last edited by klippy; 05-25-2017 at 12:26.
klippy is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-25-2017 , 14:16   Re: Noob questions...
Reply With Quote #37

Removed -d3 now it's ok for me.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-25-2017 , 14:48   Re: Noob questions...
Reply With Quote #38

Quote:
Originally Posted by PRoSToTeM@ View Post
Removed -d3 now it's ok for me.
Yes, higher debug levels also disable otpimization.
Code:
        -d0      no symbolic information, no run-time checks
        -d1      [default] run-time checks, no symbolic information
        -d2      full debug information and dynamic checking
        -d3      full debug information, dynamic checking, no optimization
klippy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-25-2017 , 16:02   Re: Noob questions...
Reply With Quote #39

O.o What is that?
__________________








CrazY. is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-31-2017 , 06:44   Re: Noob questions...
Reply With Quote #40

How to remove the "bomb" text from player name on tab window?
__________________








CrazY. 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 07:45.


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