How to convert from byte ptr to type instance ?

BlitzMax Forums/BlitzMax Programming/How to convert from byte ptr to type instance ?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi,

I'd recommend using object handles instead.

At the moment, these aren't toooo elegant to use but their advantage is that you wont accidentally 'leak' objects - eg: if you convert an object to a byte ptr and there are NO references left to the object it may get accidentally 'flushed', resulting in really hard to find bugs.

You can perform object/handle conversions using functions, but it's a bit messy. For a kludge around until I clean this up...

Extern
Function bbHandleToObject:Object( handle )
Function bbHandleFromObject:Int( obj:Object )
End Extern

Type TMyType
   Field x=1
End Type

Local obj:TMyType=New TMyType

Local handle=bbHandleFromObject( obj )

obj=TMyType( bbHandleToObject( handle ) )

Print obj.x

Release handle 'done with object!