Live data from Hacker News

Ask HN: Is memory fragmentation with C still an issue?

news.ycombinator.com

1–3 of 3 posts

Ask HN: Is memory fragmentation with C still an issue?

#1
I'm looking to create a game in C++ using OOP extensively. One requirement is the use of references to handle objects. I have read that dynamic memory (new/mallo) causes heap fragmentation, i would like to know what the solutions are to the fragmentation, thanks!

Re: Ask HN: Is memory fragmentation with C still an issue?

#2
It depends on the implementation of malloc. But usually yes, memory allocated at the same time is not at the same location. The solution is to allocate a big chunk at once and place your data in the order you want it. You can use, for example placement new for the objects and indices for references.

Re: Ask HN: Is memory fragmentation with C still an issue?

#3

It depends on the implementation of malloc. But usually yes, memory allocated at the same time is not at the same location. The solution is to allocate a big chunk at once and place your data in the order you want it. You can use, for example placement new for the objects and indices for references.

A problem with the chunk system is that i don't know how big a chunk is at the time it's declared?