Author Topic: Are handles ever recycled?  (Read 188 times)

FireFox

  • Posts: 7
Are handles ever recycled?
« on: 19 Aug '23 - 12:31 »
Hello, I'm wondering whether it's safe to use handles as unique identifiers? Specifically for BASS_ChannelSetSync. As sync callbacks as processed and removed (via the BASS_SYNC_ONETIME flag), is there a chance that a future call to BASS_ChannelSetSync could ever return a handle that's the same as one that was previously processed? And if so if that is a realistic chance and should therefore avoid using handles as global identifiers? Thank you

MB_SOFT

  • Posts: 459
Re: Are handles ever recycled?
« Reply #1 on: 19 Aug '23 - 15:15 »
i guess 32 bit handles starts from -2147483648 and end to 2147483647 so in my opinion it's not realistic to reach 2147483647

FireFox

  • Posts: 7
Re: Are handles ever recycled?
« Reply #2 on: 20 Aug '23 - 00:45 »
Sure, but I'm not sure whether it's a coincidence that new handles always seems to increment or whether they can reset back to -2147483648 way earlier if those initial handles are freed/disposed early.

Ian @ un4seen

  • Administrator
  • Posts: 25430
Re: Are handles ever recycled?
« Reply #3 on: 21 Aug '23 - 10:41 »
All sample/channel/DSP/FX/sync handles are currently globally unique, with each new handle being 1 higher than the previously allocated handle. Those handles are 32-bit with the highest bit always set, which means they won't start being recycled until over 2 billion (2^31) have been created. Since BASS 2.4.17, they'll now actually start being recycled after 1 billion (2^30) have been created, because bit 30 is always set for samples and their channels and unset for all other channel types (streams/mods/recordings).

It isn't really necessary for sync handles to be globally unique because BASS_ChannelRemoveSync requires a channel handle too, so it is possible that they could be changed to only be unique per-channel. So it might not be safe to assumes that sync handles will always be globally unique, if that is what you were asking?