[vtkusers] Serialization of VTK objects (was: about cmake)
Andy Cedilnik
andy.cedilnik at kitware.com
Wed Jul 24 09:45:56 EDT 2002
Well, it is simple. When using poly data writer, you write out the
actual dataset. Write it as ascii and look at the file. You will see all
the points, all the polygons etc. But, when you say sizeof(*a), this
gives you the size in bytes of vtkPolyData object. This object only
holds a whole bunch of control members and pointers to the actual data.
So, by transferring something like:
(unsigned char*)((void*)(*a))),
you will only send a whole bunch of pointers that do not point anywhere
useful.
For example, consider class Foo:
class Foo {
public:
char* Name;
vtkObject* Object;
double Number;
char RealString[10];
}
What is the size of it?
Well, Name is string... No, Name is pointer, so let say on 32bit Linux
that would be 4 bytes. Object is... again pointer, so another 4 bytes,
and Number is, well, it is double so let say 8 bytes. And the
RealString,.. this one is actually in the class, so it is 10 bytes.
So the sum is (if I added correctly) 26 bytes. That said, *Name itself
can be megabytes long.
So, you see what the problem is?
Now let say you actually want to serialize any object. What you need to
do is to actually traverse through all the members and serialize each
one of them.
I would suggest learning python and looking serialization (pickle) in
python. It will help you understand this better.
Andy
On Tue, 2002-07-23 at 23:33, Song Li wrote:
> Could you give me more hint on my previous question about transfer vtk
> object via socket ( this is my ultimate goal for different kinds of question
> these days)??
> I have a vtk object with the type of "vtkPolyData", say, the definition is
> "vtkPolyData* a", if using "vtkPolyDataWriter" to write it onto disk, there
> will be a vtk file with 200+ Kbytes , but if I use "sizeof *a" in the code,
> it will return a value about 200+ bytes(must be the size of ASCII description
> of this object), and I can only use this number as the number of bytes
> needed to be transfered in socket's read()/write(), and the vtk object at the
> receiving side will cause program to crash.
>
> I know using the number of 200+ must be wrong, but what is the way to obtain
> the size of the object to be transfered ??
More information about the vtkusers
mailing list