Pointers vs References

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • spekyuman

    Pointers vs References

    What processes occur during a function call? Specifically, how are
    pointers and references treated during this time? What happens to
    their memory and what they reference during this particular time? Here
    are some example functions to help with the elaboration process:

    Object naiveFunction(O bject copy)
    {
    // sizeof (copy) =750 x 2^20 bytes
    return copy;
    }

    void pointerFunction (Object* ptr)
    {
    // sizeof (ptr) =4 bytes
    // sizeof (*ptr) =750 x 2^20 bytes
    }

    void referenceFuncti on(Object& ref)
    {
    // sizeof (ref) =750 x 2^20 bytes
    }

  • Victor Bazarov

    #2
    Re: Pointers vs References

    spekyuman wrote:
    What processes occur during a function call? Specifically, how are
    pointers and references treated during this time? What happens to
    their memory and what they reference during this particular time? Here
    are some example functions to help with the elaboration process:
    Do your own homework, will you?


    Comment

    • Rolf Magnus

      #3
      Re: Pointers vs References

      spekyuman wrote:
      What processes occur during a function call?
      Why do you want to know?
      Specifically, how are pointers and references treated during this time?
      Just like any other time.
      What happens to their memory and what they reference during this
      particular time?
      Nothing.

      Comment

      • spekyuman

        #4
        Re: Pointers vs References

        On Jul 10, 1:16 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
        spekyuman wrote:
        What processes occur during a function call? Specifically, how are
        pointers and references treated during this time? What happens to
        their memory and what they reference during this particular time? Here
        are some example functions to help with the elaboration process:
        >
        Do your own homework, will you?
        Number one, do not mouth off on random posts in the illusion of acting
        sophisticated. Why? It displays nothing more than your qualities as
        human... Cough cough [you lack insight]... Elaborating further on the
        main subject to illustrate the point of this post: A reference is an
        alias, or reference [=-O], to another variable which allows you to
        indirectly access its storage. A pointer allows you to do much the
        same and yatta yatta... Since we now share a common knowledge, lets
        talk about the sophisticated processes of sending data to a procedure
        [=-O]. This is where the heart of my question lies:

        [1] Sending data by value to a procedure requires data to be copied
        from the caller to the routine.
        [2] Sending a pointer to a procedure requires data to be copied from
        the caller to the routine. Specifically, the pointer address is sent
        by value and reports a size of 4-8 bytes on modern systems; only the
        object data is being passed by reference.
        [3] My question is, what exactly happens with a reference type during
        a procedure call? Is there any overhead? What are the mechanisms at
        work?

        Comment

        • Victor Bazarov

          #5
          Re: Pointers vs References

          spekyuman wrote:
          [..] This is where the heart of my question lies:
          >
          [1] Sending data by value to a procedure requires data to be copied
          from the caller to the routine.
          From the factual argument into the formal argument. Or, simply put,
          the local variable of the function has to be initialised with the same
          value (copy-initialised, of course).
          [2] Sending a pointer to a procedure requires data to be copied from
          the caller to the routine. Specifically, the pointer address
          The pointer address?
          is sent
          by value and reports a size of 4-8 bytes on modern systems; only the
          object data is being passed by reference.
          The pointer is passed by value: the local variable is initialised with
          the value of the pointer that the caller supplies as the argument.
          Nothing else is passed by no other method.
          [3] My question is, what exactly happens with a reference type during
          a procedure call?
          The reference (the local variable of the function) is initialised by
          the l-value passed to it by the caller.
          Is there any overhead? What are the mechanisms at
          work?
          Some implementation-defined mechanisms. How references are implemented
          and what (if any) overhead there can be observed, is not specified by
          the language. If you'd like to discuss a particular implementation,
          you're welcome to, just not here.

          Initialising a reference argument (an argument that has a reference
          type) is no different than initialising one without the interference
          of a function call/invocation.

          Object someObject;
          Object & rObject = someObject;

          what mechanisms are at work? Is there overhead? Implementation-defined.

          V
          --
          Please remove capital 'A's when replying by e-mail
          I do not respond to top-posted replies, please don't ask


          Comment

          Working...