How to convert from byte ptr to type instance ?

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


Type mytype
	Field val:Int
End Type

Local m:mytype,k:mytype
Local convert:Byte Ptr
Local size:Int

m = New mytype
m.val = 10
convert = m
size = SizeOf(m)

MemCopy (Byte Ptr(k),convert,size)


Print k.val

Delay 2000



PS: I use this to copy type instances :)



@Dreamora: This is bloody brilliant! Using this technique. Someone should be able to impliment a form of "Serialization".

You could "Serialize" an instance of an object into a TStream. The TStream could transfer the object (via internet, or file) to another computer.

Of couse, the destination computer would have to have the same Class/Type definition set up. But the "Serialized" data could then be "De-Serialized" to reform the same object with it's different methods/data on the new machine.

This has many possibilities.

-Jim