Converting an object to a float array?

BlitzMax Forums/BlitzMax Programming/Converting an object to a float array?

ImaginaryHuman(Posted 2009) [#1]
I set up an array like:

Local MyFloatArray:Float[100]

Then I want to store this in memory, like so:

MyMemoryLocation[0]=HandleFromObject(MyFloatArray)

This works fine. I want to then retrieve the float array, and the only way I could figure to do this is with this:

Local Array:Float[]=Float[](HandleToObject(MyMemoryLocation[0]))

This seemed to allow the compiler to get past this problem, but I really kind of just guessed at the =Float[] part ... is this the correct way to convert back to a float array?


Gabriel(Posted 2009) [#2]
That looks right to me, and a quick test program confirms it.

SuperStrict

Local MyFloatArray:Float[100]

MyFloatArray[50]=167

Local MyMemoryLocation:Int[]=New Int[1]
MyMemoryLocation[0]=HandleFromObject(MyFloatArray)

Local Array:Float[]=Float[](HandleToObject(MyMemoryLocation[0]))

Print Array[50]



Brucey(Posted 2009) [#3]
Also note, that if MyFloatArray goes out of scope, it is liable for garbage collection.


ImaginaryHuman(Posted 2009) [#4]
Cool.

Regarding garbage, do you mean that if I store the float array as an object handle, and free the object, it will remove the object entirely from memory and won't be able to get it back from the handle? Or does the garbage collector keep track of handles as reference counts etc?


Gabriel(Posted 2009) [#5]
Also note, that if MyFloatArray goes out of scope, it is liable for garbage collection.

It shouldn't be liable for collection unless you call Release on the handle, surely? HandleFromObject - according to the documentation, which I know isn't 100% reliable - manually increases the reference count when it gets called and must correspond with a release statement to lower the reference count.

Or is this changed because of the new, threaded GC in the latest version?