| Article: |
Knowing When to Let Go: Better Living Through Memory Management | |
| Subject: | What about preallocated memory? | |
| Date: | 2003-06-11 16:10:11 | |
| From: | anonymous2 | |
|
Many apps tend to exhaust the CPU with simple memory allocations. Especially apps that allocate and free memory dynamically upon events (say,an incoming network packet). Working with preallocated memory and reusing this memory without going through the system calls free and malloc often enhances the performance of these apps dramatically. It's a bit more complex, but it's worth your while if you have this kind of app. |
||
Showing messages 1 through 3 of 3.
-
What about preallocated memory?
2003-06-11 16:59:28 anonymous2 [View]
-
Re: What about preallocated memory?
2003-06-11 22:01:17 iapole [View]
Significantly cheaper, yes, but still expensive from some perspectives. A lot of my recent coding has been done with OpenGL, and I anticipate a point in the future where allocations will be the major bottleneck. It may be farther off than I think, of course, and I'll wait till then to optimize... but it's still a fun thing to know how to do!
-
Re: What about preallocated memory?
2003-06-11 16:26:16 iapole [View]
Agreed, definitely. Because you're working within a simpler domain than e.g. the whole system, you don't have to worry about all the stuff that the malloc/free developers had to, so you can avoid some overhead.
Of course, there's no real substitute for good design in this sort of matter. You won't get as many benefits from preallocation if your preallocated memory has to be accessible concurrently by several threads, for instance, so planning ahead is (as always) advisable.



There are problems that require pre-allocation, but they are few, and far between.