Date: | May 11, 2016 / year-entry #99 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20160511-00/?p=93446 |
Comments: | 6 |
Summary: | Are you sharing an object or are you creating two objects? |
If you have a token, there are two ways to get another handle to it.
One is to use
Duplicating the handle with
The difference is significant if you try to modify the token. If you duplicate the handle, then there is still only one underlying token, and changes to the token from one handle will be visible to the other handle since it's all the same token at the end of the day; duplicating the handle just gives you two ways to refer to the same thing. If you duplicate the token, then you have two tokens, and changes to one token will not affect the other. It's the difference between buying another set of keys to a car on the one hand, and buying a brand new identical car (which comes with its own set of keys) on the other. If you buy another set of keys to the car, then there's still only one car, and if you do something to the car, that change is visible regardless of which set of keys you use. On the other hand, if you buy a new identical car, then changes to one car do not affect the other. |
Comments (6)
Comments are closed. |
Like a “deep copy” of an object-oriented instance of an object. You can duplicate the pointer to the object, or you can duplicate the object.
I wonder why we need a special API to copy a “pointer”
Because handles are not pointers.
And because their implementation might change. One does not need to know what a handle is in order to use a handle.
This seems super obvious… I was expecting a catch of some sort.
Indeed. Like the difference between “copying the file” and “copying the handle of file. The first one gives you two file that you can change one without affecting the other, the second one gives you two handle to access the same file.