string or Guid?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeffry van de Vuurst

    #1

    string or Guid?

    Hi,

    I'm working with Guids as the primary key of some of my tables. In my code,
    I'm working with those Guids. Now I was wondering what is the best way to
    work with Guids (in terms of performance, memory usage, etc)? Should I use
    the datatype Guid or should I convert them to strings and then just work
    with the string representation?

    The majority of the processing I do with these Guids is comparing a Guid
    with another Guid. Right now, I use the Guid datatype and I pass Guids as
    parameters to functions, but maybe it's better to use strings.

    Any ideas?

    Thanks,
    Jeffry


  • Michael Giagnocavo [MVP]

    #2
    Re: string or Guid?

    Well, as far as perf, a GUID is a 16-byte structure. If you represent it as
    a string, then it'll use more memory (each byte will become 2 characters,
    and each character is 2 bytes) -- 4 times more.

    -mike
    MVP

    "Jeffry van de Vuurst" <reply.to@newsg roup> wrote in message
    news:eaGW5ePlDH A.424@TK2MSFTNG P10.phx.gbl...[color=blue]
    > Hi,
    >
    > I'm working with Guids as the primary key of some of my tables. In my[/color]
    code,[color=blue]
    > I'm working with those Guids. Now I was wondering what is the best way to
    > work with Guids (in terms of performance, memory usage, etc)? Should I use
    > the datatype Guid or should I convert them to strings and then just work
    > with the string representation?
    >
    > The majority of the processing I do with these Guids is comparing a Guid
    > with another Guid. Right now, I use the Guid datatype and I pass Guids as
    > parameters to functions, but maybe it's better to use strings.
    >
    > Any ideas?
    >
    > Thanks,
    > Jeffry
    >
    >[/color]


    Comment

    • Jeffry van de Vuurst

      #3
      Re: string or Guid?

      Ok, thanks for the info. I guess I'll stick with Guids.

      Jeffry
      "Michael Giagnocavo [MVP]" <mggUNSPAM@Atre vido.net> wrote in message
      news:#tS9mcQlDH A.964@TK2MSFTNG P10.phx.gbl...[color=blue]
      > Well, as far as perf, a GUID is a 16-byte structure. If you represent it[/color]
      as[color=blue]
      > a string, then it'll use more memory (each byte will become 2 characters,
      > and each character is 2 bytes) -- 4 times more.
      >
      > -mike
      > MVP
      >
      > "Jeffry van de Vuurst" <reply.to@newsg roup> wrote in message
      > news:eaGW5ePlDH A.424@TK2MSFTNG P10.phx.gbl...[color=green]
      > > Hi,
      > >
      > > I'm working with Guids as the primary key of some of my tables. In my[/color]
      > code,[color=green]
      > > I'm working with those Guids. Now I was wondering what is the best way[/color][/color]
      to[color=blue][color=green]
      > > work with Guids (in terms of performance, memory usage, etc)? Should I[/color][/color]
      use[color=blue][color=green]
      > > the datatype Guid or should I convert them to strings and then just work
      > > with the string representation?
      > >
      > > The majority of the processing I do with these Guids is comparing a Guid
      > > with another Guid. Right now, I use the Guid datatype and I pass Guids[/color][/color]
      as[color=blue][color=green]
      > > parameters to functions, but maybe it's better to use strings.
      > >
      > > Any ideas?
      > >
      > > Thanks,
      > > Jeffry
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Steven

        #4
        Re: string or Guid?

        You probably want to stick to the GUID class for the previous reason stated,
        and also, you will probably be working with the SQL uniqueidentifie r
        data-type. A GUID->uniqueidentifi er is a pretty simple cast, opposed to
        casting a string back to a GUID, then casting again to a uniqueidentifie r.


        "Jeffry van de Vuurst" <reply.to@newsg roup> wrote in message
        news:uF0mmfXlDH A.1764@tk2msftn gp13.phx.gbl...[color=blue]
        > Ok, thanks for the info. I guess I'll stick with Guids.
        >
        > Jeffry
        > "Michael Giagnocavo [MVP]" <mggUNSPAM@Atre vido.net> wrote in message
        > news:#tS9mcQlDH A.964@TK2MSFTNG P10.phx.gbl...[color=green]
        > > Well, as far as perf, a GUID is a 16-byte structure. If you represent[/color][/color]
        it[color=blue]
        > as[color=green]
        > > a string, then it'll use more memory (each byte will become 2[/color][/color]
        characters,[color=blue][color=green]
        > > and each character is 2 bytes) -- 4 times more.
        > >
        > > -mike
        > > MVP
        > >
        > > "Jeffry van de Vuurst" <reply.to@newsg roup> wrote in message
        > > news:eaGW5ePlDH A.424@TK2MSFTNG P10.phx.gbl...[color=darkred]
        > > > Hi,
        > > >
        > > > I'm working with Guids as the primary key of some of my tables. In my[/color]
        > > code,[color=darkred]
        > > > I'm working with those Guids. Now I was wondering what is the best way[/color][/color]
        > to[color=green][color=darkred]
        > > > work with Guids (in terms of performance, memory usage, etc)? Should I[/color][/color]
        > use[color=green][color=darkred]
        > > > the datatype Guid or should I convert them to strings and then just[/color][/color][/color]
        work[color=blue][color=green][color=darkred]
        > > > with the string representation?
        > > >
        > > > The majority of the processing I do with these Guids is comparing a[/color][/color][/color]
        Guid[color=blue][color=green][color=darkred]
        > > > with another Guid. Right now, I use the Guid datatype and I pass Guids[/color][/color]
        > as[color=green][color=darkred]
        > > > parameters to functions, but maybe it's better to use strings.
        > > >
        > > > Any ideas?
        > > >
        > > > Thanks,
        > > > Jeffry
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...