HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

H2I an other way ?

12-11-2007, 01:27 PM#1
Troll-Brain
Collapse JASS:
globals
    handle H
    integer I
endglobals

Collapse JASS:
function Trig_test_Actions takes nothing returns nothing
local integer I
local handle H
set I = 1 // any value

set H = GetTriggerUnit() 
// the last set variable type is converted in the first variable type for the first variable (I)
call BJDebugMsg(I2S(I))

endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( gg_trg_test, Player(0), true )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

I didn't test for all conversions but is it faster than call a H2I function ?

PS : The globals values dont change
12-11-2007, 01:35 PM#2
Vexorian
It is faster than I2S(H2I()) in the sense that you are always converting 1 to string.

Please, get a better example cause I don't understand what you want to say at all.
12-11-2007, 03:02 PM#3
Troll-Brain
the I2S was only for see i convert an handle to integer without using a function, so faster than use the bug return.

and btw i tried to converted an integer as a string and just test it that, that's very strange.
i've not the vocabulary for explain it

Collapse JASS:
globals
    integer I
    string S
    integer inc = -1
endglobals

Collapse JASS:
function Trig_test_Actions takes nothing returns nothing
local integer I
local string S
set inc = inc +1 
set S = null
set I = inc

call BJDebugMsg (S)


endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_test, 0.2 )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction
12-11-2007, 03:05 PM#4
cohadar
Quote:
Originally Posted by Troll-Brain
i've not the vocabulary for explain it

Pure wisdom. Have a beer.

first post:
Collapse JASS:
set I = 1 // any value
call BJDebugMsg(I2S(I))

third post:
Collapse JASS:
set S = null
call BJDebugMsg (S)

You know I never saw anyone with a more appropriate nickname....
12-11-2007, 03:31 PM#5
Troll-Brain
omg test before ! that won't display null ><
12-11-2007, 03:45 PM#6
Captain Griffen
What are the outputs you're getting? Tell us, or we'll ignore you.
12-11-2007, 03:47 PM#7
cohadar
Quote:
Originally Posted by Troll-Brain
omg test before ! that won't display null ><

so what?

Look why the hell you want to do this H2I "optimization" anyways.
Even if it could be done, witch I doubt it is still pointless because performance gain would be at best.. well small.

Maybe you should concentrate on making your map instead of making futile experiments.
12-11-2007, 04:07 PM#8
Troll-Brain
@cohadar :
http://wc3campaigns.net/showthread.php?t=98199
an usefull experiment

I just want to know if it's faster than use that :
set integer = H2I(handle)

and test the second example plz
12-11-2007, 04:17 PM#9
cohadar
Let me guess, it displays random strings from memory?

Anyone who has ever printed a bad string pointer in any programming language knows that.

Just forget about it and go do something useful ok.
12-11-2007, 04:44 PM#10
Troll-Brain
Quote:
Originally Posted by cohadar
Let me guess, it displays random strings from memory?

Anyone who has ever printed a bad string pointer in any programming language knows that.

Just forget about it and go do something useful ok.

no it's not random
12-11-2007, 04:56 PM#11
cohadar
Quote:
Originally Posted by Troll-Brain
no it's not random

Yes it is.
12-11-2007, 06:09 PM#12
Anitarf
I suppose the question is, which is faster?
Collapse JASS:
globals
    handle H
    integer I
endglobals

function Foo takes nothing returns nothing
    local integer I
    local handle H
    set I = 1
    set H = GetTriggerUnit() 
    call BJDebugMsg(I2S(I))
endfunction
...or...
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function Foo takes nothing returns nothing
    local integer I
    local handle H
    set H = GetTriggerUnit() 
    set I = H2I(H)
    call BJDebugMsg(I2S(I))
endfunction
The result is supposedly the same.
12-11-2007, 06:39 PM#13
Troll-Brain
ok thx Anitarf
12-11-2007, 06:45 PM#14
weaaddar
Quote:
Originally Posted by Anitarf
I suppose the question is, which is faster?
Collapse JASS:
globals
    handle H
    integer I
endglobals

function Foo takes nothing returns nothing
    local integer I
    local handle H
    set I = 1
    set H = GetTriggerUnit() 
    call BJDebugMsg(I2S(I))
endfunction
...or...
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function Foo takes nothing returns nothing
    local integer I
    local handle H
    set H = GetTriggerUnit() 
    set I = H2I(H)
    call BJDebugMsg(I2S(I))
endfunction
The result is supposedly the same.

Actually the second will be slightly slower ( 1 user function call vs 0 function calls). The union like thing is a confusing bug in warcraft 3 that may break at anytime.
The union bug has many known issues and can break local variables.

The return bug has a long history is unlikely to break.
12-11-2007, 06:53 PM#15
PipeDream
I seem to recall that using the union bug more than once in a function causes huge leaks.