Q:  When I call a function with a string parameter, Clipper makes a
    copy of the string which is used by the function:

                subfunc( str_var )

    I can have Clipper use my copy of the string by passing it by
    reference.

                subfunc( @str_var )

    When I call Clipper functions like at() and substr() with a string
    passed by reference, I get a run-time error.  Why is this?

                at( "abc", @str_var )       --> run time error

    If I call Clipper functions like at() and substr() with a string
    passed by value (the only valid way), does Clipper use my copy or
    make a copy as it does with any other function call? I'm trying to
    conserve memory in a program that manipulates large strings
    (30k-60k) so that I reduce the VMM activity and make my processing
    as fast as possible.

A:  [Robert diFalco]

    This one often leads people astray, because in C a pointer and a
    reference are often used to describe the same thing.  This, BTW, is
    changing with C++ since a reference is something much different than
    a pointer.

    >> When I call a function with a string parameter, Clipper makes a
    >> copy of the string which is used by the function:

    This above statement is the basis of the misinformation. Clipper
    does not make a copy of the string but rather the value containing the
    OREF that refers to the string.  There are two types of references
    in Clipper, OREFs and VREFs.

    An OREF (object reference) is an internal entity that identifies
    the position of an object in virtual memory. In Clipper, a variable
    is represented by an internal structure called a VALUE. Numerics and
    other simple data types are stored directly in the VALUE structure. All
    other data types (such as characters, arrays, etc) are internally known
    as objects and the VALUE structure holds an OREF pointing to this object
    in virtual memory.

    The other sort of reference is called a VREF (variable reference). A
    VREF is an internal entity that identifies a Clipper variable. VREF's
    are created only when a Clipper variable is passed by reference.

    When you pass a variable by reference, Clipper creates a VREF and puts
    it onto the evaluation stack. When a variable is passed by value,
    Clipper puts a copy of its VALUE structure on the evaluation stack. In
    the case of a string (for example) only the OREF contained by the VALUE
    is copied and not the actual string. This reference handling is not
    noticed at the Clipper level. You may have many character variables
    that all contain the same OREF. If one is modified, it then creates
    a copy of the string and generates a new OREF. So, in short, whether
    you pass a character by value or by reference, the memory overhead
    is virtually identical.

    The answer to question 1 is simple. It's just type enforcement.
    SUBSTR() and AT() do not take reference values, they take character
    values.

    Question 2 is simple as well, Clipper does not make a copy of the
    actual string, only the VALUE structure that contains the OREF to the
    string gets copied. However, if the function modifies the character
    variable, only then will the string be copied and a new OREF
    generated.

                                   ###