Do you have to nullify a "handle" variable, too?

N-a-z-g-u-l

New Member
Reaction score
30
i was just wondering if you have to nullify a variable of type "handle", too... or if you have to do it only with all types extending handle...

because if you have to nullify them, then you could create a quite safe system, but not specific for only one handle type...
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
All destructables, units, special effects, lightnings, etc. are handles.

Handles are not destructables, units, special effects, lightnings, etc.

JASS:
function test takes handle h returns nothing


Can take destructables, units, etc.
JASS:
function test2 takes destructable d returns nothing


CANNOT take a handle.

You also cannot compare handles to destructables, units etc.

What system do you think of making?
 

SFilip

Gone but not forgotten
Reaction score
634
Yes, you need to null handles too.
 

N-a-z-g-u-l

New Member
Reaction score
30
ok thanks...

and what kind of system: ive made a system (mostly for myself) which returns a valid array index from a timer given to it, can get the array index back, if it knows the timer, and clears the array index... basically working like ABC

now i wanted to attach things to triggers, too, and i wondered if it was possible to replace all timer variables with handle variables without loosing the safety having the variable in a global variable... so no other new handle will overwrite that id...
and if you have to nullify handle-type variables, too, that means, that if you have still saved them somewhere in a variable, their handle id wont be given to a new object

for those interested in the system:
for the new version ive stolen one idea of ABC: it does not begin looping at front of the array, if it reaches index 8192... this makes the loop faster, and because i only give indexes up to 8100, there shouldnt be any problems with that...
(i made that one in notepad, so it does not have to be free of mistakes)

and note that this is nothing everyone has to use because it is uber fast, safe, easy and so on... it just fits my needs
JASS:
globals
	handle array udg_AV_Handles
endglobals

function H2I takes handle h returns integer
	return h
	return 0
endfunction

function CreateHandleId takes handle h returns integer
	local integer i=H2I(h)
	set i=i-(i/8100)*8100
	loop
		exitwhen udg_AV_Handles<i>==null
		set i=i+1
	endloop
	set udg_AV_Handles<i>=h
	return i
endfunction

function GetHandleId takes handle h returns integer
	local integer i=H2I(h)
	set i=i-(i/8100)*8100
	loop
		exitwhen udg_AV_Handles<i>==h
		set i=i+1
	endloop
	return i
endfunction

function DestroyHandleId takes integer i returns nothing
	set udg_AV_Handles<i>=null
endfunction</i></i></i></i>


and you know CSSafety? i liked that system, too, made my own then, and it looked mostly like vexorians version, but without CSData and without vJass... (the overall idea, the idea of destroying timers if the stack is full and function names are stolen)
this is meant as an example of scripts i create for myself, because i dont use vjass and dont really trust in foreign code^^ (well, i use the map optimizer nevertheless :p btw, thanks for it)
JASS:
globals
	timer array udg_TimerStack
	integer udg_TimerStackN
endglobals

function NewTimer takes nothing returns timer
	if udg_TimerStackN==0 then
		set udg_TimerStack[0]=CreateTimer()
		return udg_TimerStack[0]
	endif
	set udg_TimerStackN=udg_TimerStackN-1
	return udg_TimerStack[udg_TimerStackN]
endfunction

function ReleaseTimer takes timer t returns nothing
	call PauseTimer(t)
	if udg_TimerStackN==8191 then
		call DestroyTimer(t)
	else
		set udg_TimerStack[udg_TimerStackN]=t
		set udg_TimerStackN=udg_TimerStackN+1
	endif
endfunction



EDIT: seems like i have to use vJass now, to create that global handle array...^^ ill give it another try
 

Cohadar

master of fugue
Reaction score
209
:cool: I'm observing.

And to answer your question, storing stuff in raw handles is safe
(in the sense that it preserves reference counts)
 

N-a-z-g-u-l

New Member
Reaction score
30
note that its for the new version only ;) and the basic idea was developed by myself... btw, i dont understand your hashing, so i could not use that...^^ well, i know it uses integer overflow, but because integers are also negative numbers i couldnt get a "modulo" to work... i then stopped optimizing it that much, because its already really fast enough^^
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
well you could always create a function which imitates the XOR operator
 

Technomancer

New Member
Reaction score
14
The difference in speed after compile with native java programmed operators is a few times faster than doing it in vJass so scripting it manually to improve speed is kind of moot.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top