Performance improvement, accessing a list within a map
Posted: Sat Jan 20, 2024 12:00 am
Hello to all, I bought a copy of PB a while ago and picked up a lot from this forum already. I’d like to ask if the following is possible please.
My application is multi-threaded and has a global map, within which is a list of ids for that key. Each key to the map, and its associated list of ids, will only be written and read by one thread simultaneously, but they can be accessed later by another thread, hence the ‘global’. It’s like this :
It is working already, but I’d like to improve performance. I use a mutex, allowing a thread to read and write its list, without affecting others. I also reference the list by specifying the key to its map element every time :
This can be slow. Is it possible to address the list inside the map, using its @address, therefore first obtain the map key and the address of the list from that, and then avoid the need to repeatedly keep using the map key? Thanks all.
My application is multi-threaded and has a global map, within which is a list of ids for that key. Each key to the map, and its associated list of ids, will only be written and read by one thread simultaneously, but they can be accessed later by another thread, hence the ‘global’. It’s like this :
Code: Select all
Structure strdata ; Map structure, contains just a list associated with each map key
List List.s()
EndStructure
Global NewMap DataMap.strdata()
Code: Select all
LockMutex(ListMut.i)
AddElement(DataMap(mapkey.s)\List()) ; Add new list element
DataMap()\List() = dataitem.s
UnlockMutex(ListMut.i)