🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Do you know a way to avoid memory fragmentation ?

Started by
16 comments, last by SyncViews 4 years, 5 months ago

@Juliean Thank, great link. I never know about it.

Advertisement

Ok thank you guys ?

theScore said:
How to avoid memory fragmentation, with C++ ?

What are you trying to solve for, specifically?

Modern PCs have a lot of memory, and complex virtual memory management in the OS. As a result fragmentation generally isn't that much of a problem unless either the problem you are solving requires very unpredictable allocation patterns, or your software is designed to run for extremely long period of time (i.e. months-years of uptime required).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I was thinking about smartphone game programming. Do you think could be applied to this kind of hardware ? ( like iPhones, iPads, android smartphones, etc…)

It can be, but fragmentation is rarely going to be the top-of-mind problem in smartphone development. Limits on the total amount of memory you can allocate and memory bandwidth constraints are both liable to become a problem before fragmentation does.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Ok, thanks for your advice ?

I believe most of the modern standard allocators are also a lot better at not causing fragmentation than the early implementations when I heard a lot more about general purpose custom allocators. I didn't looks into / reverse engineer the MSVC/libc/etc. but I believe they use different memory regions based on the allocation size ("buckets"?) to avoid small objects fragmenting space larger objects will need to be continuous.

Also anywhere with 64bit virtual memory (or otherwise virtual memory much larger than RAM/pagefile which still applies to many mobile devices) will get a lot more freedom as pages need not be continuous in physical memory, so as long as small objects are not scattered across thousands of different pages needlessly wasting physical memory, there is less of an issue. Even a massive 1GB object doesn't actually need 1GB continuous RAM, and finding a free GB of virtual addresses in 64bit is fairly easy.

This topic is closed to new replies.

Advertisement