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

Strings and macros


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-13-2013 , 19:41   Strings and macros
Reply With Quote #1

Don't know where, but I saw that it's better to store strings in constants, than macros, because macros will replace every term with the desired string, and that would increase the data stored in the plugin.

So, I've just done to myself a question:

By doing this:

PHP Code:
#define PLUGIN "Shitworld"

//...

register_plugin(PLUGIN, [...]) 
The word "Shitworld" would be stored on the plugin "2" times, or just 1 time?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-14-2013 , 00:36   Re: Strings and macros
Reply With Quote #2

PLUGINis replaced 1 time, i don't think it subsist a track of macros after compilation, so string should be stored only 1 time in your case.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 11-14-2013 at 00:37.
ConnorMcLeod is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 11-14-2013 , 12:24   Re: Strings and macros
Reply With Quote #3

https://forums.alliedmods.net/showthread.php?t=188591
http://forums.alliedmods.net/showthread.php?t=158711
dFF is offline
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 11-15-2013 , 18:49   Re: Strings and macros
Reply With Quote #4

PHP Code:
#include <amxmodx>

#define LOL "zomg!"

public plugin_init()
{
    
server_print(LOL);
    
server_print(LOL);
    
server_print(LOL);
    
server_print(LOL);

Let's compile and open this plugin with AMX Disassembler (http://amx-x.ru/viewtopic.php?f=21&t=311). Result:

PHP Code:
.DATA
    str_000 string 
"zomg!"
    
str_001 string "zomg!"
    
str_002 string "zomg!"
    
str_003 string "zomg!"


.CODE
    halt                 0x0

PROC  plugin_init
    
break     
    break     
    
push.c               0x0
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    
break     
    
push.c           str_001  ;  ref to String  
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    
break     
    
push.c           str_002  ;  ref to String  
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    
break     
    
push.c           str_003  ;  ref to String  
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    zero
.pri  
    retn      
ENDP 
And this:
PHP Code:
#include <amxmodx>

new const LOL[] = "zomg!";

public 
plugin_init()
{
    
server_print(LOL);
    
server_print(LOL);
    
server_print(LOL);
    
server_print(LOL);

PHP Code:
.DATA
    _
:LOL array 0x7A 0x6F 0x6D 0x67 0x21 0x0 )


.
CODE
    halt                 0x0

PROC  plugin_init
    
break     
    break     
    
push.c               0x0
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    
break     
    
push.c               0x0
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    
break     
    
push.c               0x0
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    
break     
    
push.c               0x0
    push
.c               0x4
    sysreq
.c     server_print
    stack                0x8
    zero
.pri  
    retn      
ENDP 
And so it's better to store strings in constants, than macros.
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-15-2013 , 21:40   Re: Strings and macros
Reply With Quote #5

I think

PHP Code:
_:LOL array 0x7A 0x6F 0x6D 0x67 0x21 0x0 


It is translated to

PHP Code:
LOL[] = "zomg!"
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-15-2013 , 23:08   Re: Strings and macros
Reply With Quote #6

Quote:
Originally Posted by ^SmileY View Post
I think

PHP Code:
_:LOL array 0x7A 0x6F 0x6D 0x67 0x21 0x0 


It is translated to

PHP Code:
LOL[] = "zomg!"
Yes, so what is your point?
__________________
fysiks is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 11-15-2013 , 23:26   Re: Strings and macros
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
Yes, so what is your point?
Because fad that is turning this place of wanting protection plugin and not spend the source code: x
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-16-2013 , 00:06   Re: Strings and macros
Reply With Quote #8

Quote:
Originally Posted by ^SmileY View Post
Because fad that is turning this place of wanting protection plugin and not spend the source code: x
That statement makes absolutely no sense (looks like a bunch of random words).
__________________

Last edited by fysiks; 11-16-2013 at 00:07.
fysiks is offline
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 11-16-2013 , 00:26   Re: Strings and macros
Reply With Quote #9

Quote:
Originally Posted by ^SmileY View Post
I think

PHP Code:
_:LOL array 0x7A 0x6F 0x6D 0x67 0x21 0x0 


It is translated to

PHP Code:
LOL[] = "zomg!"
Spoiler
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
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 06:11.


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