HANDLE

Discussion in 'C++' started by Eric Kaplan, Apr 9, 2008.

  1. Eric Kaplan

    Eric Kaplan Guest

    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
    Eric Kaplan, Apr 9, 2008
    #1
    1. Advertising

  2. Eric Kaplan

    Ian Collins Guest

    Eric Kaplan wrote:
    > 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.

    --
    Ian Collins.
    Ian Collins, Apr 9, 2008
    #2
    1. Advertising

  3. Eric Kaplan

    Martin York Guest

    On Apr 8, 7:48 pm, "Christopher Pisz" <> wrote:
    > "Eric Kaplan" <> wrote in message
    >
    > news:...
    >
    > > In C++, there is datatype HANDLE

    >
    > 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"
    >
    > > void* HANDLE

    >
    > > then HANDLE is similar to "file 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.
    Martin York, Apr 9, 2008
    #3
  4. Eric Kaplan

    James Kanze Guest

    On Apr 9, 6:58 am, Martin York <> wrote:
    > On Apr 8, 7:48 pm, "Christopher Pisz" <> 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.

    --
    James Kanze (GABI Software) email:
    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
    James Kanze, Apr 9, 2008
    #4
  5. [OT] what's a handle? [Was: HANDLE]

    On 9 Apr, 10:05, James Kanze <> wrote:
    > On Apr 9, 6:58 am, Martin York <> wrote:
    > > On Apr 8, 7:48 pm, "Christopher Pisz" <> 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?  


    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."
    Nick Keighley, Apr 9, 2008
    #5
  6. Eric Kaplan

    Martin York Guest

    On Apr 9, 2:05 am, James Kanze <> 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?


    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.
    Martin York, Apr 9, 2008
    #6
  7. Eric Kaplan

    Christopher Guest

    On Apr 9, 7:29 am, Martin York <> wrote:
    > On Apr 9, 2:05 am, James Kanze <> 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?

    >
    > 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.
    Christopher, Apr 9, 2008
    #7
  8. Eric Kaplan

    James Kanze Guest

    On Apr 9, 2:29 pm, Martin York <> wrote:
    > On Apr 9, 2:05 am, James Kanze <> 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?


    > 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.

    --
    James Kanze (GABI Software) email:
    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
    James Kanze, Apr 10, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay B. Harlow [MVP - Outlook]

    Re: FileDialog window handle

    Jay B. Harlow [MVP - Outlook], Sep 2, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    3,877
    Mick Doherty
    Sep 3, 2003
  2. Dan Ignatov

    Re: FileDialog window handle

    Dan Ignatov, Sep 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,071
    Dan Ignatov
    Sep 4, 2003
  3. Dietrich
    Replies:
    1
    Views:
    643
    Joe Smith
    Jul 22, 2004
  4. Leon
    Replies:
    2
    Views:
    528
  5. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    446
    hanumizzle
    Oct 6, 2006
Loading...

Share This Page