1096
DF Suggestions / Re: System Memory issues to consider on a 'refactoring' of DF memory handling
« on: December 13, 2011, 07:56:59 am »Assuming Toady is using more or less typical data structures and algorithms, I imagine the memory access patterns are reasonable. What's DF programmed in anyway? C++? He's probably using STL or Boost containers if so, and they're very well written to keep that in line. Of course, if they're sufficiently large and he doesn't organize them well, that doesn't matter...I'm sure the containers are decently implemented, but cache use optimization isn't as simple as making sure to use good STL implementations. It's more about size and organisation. The fact that DF manages to use 2GB sometimes doesn't help, because it means you can't use more memory for speedup.
One change I thought of would be to have a separate 'display' fork from the running code. Simply turn the 'do stuff' DF process into a server that puts state changes into a queue along with reading from a command queue (things like 'build' or 'designate' that force a halt to the running 'do stuff' thread).That may be a good idea, but as a separate thread, not process, because of the need to share large amounts of data. Which means it wouldn't help with the 2GB limit. It could potentially help the frame rate though.
Then you would have a separate thread who's mission is simply to display state changes, interpret 'change display' requests (level up/ down, move display in a compass direction, alter display size). Even if your 'do stuff' thread had a frame-rate of 10 FPS, your display thread (running on its own core) would cheerfully display at 50 FPS, and if you gave it a 'build/ designate/ pause' command, it would receive the command right away and be able to throw a HALT signal to the 'do stuff' process. The processes could run separate cores and with totally separate memory. They would have a common I/O queue to communicate state changes and command. Both processes would still have to be aware of what memory they have to work with, so as to not CTD on the memory boundary.
Just ideas. I really don't know what the hell I'm talking about. Other than... it bites hitting a CTD on 2 GB of memory on a 9 GB machine with plenty of open real memory space.
The only warning when trying to do a 16 x 16 embark is about 'lag'. Options that are physically impossible due to the lack of available memory should be blocked with a warning, "Only X amount of space is available, alter Y and/ or Z for more of X". CTDs, especially due to memory should be exception handled, hopefully with a 'crash save in /crash' for a hope-in-hell recovery.