HANDLE

E

Eric Kaplan

In C++, there is datatype HANDLE
void* HANDLE

then HANDLE is similar to "file handle"?

which is unique identifier for a file, for a process, for a thread ...
etc

which is returned by a function when it's creating something - like
creating a thread, creating a process, creating a file ... etc
 
I

Ian Collins

Eric said:
In C++, there is datatype HANDLE
void* HANDLE

then HANDLE is similar to "file handle"?

which is unique identifier for a file, for a process, for a thread ...
etc

which is returned by a function when it's creating something - like
creating a thread, creating a process, creating a file ... etc
In standard C++ terms, it's probably just used as an opaque, unique
identifier. You would get more input on a windows programming group.
 
M

Martin York

Funny, it doesn't show up in any of my books as a primitive type.
I think you mean, "In the Windows SDK there is a data type HANDLE"



Why not look it up in the MSDN?

In computer science terms a 'handle' is a pointer to a pointer to a
resource.
The concept was used by many OS to allow the easy movements of
resources in memory.

But this is not specifically a C++ concept and you would need to look
up a comp-sci book to get full details.
 
J

James Kanze

On Apr 8, 7:48 pm, "Christopher Pisz" <[email protected]> wrote:

[...]
In computer science terms a 'handle' is a pointer to a pointer to a
resource.
The concept was used by many OS to allow the easy movements of
resources in memory.

Do you have a reference for that? I've always understood a
handle to be an opaque data type, used by some service providers
as an identifier of something. It could be a pointer to a
pointer, a simple pointer, an int, or even a string: just about
anything else the service provider wants to use. The critical
point was always that the type and semantics were opaque to the
client.
 
N

Nick Keighley

Do you have a reference for that?  

the MAC used to do this. I'm not sure it's particularly
widely used.

I've always understood a
handle to be an opaque data type, used by some service providers
as an identifier of something.  It could be a pointer to a
pointer, a simple pointer, an int, or even a string: just about
anything else the service provider wants to use.  The critical
point was always that the type and semantics were opaque to the
client.

on Unix it was common for a handle to be a small integer.
Think file handles.

C's FILE* is very handle like



--
Nick Keighley

"One of the main causes of the fall of the Roman Empire was that,
lacking zero, they had no way to indicate successful termination of
their C programs."
 
M

Martin York

Do you have a reference for that?

Not really. Its from my days at University. But the following may be
clearer than I was.
http://en.wikipedia.org/wiki/Handle_(computing)



By providing a layer of indirection it allows a system to perform some
form of resource management without having to keep to track of all
pointers to an object (as there is only one pointer, all the handles
point at this pointer). If the resource is moved you just need to
update one pointer and all handles are automatically still referencing
the correct resource.

Though handles can be opaque (thus forcing access to the data via a
functional API) this is not a requirement of handle. Most systems
force you to use an API because accessing data directly via the handle
is dangerous (as the resource could move during access). Using a
handle directly requires that it be locked before use and unlocked
after. SIDE-NOTE: Not locking a handle before use leads to very hard
to find bugs (as they can be non deterministic [especially in
multithreaded environments]). As a consequence most systems that use
handles at a high level (were there is a high proportion of developers
that are less experienced with CS techniques) now make the handle
opaque to force you to use the API so that the lock/unlock can be done
automatically. On systems were performance is an issue handles are
generally not opaque to allow the developers to optimize usage but
adds the complexity of forcing them to manually lock/unlock the
handle.

OK. That's what I remember, but as I can't provide a good source for
the definition (my CS text books are all in storage) I am quite happy
to stand corrected.
 
C

Christopher

Do you have a reference for that?

Not really. Its from my days at University. But the following may be
clearer than I was.http://en.wikipedia.org/wiki/Handle_(computing)

By providing a layer of indirection it allows a system to perform some
form of resource management without having to keep to track of all
pointers to an object (as there is only one pointer, all the handles
point at this pointer). If the resource is moved you just need to
update one pointer and all handles are automatically still referencing
the correct resource.

Though handles can be opaque (thus forcing access to the data via a
functional API) this is not a requirement of handle. Most systems
force you to use an API because accessing data directly via the handle
is dangerous (as the resource could move during access). Using a
handle directly requires that it be locked before use and unlocked
after. SIDE-NOTE: Not locking a handle before use leads to very hard
to find bugs (as they can be non deterministic [especially in
multithreaded environments]). As a consequence most systems that use
handles at a high level (were there is a high proportion of developers
that are less experienced with CS techniques) now make the handle
opaque to force you to use the API so that the lock/unlock can be done
automatically. On systems were performance is an issue handles are
generally not opaque to allow the developers to optimize usage but
adds the complexity of forcing them to manually lock/unlock the
handle.

OK. That's what I remember, but as I can't provide a good source for
the definition (my CS text books are all in storage) I am quite happy
to stand corrected.

Fact is, it could be anything. The only way to tell is to refer to the
documentation of the library that is providing it. There is a big
difference in what the concept of a handle is and a particular
implementation of one.
 
J

James Kanze

Not really. Its from my days at University. But the following
may be clearer than I
was.http://en.wikipedia.org/wiki/Handle_(computing)

You'll notice that the article doesn't provide any references
either.
By providing a layer of indirection it allows a system to
perform some form of resource management without having to
keep to track of all pointers to an object (as there is only
one pointer, all the handles point at this pointer). If the
resource is moved you just need to update one pointer and all
handles are automatically still referencing the correct
resource.

The concept of handle definitely involves a conceptual level of
indirection. It's something which allows the OS to find the
relevant object. It "might" be an actual pointer to the object,
or it might be anything else. (I seem to recall file handles in
MS-DOS being small integers. Just like file descripters in
Unix. And a file descripter in Unix would be a handle IF is
wasn't documented to be an int, with a few documented integral
values for predefined file descripters and the error case.)
Though handles can be opaque (thus forcing access to the data
via a functional API) this is not a requirement of handle.

That's the key to what I've always understood by the word
"handle". But I'll admit, I'm not aware of any formal
definition anywhere; that just corresponds to the use that seems
to be current among the programmers (and the OS's) I work with.
Most systems force you to use an API because accessing data
directly via the handle is dangerous (as the resource could
move during access). Using a handle directly requires that it
be locked before use and unlocked after. SIDE-NOTE: Not
locking a handle before use leads to very hard to find bugs
(as they can be non deterministic [especially in multithreaded
environments]). As a consequence most systems that use handles
at a high level (were there is a high proportion of developers
that are less experienced with CS techniques) now make the
handle opaque to force you to use the API so that the
lock/unlock can be done automatically. On systems were
performance is an issue handles are generally not opaque to
allow the developers to optimize usage but adds the complexity
of forcing them to manually lock/unlock the handle.
OK. That's what I remember, but as I can't provide a good
source for the definition (my CS text books are all in
storage) I am quite happy to stand corrected.

Could it be that different communities use the term differently?
I've never heard it used in the way you describe, but I don't
doubt that you have. And the "natural" meaning of the word in
English could lead to either or both senses.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top