[pgpointcloud] Wrong serialized size of a PcPoint ?

Sandro Santilli strk at keybit.net
Wed Apr 8 02:56:04 PDT 2015


Checking the size of PcPoint values (with pc_memsize and pg_column_size)
I found that we're using 11 bytes for the header when instead only 8 are
required:

 typedef struct
 {
   uint32_t size; //   4
   uint32_t pcid; //  +4 = 8
   uint8_t data[1];
 }
 SERIALIZED_POINT;

This is because the code uses sizeof(SERIALIZED_POINT) - 1 to determine
the required size, but sizeof(SERIALIZED_POINT) is 12 on my machine,
rather than 9 as expected by the code.

In turn, 12 means that the structure is padded to the closest 4bytes
boundary (4+4+4 rather than 4+4+1).

As we're going to add the actual size of the dimensions, that padding
would not necessarely be needed. For example, a PcPoint with 3 4bytes
dimensions would be perfectly aligned with just 16 bytes. Instead
it uses 8+11=19 bytes.

Similar assumption (no padding) is done for the PcPatch case, whose
struct also ends with an uint8_t.

I hadn't checked if such 3 bytes padding sums up for each point in
a patch but it sounds like something worth inspecting.

--strk; 

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html


More information about the pgpointcloud mailing list