Do you still have to null locals? I saw some people's code using this but they weren't nulling.
Cool!The result, the speed is actually the same as this script in not debug mode, and in debug mode it prevents me for double free.
Using something like that for double free protection seems counter-intuitive. Surely, the unit may have been removed from the group before being freed for a second time - such as if any enum was called for it...
Yes, if the group is used at all with an Enum or FoG loop, your protection is shot. You seemingly would only save double free protection if it is immediately two calls. But that's not very useful... most likely the user (yourself? XD) would accidentally keep a reference to the group, and try using it for something, and then free it again...
Hm.
library Memory initializer Initialization uses Recycle
{
struct Memory {
public static int offset
public static timer privateTimer = CreateTimer()
public static integer array data
define <Memory.set>(handleId, value) = {
Memory.data[handleId-Memory.offset] = value
}
define <Memory.get>(handleId) = {
Memory.data[handleId-Memory.offset]
}
public hashtable memory = InitHashtable()
define <Memory.set>(handleId, slot, value) = {
SaveInteger(Memory.memory, handleId, slot, value)
}
define <Memory.get>(handleId, slot) = {
LoadInteger(Memory.memory, handleId, slot)
}
}
private void Initialization() {
Memory.offset = GetHandleId(Memory.privateTimer)
Timer.release(Memory.privateTimer)
Memory.privateTimer = null
}
}
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"
include "cj_typesEx_priv.j"
include "cj_order.j"
include "cj_antibj_base.j"
scope Demo initializer Initialization {
timer t
int data
void Test() {
data = Memory.get(GetHandleId(GetExpiredTimer()))
printf(I2S(data))
}
void Initialization() {
t = Timer.get()
Memory.set(GetHandleId(t), 5)
TimerStart(t, 1, false, function Test)
}
}
Wait, what? You can double-free with groups? I haven't been able to find any mention of how that can happen. Could you explain?Yes, if the group is used at all with an Enum or FoG loop, your protection is shot. You seemingly would only save double free protection if it is immediately two calls. But that's not very useful... most likely the user (yourself? XD) would accidentally keep a reference to the group, and try using it for something, and then free it again...