by drakinite » Wed Aug 23, 2023 3:58 pm
Sorry for the late response. You're right, to get a read lock you need to use the locked method and put your code in a callback. Inside a read lock, you can use
getValue and
getFastObject. getFastObject is faster than getValue when you call it multiple times because it doesn't require extra memory allocation, but it reuses the same item in memory so you can't use it when storing track data for later use.
beginUpdate and
endUpdate are unrelated to read/write locking and are instead used if you plan to modify the list, where a single change event is fired once after you're done, instead of firing a change event any time you make a modification. Haven't checked the source code but I think you should do beginUpdate and endUpdate inside of a modifyAsync callback. If you want to update *track data* like a song title you don't need to use modifyAsync, but if you want to add/remove songs from the list, modify the selected index, etc., use modifyAsync.
The new (WIP) documentation pages aren't super clear on those distinctions, and I can't find the SharedList blurb from the old documentation page (
https://www.mediamonkey.com/docs/api/cl ... dList.html) so I'll try and make sure that's added.
Sorry for the late response. You're right, to get a read lock you need to use the locked method and put your code in a callback. Inside a read lock, you can use [url=https://www.mediamonkey.com/docs/apinew/classes/Native.SharedList.html#getValue]getValue[/url] and [url=https://www.mediamonkey.com/docs/apinew/classes/Native.SharedList.html#getFastObject]getFastObject[/url]. getFastObject is faster than getValue when you call it multiple times because it doesn't require extra memory allocation, but it reuses the same item in memory so you can't use it when storing track data for later use.
[url=https://www.mediamonkey.com/docs/apinew/classes/Native.SharedList.html#beginUpdate]beginUpdate[/url] and [url=https://www.mediamonkey.com/docs/apinew/classes/Native.SharedList.html#endUpdate ]endUpdate[/url] are unrelated to read/write locking and are instead used if you plan to modify the list, where a single change event is fired once after you're done, instead of firing a change event any time you make a modification. Haven't checked the source code but I think you should do beginUpdate and endUpdate inside of a modifyAsync callback. If you want to update *track data* like a song title you don't need to use modifyAsync, but if you want to add/remove songs from the list, modify the selected index, etc., use modifyAsync.
The new (WIP) documentation pages aren't super clear on those distinctions, and I can't find the SharedList blurb from the old documentation page (https://www.mediamonkey.com/docs/api/classes/SharedList.html) so I'll try and make sure that's added.