- Whether you pass an object as ByRef or not ByRef, any changes to the object are permanent. Does whether a parameter is ByRef or not have any effect on objects? Are there performance advantages/disadvantages, or other consequences?
- There is at least one difference that I know of, which is that if you pass an object ByRef, the reference count is not affected.
Code: Select all
q:: ;test object get reference count functions
obj := obj2 := obj3 := {}
MsgBox, % JEE_ObjRefCount(obj)
MsgBox, % JEE_ObjRefCountAlt(obj)
MsgBox, % ZJEE_ObjRefCount(obj)
MsgBox, % ZJEE_ObjRefCountAlt(obj)
return
;notice in the definitions whether 'ByRef' is used
JEE_ObjRefCount(ByRef oArray)
{
;note: if you didn't use ByRef, this function itself would increase the ref count
if !IsObject(oArray) ;it's a ptr
{
ObjAddRef(oArray)
return ObjRelease(oArray)
}
ObjAddRef(&oArray)
return ObjRelease(&oArray)
}
;==================================================
JEE_ObjRefCountAlt(ByRef oArray)
{
;note: if you didn't use ByRef, this function itself would increase the ref count
;note: this technique is undocumented, and may not work in future (tested on AHK v1.1)
return NumGet(&oArray + A_PtrSize)
}
;==================================================
ZJEE_ObjRefCount(oArray)
{
;note: if you didn't use ByRef, this function itself would increase the ref count
if !IsObject(oArray) ;it's a ptr
{
ObjAddRef(oArray)
return ObjRelease(oArray)
}
ObjAddRef(&oArray)
return ObjRelease(&oArray)
}
;==================================================
ZJEE_ObjRefCountAlt(oArray)
{
;note: if you didn't use ByRef, this function itself would increase the ref count
;note: this technique is undocumented, and may not work in future (tested on AHK v1.1)
return NumGet(&oArray + A_PtrSize)
}
;==================================================