Page 524 of the PostgreSQL 8.1 Manual, PDF Edition, has a code snippit that makes use of the VARHDRSZ macro. I'm trying to understand the purpose of this macro.
Here is the code from the manual: #include "postgres.h" ... char buffer[40]; /* our source data */ ... text *destination = (text *) palloc(VARHDRSZ + 40); destination->length = VARHDRSZ + 40; memcpy(destination->data, buffer, 40); ... The manual also says, just below the code snippit: "VARHDRSZ is the same as sizeof(int4), but it's considered good style to use the macro VARHDRSZ to refer to the size of the overhead for a variable-length type." Does this mean that we are simply allocating 44 bytes for the data type with these calls to the VARHDRSX macro? Previous to the code snippit the manual says this: "All variable-length types must begin with a length field of exactly 4 bytes, and all data to be stored within that type must be located in the memory immediately following that length field." If this is the case, why even have the VARHDRSZ macro? Why not just add 4 bytes to the length of the data when you use palloc? I know I could just take this on faith, but I'm trying to understand the underlying concepts of what is being done in this code. Is the macro used becuase of different operating system implementations of the C programming language, or is the Macro used to perserve backward compatibility if the "length" indicator is increased to more than 4 bytes in the future? Thanks, Scott Huey ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings