What exactly is GUID? Why and where I should use it?

后端 未结 15 2086
走了就别回头了
走了就别回头了 2020-12-13 07:48

What exactly is GUID? Why and where I should use it?
I\'ve seen references to GUID in a lot of places, and in wikipedia, but it is not very clear telling you where to

相关标签:
15条回答
  • 2020-12-13 08:38

    GUID or UUID (globally vs Universally) Unique IDentifier is, well, a unique ID :) When you need something really unique machine generated, there are libraries to get you one.

    See GUID on wikipedia for details.

    As to when you don't need a GUID, it is when a counter that you control (one way or another, like a SERIAL SQL type or a sequence) gets incremented. Indexing a "text" value (GUID in textual form) or a 128 bit binary value (which a GUID is) is far more expensive than an integer.

    0 讨论(0)
  • 2020-12-13 08:38

    Someone said they are conceptually 128-bit random values, and that is substantially true, but having done a little reading on UUID (GUID usually refers to Microsoft's implementation of UUID), I see that there are several different UUID versions, and most of them are not actually random. So it is possible to generate a UUID for a machine (or something else) and be able to reliably repeat that process to obtain the same UUID down the road, which is important for some applications.

    0 讨论(0)
  • 2020-12-13 08:39

    If you need to generate an identifier that needs to be unique during the whole lifetime of your application, you use a GUID.

    Imagine you have a server with sessions, if you give each session a GUID, you are certain that it will be unique for every session ever created by your server. This is useful for tracing bugs.

    0 讨论(0)
  • 2020-12-13 08:42

    128-bit Globally Unique ID. You can generate GUIDs from now until sunset and you never generate the same GUID twice, and neither will anyone else. They are used a lot with COM.

    As for example of something you would use them for, we use them in one of our products. Our users can generate categories and cards on various devices. We want to make sure that we don't confuse a category made on one device with a category created on a different one, so it's important that IDs are unique no matter who generates them, where they generate them, and when they generate them. So we use GUIDs (actually we use our own scheme using 64-bit numbers but they are similar to GUIDs).

    0 讨论(0)
  • 2020-12-13 08:42

    The Wikipedia article on GUIDs is pretty clear on what they are used for - maybe rephrasing your question would help - what do you need a GUID for?

    0 讨论(0)
  • 2020-12-13 08:46

    GUID = Global Unique IDentifier.

    Use it when you want to uniquely identify something in a global context.

    This generator can be handy.

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