What is the “atom” data type?

前端 未结 4 742
星月不相逢
星月不相逢 2021-02-01 16:57

I have encountered the ATOM type in the Win32api and also in the Acrobat API there is ASAtom.

As far as I can tell, atoms are keys for a hash table usually

4条回答
  •  粉色の甜心
    2021-02-01 17:26

    As for the etymology of the name ATOM, I know I've once seen it in some old Microsoft Win32 API documentation that it is an acronym of "Access to Memory" or something like that. It is a term used for simple numerical identifiers (other name is "handles") which represent some internal data structures in the system.

    From obvious reasons, it wouldn't be smart to give the user direct pointers to these structures. First, because they reside in kernel space, and second, because it violates encapsulation. The user could then just free the memory which doesn't belong to it, or overwrite it, or some other stupid ideas. So the operating system simply gives it some replacement number tag (that's the ATOM), which then could be used to request the data from the system. It's also faster for the user to pass around the little number instead of the whole huge data structure. Users don't need to care about memory allocations & stuff, or accessing some data through pointers which are no longer valid, which could simply crash their programs.

提交回复
热议问题