B.Morris
03-13-2002, 01:08 PM
CONST is better. If you have the freedom to choose (when you're writing your own procedure), use this rule of thumb for non-reference parameters: use VALUE for pointers and numeric values, and CONST for arrays, structures and strings. For any large parameter, it's better to pass it by reference (CONST) than by value. Passing by reference requires just 16 bytes to be copied to the parameter area. Passing by value requires the entire length of the parameter to be copied(*) to ... somewhere, I have no idea of the actual details. With CONST, if the passed parameter matches the prototyped parameter, no copying is required. With CONST varying length parameters, if a varying temporary must be created, the only copying is of the length of the passed parameter. So for say a CHAR(1000) VARYING parameter, if passed by value, at least 1000 bytes must be copied somewhere. Say you passed the value 'abc'. Then with VALUE, the compiler has to copy 'abc' to the 1002-byte varying temporary and then "something" has to copy that 1002 bytes "somewhere". With CONST, the compiler has to copy 'abc' to the varying temporary and then the "something" has to copy the 16 byte pointer "somewhere". (*) While it may be true (I think it is) that even when passed by value, large structures sort of get passed by reference under the covers, I think this still involves some copying of the data to "somewhere" (it must, since the callee is free to modify the passed parameter, and that can't be reflected in the passed parameter).