Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the GUID structure declared the way it is?

Tags:

guid

In rpc.h, the GUID structure is declared as follows:

typedef struct _GUID 
{  
   DWORD Data1;  
   WORD Data2;  
   WORD Data3;  
   BYTE Data[8];
} GUID;

I understand Data1, Data2, and Data3. They define the first, second, and third sets of hex digits when writing out a GUID (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX).

What I never understood was why the last 2 groups were declared together in the same byte array. Wouldn't this have made more sense (and been easier to code against)?

typedef struct _GUID 
{  
   DWORD Data1;  
   WORD Data2;  
   WORD Data3;  
   WORD Data4;  
   BYTE Data5[6]; 
} GUID;

Anyone know why it is declared this way?

like image 782
Eric W Avatar asked Nov 09 '08 21:11

Eric W


People also ask

What is the structure of a GUID?

GUID structure (guiddef. A GUID is a 128-bit value consisting of one group of 8 hexadecimal digits, followed by three groups of 4 hexadecimal digits each, followed by one group of 12 hexadecimal digits.

What is GUID structure in C#?

A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.

Why do we need GUID in C#?

we use GUID because it have very low probability of being duplicated as it is 128-bit integer(16 bytes) which allow to use GUID across all databse and computer without data collision.

How are C# GUIDs generated?

Basically, a a GUID is generated using a combination of: The MAC address of the machine used to generate the GUID (so GUIDs generated on different machines are unique unless MAC addresses are re-used) Timestamp (so GUIDs generated at different times on the same machine are unique)


1 Answers

It's because a GUID is a special case of a UUID. For information on what all the fields mean, you can look at RFC 4122.

like image 91
ReinstateMonica Larry Osterman Avatar answered Sep 20 '22 19:09

ReinstateMonica Larry Osterman