Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am not an expert in programming, but I would like to improve my knowledge. Here's what it's all about, I'm writing a script and I want to create a plugin that would serve me to store data per player, read (open.mp | Per-player variable system[^])
Even though it exists already a plugin that is no longer being upgraded it uses unordered_map and that system is a shade faster than PVAR but still slower than normal variables. My question is, is there any faster and better way to be close to normal variables? Sorry for my english, google translate helped me

What I have tried:

it's just a simple question.......
Posted
Updated 25-Feb-24 4:39am
v2

Without information on exactly what the data looks like, it is hardly possible to suggest suitable data structures. For an unknown number of data records, for example, a vector could be considered. Considering a scenario where the data per player can grow over time, it is important to choose a data structure that can handle the addition of new data efficiently. Important parameters would be access speed, insertion efficiency and memory consumption. An unordered_map could be favorable on average. System performance and memory consumption should be investigated. Often a combination of several data structures is advantageous, enabling both fast lookups and efficient insert operations.
Without more specific information about which data should be stored and how it should be accessed, it is almost impossible to make a concrete recommendation.

//edit:
Quote:
now imagine performing checks on 1000 players at once

The requirement that it should be possible to update a large number of active players and calculate interactions efficiently can be met by multithreading. Multithreading makes it possible to execute tasks in parallel and thus improve performance, especially when it comes to processing a large amount of data.
Simultaneous access to shared data usually requires synchronization. This can be done by using mutexes, atomic operations or other synchronization techniques.
The selected data structure must be thread-safe or appropriately secured to ensure that multiple threads can access it safely without causing data corruption.
Standard library data structures such as unordered_map and vector require additional synchronization as they are usually not automatically thread-safe.
Presumably, it would be easier to achieve thread safety with vector, since the elements are arranged sequentially in memory and access to different indices can possibly be parallelized. The interference with accesses to an unordered_map could be more difficult to handle with multithreading.
 
Share this answer
 
v2
You need to think about some in memory datastore like a big and ordered array or dictionary and some additional thread which serializes the data like on a drive or server.

Writing and reading little chuck of data from some disk or over the network is problematic. You need some snapshot and update policy.
Consider to time stamp individual datasets to optimize processes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900