#Why do people use the term handle to describe a pointer to a resource?

26 messages · Page 1 of 1 (latest)

plush rock
#

Back in uni far too often I would hear lecturers say "a file handle" or "a database handle" which did not help me understand anything, a handle is a physical part of a physical door you use to open the door. And now that I finally understand that this is a pointer, or a RAII wrapper to some resource, I understand what is going on.

Is it normal to call these a handle instead of a pointer/RAII wrapper object to a resource? Am I in the wrong here?

minor hawkBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

median thunder
#

You use the door handle to control the door. You say you open and close the door, but you actually use the door handle to do so, not the actual door. The same analogy applies to file handles and database handles. They are not files or databases, that would just not work. They are handles so you can manipulate said objects. The analogy makes sense to me 🤷

#

Specifically in programming, handles themselves tend to be useless. Despite being a pointer, dereferencing a FILE* to get at the FILE tends to not work. You're not meant to access the real object, so one could argue said FILE* isn't a real pointer, it's just a handle.

plush rock
#

dereferencing it and accessing the fields might be useful

median thunder
#

In that case it's a real pointer, not just a handle 🤷

#

It's not really about right or wrong, it's more about making an attempt at having the analogies work and know where they break down.

bold night
#

you typically use a handle to symbolically represent those entities

#

a pointer or raii class wrapper or whatever is an implementation details of how you can produce a handle, the pointer would often point to a structure with the information required to manipulate or communicate with whatever the entity you want

#

likewise a "integer" handle would often be some sort of ID to identify the actual resource

#

in the end that resource is not a program object but something outside the program

plush rock
bold night
#

sure, and how is that a file?

#

that's a struct that store information to be able to manipulate a file

#

the file itself is sitting in your filesystem

plush rock
bold night
#

FILE/FILE* is a handle to a file on your filesystem

plush rock
#

platform specific details are not an abstraction, they are details

bold night
#

or whatever it is that contains the file

#

?

median thunder