Options for uniquely identifying objects at runtime?

前端 未结 4 448
死守一世寂寞
死守一世寂寞 2021-01-03 05:45

I need to attach a unique identifier to objects at runtime. The identifier must be unique for the duration of the application. I plan to do this my having a private member

4条回答
  •  一整个雨季
    2021-01-03 06:22

    If the uniqueness is just for the life of the application, can't you use a 32-bit integer, initialized to zero, and then simply incremented with each object allocation?

    There's no need to worry about TickCount or anything like that. The number "2" is unique among numbers; it's as different from "1" and "3" as it is from "1,203,718" if all you're testing for is equality.

提交回复
热议问题