473,320 Members | 2,117 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,320 software developers and data experts.

Thumb rule for passing arguments

Hi all,

I have a single-rooted hierarchy of heap-allocated objects -- call the
root Object. These objects are handled via a smart pointer template
Reference<T>. Basically, Reference<Tis a wrapper around T* with some
extra smarts including reference counting to make memory management
easier. Below, Reference<Objectwill be denoted simply by Ref.

Since you only get your hands on Reference<Tand never on a T (or T*)
directly, my thumb rule has been, at least in the public interface of
the T class, to pass and return by Reference<T(in most cases,
actually Ref). In addition, until now I have used

- return Reference<Tby const value, e.g.

const Reference<TsomeMethod(...);

The const to avoid such perplexing oddities as doing:

someMethod(...) = ...;

My question is now, what would be your thumb-rule for passing
arguments? Two basic choices:

- By value, e.g. someMethod(Reference<TsomeArg).

- By reference, e.g. someMethod(const Reference<T>& someArg)

Since Reference<Tis basically a pointer, I am inclined to
pass-by-value. This has the inconvenience of triggering a call to the
copy-constructor which implies the creation of another object and
fiddling of the reference count of T. On the other hand, there is one
less layer of indirection.

OTOH, looking at some Boost library smart pointer classes, they
usually use the pass-by-reference form.

Do you have any thumb-rule advice? Since I am writing this hierarchy
from scratch and for my own use (for now at least) I tend to value
consistency and doing everything the same way everywhere.

TIA, with my best regards,
G. Rodrigues
Nov 2 '06 #1
0 1322

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
4
by: aling | last post by:
What's the rule of default argument of function in C++? I found that the default argument of function could not necessary be a constant value. Is it true? Previously I thought that the default...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
1
by: John | last post by:
I can't find this in the manuals. I'm not interested in size of primary or secondary logs, what is a good rule of thumb for how many logs to cut in an hour in a busy OLTP and DW environment. I...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
5
by: Michael | last post by:
Hi, once I read here that it is not 'a good idea' to pass variables that are not initialized to a function. I have void something ( double *vector ); ....
6
by: Cody Powell | last post by:
Greetings all, I'm wondering if there's a rule of thumb related to objects that implement IDisposable, but whose Dispose() methods are actually marked as protected. If you dig around System.IO,...
9
by: utab | last post by:
Dear all, How do experienced programmers using this group use the rule of thumb,namely copy ctor, assignment operator, and dtor. example if the class does not need them dont use and define...
2
by: william.w.oneill | last post by:
I have an application that takes a few command line parameters. As recommended by others in this group, I'm using a named mutex to ensure that only one instance of the application is running. My...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.