Raised This Month: $ Target: $400
 0% 

a little difference of AMX to AMXX


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Terran
New Member
Join Date: Mar 2004
Location: Ulm, Germany
Old 03-28-2004 , 11:30   a little difference of AMX to AMXX
Reply With Quote #1

At AMX strings got initialized to "" (if not set otherwise), AMXX doesn't do that. Therefore you get garbage if you don't initialize them before usage.
I noticed this while I tried to get psychosounds to work with AMXX.
__________________
one head cannot contain all wisdom
Terran is offline
BAILOPAN
Join Date: Jan 2004
Old 03-28-2004 , 11:36  
Reply With Quote #2

hrm that is strange that the new machine would not have that garbage collection. But, why would you be using unitialized strings?
__________________
egg
BAILOPAN is offline
MagicShot
Senior Member
Join Date: Mar 2004
Location: MN
Old 03-28-2004 , 11:38   htm
Reply With Quote #3

Terran: what do you mean by unitlized stings?
__________________
|v|agic$hot
.
Without a Sound
MagicShot is offline
Send a message via MSN to MagicShot Send a message via Yahoo to MagicShot
BAILOPAN
Join Date: Jan 2004
Old 03-28-2004 , 11:40  
Reply With Quote #4

new string[24]

every member of the array is set to 0 automatically
in languages without garbage collection, the array has garbage data found randomly in memory
__________________
egg
BAILOPAN is offline
MagicShot
Senior Member
Join Date: Mar 2004
Location: MN
Old 03-28-2004 , 11:42   Hrmm
Reply With Quote #5

Ahh.. do you have to make your own garbage file or something?
__________________
|v|agic$hot
.
Without a Sound
MagicShot is offline
Send a message via MSN to MagicShot Send a message via Yahoo to MagicShot
BAILOPAN
Join Date: Jan 2004
Old 03-28-2004 , 11:44  
Reply With Quote #6

huh?

no it's like this:
new string[24]
client_print(0, print_chat, string) //will print nonsense
do this:
string[0] = 0
to initialize it
__________________
egg
BAILOPAN is offline
MagicShot
Senior Member
Join Date: Mar 2004
Location: MN
Old 03-28-2004 , 11:53   hrm
Reply With Quote #7

So if you don't initilize a sting before the use it will just print garbage..
__________________
|v|agic$hot
.
Without a Sound
MagicShot is offline
Send a message via MSN to MagicShot Send a message via Yahoo to MagicShot
Terran
New Member
Join Date: Mar 2004
Location: Ulm, Germany
Old 03-29-2004 , 02:44  
Reply With Quote #8

Well, it's not my plugin, it's the plugin "psychosounds".
This plugin worked without explicit string initialization at AMX but not at AMXX.
__________________
one head cannot contain all wisdom
Terran is offline
XAD
Senior Member
Join Date: Mar 2004
Location: Sweden
Old 03-29-2004 , 03:01  
Reply With Quote #9

Quote:
Originally Posted by BAILOPAN
hrm that is strange that the new machine would not have that garbage collection. But, why would you be using unitialized strings?
Bailopan, garbage collection is something else. Garbage collection is releasing (free) unused/unreferenced memory which is done automaticly in the background in Java... In Small there is no garbage collection nor any use of it as you can't allocate memory at runtime (local variables on the stack is not real "memory" allocation).

This topic is about uninitialized variable definitions. In C/C++ any variable or array is uninitialized and must be treated as such in the code especially these pesky terminating string zero). In AMXmod OLO defaulted the compiler to initialize all variables and arrays to zeroes, which is very important as the string functions in Small is depending on terminating zero (same as for C/C++) but also support packed strings which complicates things (as not only the last char must be zero but the last cell).

/X

PS! OLO did an attemp to switch of this zero initialization in a later version (after 0.9.3) which improved the performance quite well but unfortenately caused a havoc among other plugins, as they were coded based on the zero initialization (actually a lot of them didn't know this technicality but were either new to programming or only lazy).

When I first found out this initialization stuff I recoded StatsX using global buffers as this would improve performance as they then wouldn't then need to re-initialized for every function call (plus using format instead of add). OLO later also changed "stats" to use both this changes (but he probably found it it out by himself, it's not brain surgery).
XAD is offline
BAILOPAN
Join Date: Jan 2004
Old 03-29-2004 , 03:07  
Reply With Quote #10

XAD: hrm I guess I should not tie the two concepts together ;] I assumed that languages with garbage collection would also initialize to null

Maybe we should keep zero termination early-on to force it...
__________________
egg
BAILOPAN 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 04:58.


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