473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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(Object 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 referenceFunction(Object& ref)
{
// sizeof (ref) =750 x 2^20 bytes
}

Jul 10 '07 #1
4 1261
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?
Jul 10 '07 #2
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.

Jul 10 '07 #3
On Jul 10, 1:16 pm, "Victor Bazarov" <v.Abaza...@comAcast.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?

Jul 10 '07 #4
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
Jul 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Web Developer | last post by:
Hi, Can someone provide a short and concise statement(s) on the difference between pointers and references. A graphical representation (via links?) of both would be much appreciated as well. ...
4
by: cppaddict | last post by:
I understand that there are a couple differences between reference variables and pointer: 1) reference variables *must* be initialized. 2) You cannot change what a reference variable refers...
26
by: Desmond Liu | last post by:
I've read articles like Scott Meyer's EC++ (Item 22) that advocate the use of references when passing parameters. I understand the reasoning behind using references--you avoid the cost of creating...
7
by: _ed_ | last post by:
I'd like to build a class or struct composed of pointers to variables. Does this require dropping into an 'unsafe' block, or is there a trick? .... int value1 = 1234; bool value2 = false;...
12
by: arganx | last post by:
Before I had a good idea how to use pointers, I was wondering - first, how to use them. And second, of what value would they be. Now that I have at least a pretty good idea of how to use them, I...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
7
by: Erdal Mutlu | last post by:
Hi, I am trying to design a base class (interface) with two or more subclasses as follows: class A { .... virtual static A* getByName(const string x)=0 const; }
64
by: Zytan | last post by:
I know there are no pointers in C#, but if you do: a = b; and a and b are both arrays, they now both point to the same memory (changing one changes the other). So, it makes them seem like...
19
by: MQ | last post by:
Can someone tell me where I should use pointers and where I should use references? In his book, Stroustrup says that you should use pointers for passing arguments that are to be modified, not...
29
by: Simon Saize | last post by:
Hi - What's the point of having references (&)? Why don't we just use pointers (*)? Thanks.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.