MapElementExists(Map(), Key$)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
benubi
Enthusiast
Enthusiast
Posts: 215
Joined: Tue Mar 29, 2005 4:01 pm

Re: MapElementExists(Map(), Key$)

Post by benubi »

Beside the multi-threaded issue, there's also the problem you'd have to write a procedure for each data type the Maps may have in your program.

Also, I believe to remember PB doesn't like to Push/Pop the Map and List Positions when there's no current element. You'd have to make a few additional checks which could also be a drain on efficiency, when done in "external" PureBasic code.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: MapElementExists(Map(), Key$)

Post by freak »

You cannot safely access a Map from multiple threads as long as there is the possibility for updates. So you would still need a mutex even with this proposed command to protect against reading while an update is in progress.

If you have no updates then a local copy of the map for each thread might be the better option.
quidquid Latine dictum sit altum videtur
User avatar
idle
Always Here
Always Here
Posts: 5840
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: MapElementExists(Map(), Key$)

Post by idle »

Maybe its time to look at an alternative to a map if it cant be practically made to be thread safe.

Squint3 provides
Lock free Reads and Writes.
Keys can be strings, numeric or binary.
Dynamically grows and shrinks
Operates in constant time O(k) speed is dependent on size of the key
Generally uses less memory than a map
key space is Lexographically sorted
Can use stored cursors for faster access (single writer only) so it can be used like an In memory DB

viewtopic.php?t=79453
Post Reply