• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Snippet] Bounty

BBQ

BBQ

Level 4
Joined
Jun 7, 2011
Messages
97
JASS:
                set m=null
                set z=null
Players don't leak, so there's no need to do that.
 
Actually, according to a friend of Bribe's, his map lagged until he nulled player handles.


I now null all handles.


The reason for this is because all handles, even if they are never destroyed, still count references.. what this means is that the ref counter just keeps going up and up and up and up =P.


yaaa, it's stupid =), but if you don't want a huge ref count, then you gotta null
 

BBQ

BBQ

Level 4
Joined
Jun 7, 2011
Messages
97
The reference count serves absolutely no purpose for agents that are never destroyed. That's exactly the case with players.

I just tried executing a function that had 12 local player variables in it (each pointing to a certain player, of course), 20000 executions with nulling and 20000 without. Guess what? There was no difference whatsoever.

And I have no idea what stuff Bribe's friend was on.
 

BBQ

BBQ

Level 4
Joined
Jun 7, 2011
Messages
97
My "Guess what? There was no difference whatsoever." was referring to, among other things, to the memory usage. But it's up to you.
 
Also, nulling all handles is a good programming practice.
Get used to it.
Just null everything.
In some very rare cases, even strings need to be 'nulled'.
JASS:
local integer i=0
loop
    exitwhen i>8190
    set s[i]="djipwejfiwejfewjpwje'okweewiljweligjfreioe;jroeoigtt/reokgkreg;iojtr;gjrtojiweijgrerjglreijlwgerihjwreoijgeriwjgrewoijewirojiwjiowjguwjgwjgoiwjoirjergjoirewjgrjeglksdjfijetiu4hreewjgkhuikhw7y"
    set i=i+1
endloop

That would leak a total of 1.8 MB 0.o (Equivalent to about 180 special effects)
 

BBQ

BBQ

Level 4
Joined
Jun 7, 2011
Messages
97
Also, nulling all handles is a good programming practice.
Get used to it.
Just null everything.
In some very rare cases, even strings need to be 'nulled'.
JASS:
local integer i=0
loop
    exitwhen i>8190
    set s[i]="djipwejfiwejfewjpwje'okweewiljweligjfreioe;jroeoigtt/reokgkreg;iojtr;gjrtojiweijgrerjglreijlwgerihjwreoijgeriwjgrewoijewirojiwjiowjguwjgwjgoiwjoirjergjoirewjgrjeglksdjfijetiu4hreewjgkhuikhw7y"
    set i=i+1
endloop

That would leak a total of 1.8 MB 0.o (Equivalent to about 180 special effects)
Okay now, I agree that it might be "good practice" to null players, but strings? You've got to be kidding me.

Each time a new string is used, it is cached and stored into a table for further access and usage. And they are never removed from the table during run-time. That is WC3's way of optimizing the speed at which strings are accessed and operations with them are done.

In your example, you don't create 8190 strings, but instead you create just a single one.

So I can safely tell you that nulling strings does absolutely nothing.
 
Each time a new string is used, it is cached and stored into a table for further access and usage. And they are never removed from the table during run-time. That is WC3's way of optimizing the speed at which strings are accessed and operations with them are done.

I never knew that :p
But still, you should null absolutely everything that extends a handle.
 
It makes sense, since it fits with the short name convention. (joke ofc)

I'm going to submit an empty resource and say it's the fastest resource :D

10553936.jpg
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Player reference counting doesn't do anything since they are never destroyed, so there is no point to nulling them : )

That makes sense , if ... we are not talking about jass :p

Also i know someone with a map which was (is ?) played and he says that players complained about lag/desync/memory usage/whatever (can't remember what lame thing)
He did nothing but nulled player locals and he said that was fixed.

To be honest i don't believe that much in it, even if he is not usually a liar, it's more likely he has missed something.

Moar safety is always good since the speed advantage of not nulling it is ridiculous.
 
Level 13
Joined
Mar 19, 2010
Messages
870
Ok, i checked your API but i've still a question.
If a unit dies i want to give the killer gold. For this i want to use a table, hashtable or an array. I'll see. In this object i want to save the unitId and the bounty. So if a unit die, i look in this obj and so i get the bounty. And now, how i use your Snippet to give the killer the bounty?

Reg.
Patrick
 
Don't get me wrong but isn't this somehow useless?
I really don't see any practical use of this, even WE newbies that code terrible triggers
using simple GUI can easily create decent bounty system that will with a little more work
even calculate experience, handle floating texts and so on.

And even if you wanted to do that above, simple small library or struct without external
required scripts won't be longer than maybe 40 lines of code if we keep things simple.

If we decide to register each unit type or even handle on it's own, it can increase size
but that's map maker decision.
 
This will register when regular bounty occurs and provide an interface for it. So this is useful as long as you use regular bounty. If you don't, you probably won't have as much of a use for it.

I understand what you mean though. In most cases, you'll want a custom bounty system. However, it is always nice to have scripts for these kinds of things in the off chance that someone needs it. :)
 
Top