Re: RFC: getting a unique integer value


Subject: Re: RFC: getting a unique integer value
From: Martin Sevior (msevior@mccubbin.ph.unimelb.edu.au)
Date: Sat Oct 13 2001 - 09:06:30 CDT


On Fri, 12 Oct 2001, Matti Picus wrote:

> Generating a unique int ID seems to be faulty in many places in AbiWord.
> The general method is to use the result from UT_rand() and hope that it is
> unique.

Thanks to Pat Lam we have a great XP random number generator. This will on
average give you an identical random number one in 2^32 attempts. That's
approximately 1 in 4,000,000,000 attempts so we're pretty safe :-)

I recently modified the RTF importer with a different method:
> using a static member variable.
>
> I hope the construct is portable to all platforms.
>
> Here is what it looks like:
> -------- NeedToIncrement.h-----------------
> class NeedToIncrement
> {
> static UT_uint32 m_incrementer;
> UT_uint32 m_ID;
> }
> -----------------------------------------
>
> --------NeedToIncrement.cpp---------------
> NeedToImcrement::NeedToIncrement()
> {
> m_ID = m_incrementer++;
> }
> // Static data members must be initialized at file scope.
> UT_uint32 NeedToImcrement::m_incrementer = 100;
> -------------------------------------------
>

I want to reserve the first the 10000 ID numbers for future use. Please
start this off above 10000.

Cheers

Martin



This archive was generated by hypermail 2b25 : Sat Oct 13 2001 - 09:06:45 CDT