-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
BitMap class consumes double expected memory #48545
Comments
It happens because godot/scene/resources/bit_map.cpp Line 41 in ee44982
there's this + 1 which in this case results in resizing to (1024 * 262144) / 8 + 1 = 225 + 1 bytes and thus size being allocated is 226 bytes. The issue here with the BitMask itself is that it requests more bytes than it needs when its size is a multiply of 8.
|
Thank you for investigating, kleonc. I just want to double check I understand the explanation because, having tested more, I see I can use a Po8 size and get correct memory allocation e.g. in the test case, if I reduce x dimension by 1:
1023 x 262144 = 268,173,312 bits/size Expected allocation is around 33.5 MB, and that is what happens, which I was not expecting based on my understanding of this issue: Pre-assign: 32621520 |
I could've probably explain it better. So I'd point out two different aspects here:
So currently when
In general for In #48549 I've addressed the first issue so the To address the "unexpected amount of memory allocated" part of your issue what would need to be changed is either how |
I built an executable from 3.3-stable plus your one-line fix (3.3...belzecue:3.3-stable-AF), and memory now behaves as expected. 3.3-stable: BitMap size = (1, 1) bits / 0.125 bytes; allocated: 0 bytes; ratio: 0.00 3.3-stable + your fix: BitMap size = (1, 1) bits / 0.125 bytes; allocated: 0 bytes; ratio: 0.00
|
... for BitMap size in bytes being a Po2 (that what was fixed in there). If you'd repeat your test with creating BitMaps like this:
there will still be (almost) 2.0 |
Darn it, I got mixed up. Yes, 2x allocation for non Po2. I suppose I'll be sticking to Po2 size assignment in the meanwhile. Thanks again for providing this useful workaround. |
This was only partially fixed by #48549, what's left to fix is maybe to add a note in the documentation that BitMap memory usage grows in powers of two? |
Godot version:
3.3 stable
OS/device including version:
Linux Ubuntu 20.04.2
Issue description:
Stable documentation explains the BitMap class as:
"Every matrix element takes only one bit."
In Godot 3.3, I created a BitMap of size 1024 x 262,144 and printed the memory stats immediately before and after object creation. It showed the BitMap consuming double the memory I expected. The BitMap is 268,435,456 bits = 33,554,432 bytes, i.e. 33.5 MB.
So that's 67 MB memory consumed for that one BitMap, which is double what you'd expect if the BitMap is using bits/bytes. It's like BitMaps actually work with Uint16 instead of bytes, and ignore the extra 8 bits per word. That would explain why double the memory is being allotted. But looking at resources/bit_map.h and resources/bit_map.cpp, everything is uint8_t, so I must be missing something here.
Steps to reproduce:
Using the simple code below, memory stats show that creating one BitMap sized to 1024 x 262144 bits, i.e. 33,554,432 bytes, actually consumes 67,109,160 bytes, which is very close to 2 x 33,554,432 (67,108,864).
Minimal reproduction project:
The text was updated successfully, but these errors were encountered: