On Fri, Jul 24, 2009 at 5:53 PM, Nicolai Hähnle<[email protected]> wrote: > The r300 program compiler has some parts in which we dynamically allocate > structures to represent values and value accesses. The memory usage pattern is > as follows: > > . Many small allocations > . Allocations live only during compilation > . While quite a few allocations could be freed early, it would be rather > cumbersome to determine exactly when freeing them is legal > > In other words, the pattern is quite typical of some arguments in favour of > garbage collection. The good thing about the compiler is, however, that we > know that *everything* can be freed once compilation is finished. > > To make life easier, I have written a memory_pool structure which supports > this type of usage pattern: One can quickly and dynamically allocate small > structures. This is achieved at the cost of being able to free those > structures dynamically. Instead, all allocations can be freed in one big sweep > at the end of the operation. > > I would imagine that such a memory pool could be beneficial to other users in > Mesa. Right now, the code is in my branch in the driver itself, but I wonder > whether I should move it outside into a generally accessible location and if > so, where. It doesn't really fit under either src/mesa nor src/gallium since > both might want it. > > Right now, the code is here: > http://cgit.freedesktop.org/~nh/mesa/tree/src/mesa/drivers/dri/r300/compiler?h=r300- > compiler > > Feedback is most welcome!
The GLSL compiler uses a similar memory allocator. See slang_mem.c. We should probably lift this code up into src/mesa/main/ and rename the functions to make it re-usable in drivers, etc. -Brian ------------------------------------------------------------------------------ _______________________________________________ Mesa3d-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mesa3d-dev
