2 ms·
Abstraction presumes some common operations, otherwise it's not abstraction, it's just some opaque bytes. You can open/read/write/close files. May be seek. What
by vbezhenar 8y ago
Abstraction presumes some common operations, otherwise it's not abstraction, it's just some opaque bytes. You can open/read/write/close files. May be seek. What common operations can you do with some random windows HANDLEs? AFAIK you can't even close that handle, you need to call specific function.
- deathanatos 8y agoTypically, I've found, the common operation is not so much the file/HANDLE itself, as that the file/HANDLE can generate operations that you need to wait on. But select() set the stage by waiting on the file descriptor, and poll/epoll mostly follow suit. You register interest in events on an FD. (Instead of, say, starting an operation and saying "tell me when this operation finishes"; e.g., "futures" as exposed by a number of languages. Aside from waiting, I'd say passing/referring to the objects being operated on is also a commonality. Passing a FD to a child process, for example, or giving it (the object, be that a file/pipe/socket/timer/process/etc.) a name in the FS s.t. other things can refer to them by name. (I personally wish though that fork()/exec() had forced you to specify exactly the set of objects (files/etc.) for the child to avoid the entire multithreading/close-on-exec/atomic flag setting hell that exists today.) I don't know that read/write are actually abstract at the level of a "file descriptor" though. Eventfds and timerfds both support them, but it feels forced. Pipes are one-way, so one of read/write don't make sense, and seek on pipe doesn't either. I think some file descriptors (child classes of a generic "object"/FD/HANDLE, such as files) support read/write, but not necessarily all FDs support read/write/seek.
- vbezhenar 8y agoMy point is that HANDLE is too general abstraction. Can you wait on HANDLE that's result from CreateHeap call? Can you wait on HANDLE that's result from CreateWindow call (HWND is defined as HANDLE)? What's common between file, window and heap object?
- bhk 8y agoClosing/destroying and granting (to another process) are generally applicable to about any resource held by a process. UNIXes, by contrast, expose multiple "close" system calls for non-file things, and have a largely incomplete mishmash of ways to share non-file things.
- useerup 8y agoWindows handles can be handles to a number of different types of objects. Generic operations which can be performed for any type of handle: * Closing the handle: Release any kernel resources associated with the the handle * Comparing to other handles * Duplicating, e.g. duplicating a handle to be used by another process. This allow a process to create a less privileged process and only pass handles with certain privileges to the process. * Get/set handle flags, e-g- flag which indicates whether the handle will be inherited by child processes. For each object type a number of object type specific operations can be used in addition to the above, e.g. file read/write for files or send/receive for sockets. Regardless of whether a handle is for a file, a socket, window, mutex or something else, the generic functions such as close will always work.