473,376 Members | 1,041 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,376 software developers and data experts.

Handle?

What is exactly a handle to an object????Is it same as reference....

Jun 10 '07 #1
7 40600
Shraddha wrote:
What is exactly a handle to an object????Is it same as reference....
Handle is NOT a C++ term. In windows a HANDLE is an opaque datatype
that really was a pointer at some point (perhaps in the operating
systems address space) that you're not supposed to treat as a pointer
just an indentifier of some system created resource.

Think of it as a void* you can't do anything with other than pass
back to other functions in the API.
Jun 10 '07 #2
On 2007-06-10 06:20:01 -0700, Shraddha <sh*************@gmail.comsaid:
What is exactly a handle to an object????Is it same as reference....
The term "handle" is meaningless as far as C++ is concerned. Different
platforms and environments use the term for different concepts. I have
seen handle to mean any of: A pointer, an opaque identifier, a
pointer-to-pointer, a smart pointer. Please refer to the documentation
for your specific environment for more information.

--
Clark S. Cox III
cl*******@gmail.com

Jun 10 '07 #3
On Sun, 10 Jun 2007 09:43:51 -0400, Ron Natalie wrote:
>Shraddha wrote:
>What is exactly a handle to an object????Is it same as reference....
Sort of. A handle typically encapsulates access to resources and/or
objects.
>Handle is NOT a C++ term.
It is a term of any language, including C++, that uses handles. In C++
handles can take advantage of genuine C++ idioms like RAII. See
http://www.research.att.com/~bs/glossary.html#Ghandle
>In windows a HANDLE is an opaque datatype
that really was a pointer at some point (perhaps in the operating
systems address space) that you're not supposed to treat as a pointer
just an indentifier of some system created resource.
Great idea, isn't it?
>Think of it as a void*
A handle (and also a HANDLE) usually isn't a void*.
>you can't do anything with other than pass
back to other functions in the API.
.... which is exactly what you want when you use a handle.
BTW, Stroustrup sometimes uses 'handle' synonymously with 'smart
pointer' which is, IMO, misleading ('smart pointers' don't encapsulate
the pointed-to objects).
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 10 '07 #4
On Jun 10, 3:49 pm, Clark Cox <clarkc...@gmail.comwrote:
On 2007-06-10 06:20:01 -0700, Shraddha <shraddhajosh...@gmail.comsaid:
What is exactly a handle to an object????Is it same as reference....
The term "handle" is meaningless as far as C++ is concerned. Different
platforms and environments use the term for different concepts.
The concept is well known in computer science in general. It's
an opaque identifier of something. (Handles existed way before
Windows.)

As names go, it's pretty poor, because it is also often used as
a verb. If you don't know what else to name a function, call it
handle(). It's one of those names that, if you see it in a
program, you know that the design wasn't sufficiently precise.
So while it's usable as a noun, it lends to confusion, and it is
far better to use id or Identifier, or something along those
lines.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 10 '07 #5
Roland Pibinger wrote:
On Sun, 10 Jun 2007 09:43:51 -0400, Ron Natalie wrote:
>>Shraddha wrote:
>>What is exactly a handle to an object????Is it same as reference....

Sort of. A handle typically encapsulates access to resources and/or
objects.
>>Handle is NOT a C++ term.

It is a term of any language, including C++, that uses handles.
The C++ language definiton doesn't define that term. Basically, things that
aren't defined in the C++ standard are off-topic here.
When using some non-standard libraries that use something called 'handle',
it might mean different things depending on the library.
>>In windows a HANDLE is an opaque datatype
that really was a pointer at some point (perhaps in the operating
systems address space) that you're not supposed to treat as a pointer
just an indentifier of some system created resource.

Great idea, isn't it?
It seems quite common, but unneccesary in C++. It's more of a concept used
with C to compensate for the lack of classes.
>>Think of it as a void*

A handle (and also a HANDLE) usually isn't a void*.
>>you can't do anything with other than pass
back to other functions in the API.

... which is exactly what you want when you use a handle.
BTW, Stroustrup sometimes uses 'handle' synonymously with 'smart
pointer' which is, IMO, misleading ('smart pointers' don't encapsulate
the pointed-to objects).
As I said, since it's not defined in the C++ standard, it might mean
different things.
Jun 11 '07 #6
On 2007-06-10 14:45:35 -0700, James Kanze <ja*********@gmail.comsaid:
On Jun 10, 3:49 pm, Clark Cox <clarkc...@gmail.comwrote:
>On 2007-06-10 06:20:01 -0700, Shraddha <shraddhajosh...@gmail.comsaid:
>>What is exactly a handle to an object????Is it same as reference....
>The term "handle" is meaningless as far as C++ is concerned. Different
platforms and environments use the term for different concepts.

The concept is well known in computer science in general. It's
an opaque identifier of something.
Which was one of the meanings in the list I provided (which you snipped)
(Handles existed way before Windows.)
I know this.
--
Clark S. Cox III
cl*******@gmail.com

Jun 11 '07 #7

"Shraddha" wrote:
What is exactly a handle to an object?
There is no "exact" answer. "Handle" is not a C++ term.
It's usually used to mean an identifier for a dynamically-
allocated object. (Examples: windows, icons.) This is
in contrast to an "identifier" which usually refers to
statically-allocated objects. (Examples: controls in a
window template.)
Is it same as reference?
No. In C++ a "reference" is an "alias", or an alternate
name, for an object.

Example:

std::string & Name = status_object.IncomingFileRecord.name;

You can now write to status_object.IncomingFileRecord.name
like this:

Name = "qb_7309.icf";

Instead of having to write:

status_object.IncomingFileRecord.name = "qb_7309.icf";

Much neater!

(Not to mention passing arguments to functions by non-const
reference, which makes it a breeze to use one function to
alter variables in another function. VERY nice technique.)

I suppose a "handle" could be implimented using a reference,
but it usually isn't. In my compiler at work (CVI), handles
are ints. In another compiler I worked with (Visual C++),
handles are void*. In the compiler I use at home for making
system utilities (gcc) handles are not used. It varies.

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org
Jun 11 '07 #8

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

Similar topics

15
by: Tim Clacy | last post by:
Please illuminate; what operator of class 'Event' will get matched for these two cases : Event ev1; Event ev2; // Case 1 // if (ev1) ;
7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body. Each...
2
by: Indiana Epilepsy and Child Neurology | last post by:
Before asking this questions I've spent literally _years_ reading (Meyer, Stroustrup, Holub), googling, asking more general design questions, and just plain thinking about it. I am truly unable to...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
7
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to...
13
by: Abhishek | last post by:
Hi, how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application only even if there is any other window in front of it. I dont...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
3
by: Peterwkc | last post by:
Hello all C++ expert programmer, I have a handle class which point to another class and use the pointer as object. I follow the code from C++ articles submited by someone in this forum....
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:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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.