473,320 Members | 1,839 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.

Handle?

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

Jun 10 '07 #1
7 40586
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....
0
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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

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.