corwin42 Expert Licensed User Longtime User May 23, 2011 #1 I use the following sub to clone objects of user defined types. Code: Copy Sub CloneObject(source As Object) As Object Dim raf As RandomAccessFile Dim buf(1024) As Byte Dim dest As Object raf.Initialize3(buf, False) raf.WriteObject( source, False, 0) dest = raf.ReadObject(0) Return dest End Sub Is there any chance to get the size of the object so that the buffer can properly sized?
I use the following sub to clone objects of user defined types. Code: Copy Sub CloneObject(source As Object) As Object Dim raf As RandomAccessFile Dim buf(1024) As Byte Dim dest As Object raf.Initialize3(buf, False) raf.WriteObject( source, False, 0) dest = raf.ReadObject(0) Return dest End Sub Is there any chance to get the size of the object so that the buffer can properly sized?
Erel B4X founder Staff member Licensed User Longtime User May 23, 2011 #2 Yes. Check raf.CurrentPosition after reading the object. Note that if your object includes any non-primitive field then its size may not be constant. Upvote 0
Yes. Check raf.CurrentPosition after reading the object. Note that if your object includes any non-primitive field then its size may not be constant.
Roberto P. Well-Known Member Licensed User Longtime User Feb 10, 2015 #3 how do I determine the size of the object in order to send? Sub SendObject (Obj As Object, Out As OutputStream) Dim raf As RandomAccessFile Dim buffer( ? ) As Byte raf.Initialize3(buffer, False) raf.WriteObject(Obj, True, 0) Out.WriteBytes(buffer, 0, raf.CurrentPosition) End Sub thanks Upvote 0
how do I determine the size of the object in order to send? Sub SendObject (Obj As Object, Out As OutputStream) Dim raf As RandomAccessFile Dim buffer( ? ) As Byte raf.Initialize3(buffer, False) raf.WriteObject(Obj, True, 0) Out.WriteBytes(buffer, 0, raf.CurrentPosition) End Sub thanks
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2015 #4 This is a thread from 2011. Please start a new one instead. Upvote 0