Skip to main content
added 173 characters in body
Source Link
Hannah Vernon
  • 70.5k
  • 22
  • 177
  • 321

Generate new sequential GUIDs on the client end. This will reduce the frequency of page splits to a more manageable level.

In C# on Windows, the following will generate 100 sequential UUID values:

using System;
using System.Runtime.InteropServices;

namespace GUIDtest
{
    class Program
    {
        [DllImport("rpcrt4.dll", SetLastError = true)]
        static extern int UuidCreateSequential(out System.Guid guid);

        static void Main(string[] args)
        {
            Guid guid; ;
            for(var a = 0; a < 100; a++)
            {
                _ = UuidCreateSequential(out guid);

                Console.WriteLine($"guid: {guid}");
            }
        }
    }
}

Note that for cases where the security of the generated guid is not of paramount importance it's ok to generate GUIDs using this methodology since they are still going to be for all intents-and-purposes unique. This However, if the generated guid will be used to obfuscate publicly visible parameters in a URL, for example, be aware that this method uses the MAC address of the computer running the code to generate a portion of the address, thus guaranteeing its uniqueness, but also providing a path to predict future GUIDs. The one gotcha here would be ensure you aren't running this code in multiple virtual machines configured to use the same MAC addresses (they would need to be on different networks for that to even work, so this is unlikely to be a problem).

Generate new sequential GUIDs on the client end. This will reduce the frequency of page splits to a more manageable level.

In C# on Windows, the following will generate 100 sequential UUID values:

using System;
using System.Runtime.InteropServices;

namespace GUIDtest
{
    class Program
    {
        [DllImport("rpcrt4.dll", SetLastError = true)]
        static extern int UuidCreateSequential(out System.Guid guid);

        static void Main(string[] args)
        {
            Guid guid; ;
            for(var a = 0; a < 100; a++)
            {
                _ = UuidCreateSequential(out guid);

                Console.WriteLine($"guid: {guid}");
            }
        }
    }
}

Note that for cases where the security of the generated guid is not of paramount importance it's ok to generate GUIDs using this methodology since they are still going to be for all intents-and-purposes unique. This method uses the MAC address of the computer running the code to generate a portion of the address, thus guaranteeing its uniqueness. The one gotcha here would be ensure you aren't running this code in multiple virtual machines configured to use the same MAC addresses (they would need to be on different networks for that to even work, so this is unlikely to be a problem).

Generate new sequential GUIDs on the client end. This will reduce the frequency of page splits to a more manageable level.

In C# on Windows, the following will generate 100 sequential UUID values:

using System;
using System.Runtime.InteropServices;

namespace GUIDtest
{
    class Program
    {
        [DllImport("rpcrt4.dll", SetLastError = true)]
        static extern int UuidCreateSequential(out System.Guid guid);

        static void Main(string[] args)
        {
            Guid guid; ;
            for(var a = 0; a < 100; a++)
            {
                _ = UuidCreateSequential(out guid);

                Console.WriteLine($"guid: {guid}");
            }
        }
    }
}

Note that for cases where the security of the generated guid is not of paramount importance it's ok to generate GUIDs using this methodology since they are still going to be for all intents-and-purposes unique. However, if the generated guid will be used to obfuscate publicly visible parameters in a URL, for example, be aware that this method uses the MAC address of the computer running the code to generate a portion of the address, thus guaranteeing its uniqueness, but also providing a path to predict future GUIDs. The one gotcha here would be ensure you aren't running this code in multiple virtual machines configured to use the same MAC addresses (they would need to be on different networks for that to even work, so this is unlikely to be a problem).

Source Link
Hannah Vernon
  • 70.5k
  • 22
  • 177
  • 321

Generate new sequential GUIDs on the client end. This will reduce the frequency of page splits to a more manageable level.

In C# on Windows, the following will generate 100 sequential UUID values:

using System;
using System.Runtime.InteropServices;

namespace GUIDtest
{
    class Program
    {
        [DllImport("rpcrt4.dll", SetLastError = true)]
        static extern int UuidCreateSequential(out System.Guid guid);

        static void Main(string[] args)
        {
            Guid guid; ;
            for(var a = 0; a < 100; a++)
            {
                _ = UuidCreateSequential(out guid);

                Console.WriteLine($"guid: {guid}");
            }
        }
    }
}

Note that for cases where the security of the generated guid is not of paramount importance it's ok to generate GUIDs using this methodology since they are still going to be for all intents-and-purposes unique. This method uses the MAC address of the computer running the code to generate a portion of the address, thus guaranteeing its uniqueness. The one gotcha here would be ensure you aren't running this code in multiple virtual machines configured to use the same MAC addresses (they would need to be on different networks for that to even work, so this is unlikely to be a problem).