Skip to main content
gamedev.net
🔒 Locked

Dynamic memory fragmentation

Started by antareus 5 replies 850+ views
Original Post
antareus
antareus
I hear about watching for memory fragmentation in many discussions of dynamic memory, but don''t know when to recognize it is even happening. It has always been glazed on, but never discussed. 1. Is it even an issue nowadays with 256MB of RAM becoming the norm? 2. Does the C++ standard library exacerbate fragmentation through its heavier reliance on new/delete (as compared to C)? Do the default allocators for STL help things at all? I guess I''m wondering if I should be stingy about reusing std::string''s. 3. How do I know when it happens? How long does it take to finish defragmenting the RAM? (also I wonder how it compares to time spent garbage collecting) 4. What sorts of apps are more prone to it? The obvious answer is "apps that use dynamic memory" but this isn''t always the case (games use a lot of memory, but can allocate everything they need up front and release it in a fairly orderly fashion).
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
cbenoi1
cbenoi1
> Is it even an issue nowadays with 256MB of RAM becoming the norm?

You won''t notice anything with a "Hello World!" program. A MMORPG server will need to be careful since it has to survice for a long period of time witout its memory footprint growing without bounds. In that case, memory leaks are more of an issue than fragmentation.

> 3. How do I know when it happens?

Your app starts swapping and frame rate drops. Take a look at "Task Manager" at how your process grows with time until it kinda stabilizes.

> What sorts of apps are more prone to it?

Apps that allocate and free tons of ill-sized memory blocks. A 3D CAD system or a word processing system are more likely to have problems; that''s why you''d see ''multiple heaps'' use in them. Games typically load large chunks of geometry and alloc/free other structs using only a fraction of what it has loaded. As noted above, this is rarely an issue.

> Does the C++ standard library exacerbate fragmentation

That''s a loaded question! You could design classes that use pooled memory buffers and thus STL allocators will not be too much affected except for tree structures and other colateral structs. Like any tool, performance lies on the shoulders of the programmer that uses them. STL in general, however, promotes code bloat as developpers include template header files all over, duplicating code everywhere for minor class differences.

> I hear about watching for memory fragmentation

It is an important issue for widely distributed software, but I wouldn''t worry about it for indie projects.

-cb
antareus
antareus
Thanks for the good replies.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Krylloan
Krylloan
With virtual memory, physical memory fragmentation doesn''t really occur, and all notable memory occurs inside the process. (this isn''t entirely true, but close enough)

There are many different dynamic memory allocation algorithms that are used. AFAIK there are different implementations of malloc from "stdlib" in windows and linux.

A good allocator should only waste something like an order of magnitude less bytes than it actually uses, even after a very long time.

If you are worried about the performance of your malloc''ing, you might want to look up DLMalloc, AKA Doug Lea''s malloc. It''s way more efficient than the default Windows stdlib version, and it''s easy to incorporate into your program. I''m fairly sure the licence is free, haven''t checked yet.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.