Originally Posted by
DrakeFish
Calling RPM (ReadProcessMemory) is usually something you want to do as less frequently as possible. I have no idea what your current code looks like and your application could be slowed down for other reasons, but a tip would be to try to optimize it so you you call RPM less frequently. By example, you could read an entire "object" at once and then access its fields directly in your process' memory instead of reading each field with a RPM of 4-bytes. While doing that, considering only one thread is doing the reading, you should also re-use the same buffer instead of allocating/freeing one every time.
These are pretty obvious tips but your question doesn't really go into details concerning what you're currently doing.
You're right, please let me elaborate. As of right now my update loop looks like this:
Code:
RPM GameState
if (not in game)
return;
RPM EntityList (2)
RPM FirstEntity
RPM LocalGuid
RPM Camera (2)
RPM Camera Fields (3)
while (nextEntity != 0 and (nextEntity & 1) == 0)
{
RPM EntityType
switch (Type)
{
case Npc:
RPM fields (9)
case Player:
RPM fields (6)
case Object:
RPM fields (7)
}
RPM nextEntity
}
Thank you for the tips. In response to your observations: I have identified the bottleneck in the update loop, there don't seem to be any anomalies in other parts of the program. Regarding memory optimizations, Yes I'm aware of those techniques, and will be incorporating them later on. I am a bit confused though about reading the "entire" object. I have thought about this but can't understand how big the buffers should be. Especially when fields like name are two level pointers.
Here are my current ideas:
- Object caching (as you suggested), when I figure out the specifics such as the question above about buffer size.
- Partitioning entities across multiple threads in a thread pool. Each thread would read a percentage of entities.
- Refreshing certain values faster than others. For instance, camera would get refreshed faster than entities. That way when moving the camera, lag would be significantly reduced since old entity locations may be used.