What is the “atom” data type?

前端 未结 4 741
星月不相逢
星月不相逢 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:19

    The earliest thing I can find about the term "atom" is from the Lisp programming language (source). However, it probably originally came from mathematical logic. In programming they are also called Symbols and at its simplest form are name integers (an enumerated type in C would be an example). However, they are widely used in many programming languages and in the Win32 API and Acrobat API they are identifiers for strings in a table.

    Also, as Mehrdad points out, the original meaning in Greek is "indivisible", so they imply a primitive data type which cannot be broken down any further.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-01 17:38

    The RegisterClass / RegistrClassEx functions (and a few others) return an ATOM data type.

    The ATOM uniquely identifies the class being registered, but if the function fails it returns zero, so you can test if the function has failed like this

    ATOM a=0;
    .
    .
    a = RegisterClassEx(your_window);
    if (0==a)
      {
        //code for function failed
      }
    
    0 讨论(0)
  • 2021-02-01 17:42

    ATOM is a 16-bit Windows handle-like primitive. It's value is completely opaque to user-mode. It is not a pointer or an index.

    typedef unsigned short ATOM;

    0 讨论(0)
提交回复
热议问题