-
-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch droids to use PagedEntityContainer<DROID>
as backing storage
#3689
Switch droids to use PagedEntityContainer<DROID>
as backing storage
#3689
Conversation
The default value is 1024 elements per page. Signed-off-by: Pavel Solodovnikov <[email protected]>
7488005
to
786cd32
Compare
This allows to disable slot reuse in `PagedEntityContainer`. The feature is temporary and will be used only until we are confident that we don't have any issues in the WZ code base regarding object pointers not updated properly, e.g. when transitioning between the base and offworld missions. So, it's to prevent cases where one object would be overwritten by another and the game code haven't noticed that. It's better to crash/assert rather than silently use one object instead of another, which could lead to unobvious and weird bugs. Signed-off-by: Pavel Solodovnikov <[email protected]>
1. Split the droid storage into pages containing 256 droids 2. Disable slot reuse to guard against memory-related issues when some object pointers won't get updated properly, e.g. when transitioning between the base and offworld missions. Signed-off-by: Pavel Solodovnikov <[email protected]>
786cd32
to
de6a149
Compare
I've pushed a commit to However I still have a concern that, in a long-duration campaign play session for example (progressing through many levels of the campaign), we'll just keep allocating blocks and never freeing them. I think it might be helpful for (Only in debug development situations should we just accumulate memory and never free it, IMHO.) |
Generally, I agree, the memory should be recycled in such cases. Although, technically, I have another proposition for how to implement this. So, to keep the internal housekeeping as simple, as it was before, I think instead of re-initializing existing pages, better to put them into "deactivated" (or "discarded") state indefinitely (that is, free their internal storage) and just allocate new ones at the end. There's even more to why I think we should just abandon older pages: Theoretically, we can run into a situation which involves undesired iteration behavior. Say, we have an iterator After some more time, we allocate a new element I'll prepare a patch to implement this. |
Great idea for |
…false` This helps to keep memory consumption under control. Existing expired pages are left in the deactivated state indefinitely instead of reallocating their storage upon expiration, so that we don't break the indexing and memory safety guarantees for the container. Signed-off-by: Pavel Solodovnikov <[email protected]>
Aside from changing droids to be allocated via a seprated
PagedEntityContainer<DROID>
, this changeset also implements a couple of other important things:PagedEntityContainer
can now be customizedvia
MaxElementsPerPage
template argument. The default value is 1024 elements.NOTE: The storage for droids uses 256 elements per page.
PagedEntityContainer
can now be configured not to reuse slots upon element erasure. In such case, the slot becomes invalid right after first use. The behavior is controlled byReuseSlots
template argument. The default value istrue
.NOTE: The storage for droids disable slot reuse feature, at least until we are sure that other memory-related and dependency-tracking issues between
DROID
instances are eliminated throughout the WZ code base.This PR should not introduce any notable performance difference. Although, memory utilization patterns should become slightly better (e.g. there should be less memory fragmentation overall).
Signed-off-by: Pavel Solodovnikov [email protected]