Getting Object size?

corwin42

Expert
Licensed User
Longtime User
I use the following sub to clone objects of user defined types.

B4X:
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?
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
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
Top