Talk:Smart pointer
From Wikipedia, the free encyclopedia
[edit] Getting a handle on handles
More details on handle are needed....
- I think the section on handles should be eventually moved to their own page. There's an argument against this — pointer, smart pointer, and reference are all separate and vaguely redundant, and handle would only add to the mess. I'm going to leave it for now, because I usually stick to FP and prefer not to mess with this stuff. :) --Mgreenbe 23:17, 8 December 2005 (UTC)
[edit] Handles aren’t smart pointers
It’s never been my impression that handles are smart pointers. Sometimes handles aren’t pointers at all. Even when a handle is a pointer, it can be harmful for a programmer to think of it that way since that brings the temptation to dereference the pointer and dig around at what it’s pointing at. A handle is meant to keep those kinds of details abstract.
There are other kinds of handles that have nothing to do with the memory manager. Those include file handles, window handles, mutex handles, search handles, etc. In this way, the notion of a handle is a kind of pattern: All those kinds of handles represent different things, but they’re all there to prevent (or relieve) the program from having to deal with the nitty-gritty details of the underlying system.
Smart pointers don’t do that. Smart pointers don’t really hide anything from the program. They lessen the burden of some of the bookkeeping involved with pointers, but they still provide access to the same memory that would have been available with a conventional pointer.
Although handles for memory may have fallen out of favor lately, they’re definitely still going strong for other uses, especially on Windows. I suspect they still get frequent use on other operating systems.
If anything has caused other kinds of handles to fall out of favor, it’s classes. Instead of file handles with API functions that accept file handles for their first parameters, we instead often see File
classes with various methods to act on underlying disk files.
To describe a handle as a smart pointer, I’d want to know what kind of “smarts” the handle supposedly has. This article doesn’t address that, and I doubt it can. --Rob Kennedy 04:55, 30 August 2006 (UTC)
[edit] As a Windows Programmer...
I HATE handles, Win32 API is not O-O, handles suck. "Smart" pointers, more like "RETARDED AND CONFUSING" pointers! Just my humble opinion. 64.12.116.10 21:23, 5 September 2006 (UTC)