Quote:Original post by Teknofreek
The only one that holds some merit to me is not allocating any memory in the core code. You could use custom allocators, but that scheme has its own quirks. For example, what happens if you want to use different allocation strategies for large and small objects? What if you want to use different strategies for objects that are allocated once per game/level/etc versus objects that are constantly being created and destroyed during the game. And so on. The problem with simply providing alloc/free callbacks is that it might not allow for enough customization.
Another way to go about it would be to allow the users to customize the memory allocation via template policies. That can also get a bit icky, hard to debug, and it may confuse some less experienced programmers. Personally, I think I prefer this approach to simple callbacks though.
You're right, a simple callback approach would not be as flexible as the current system. To address those limitations my preference would be for some kind of template based allocator scheme as well, something like the STL allocators. I don't think it would be any more confusing for less experienced programmers than the current scheme. In fact, for less experienced C++ programmers it's probably much less confusing. C programmers might be more comfortable with the current system. A template based allocator scheme can be made easy in the simple case (for STL containers you don't even have to know the allocators exist if you're happy with the default behaviour) and just as flexible in the general case. It would require a bit more up front engineering and design effort but I think the payoff would be well worth it.
Quote:
However, I think the real reason that the no-allocation policy feels so icky in this case is because of #2. If the class size was consistent, it would be easy to write some wrappers to allocate arrays, and so on.
That definitely makes things worse. What really bothers me is that it throws out the window any possibility of the compiler helping you catch your mistakes. Subverting the type system like this makes it much harder to catch errors at compile time which is where they are easiest and cheapest to fix.
Quote:
Well, if you are working with the same stuff I'm working with...good luck! The tools that accompany the stuff I'm working with make the engine-side code look like gold!
Ha, we very well might be working on the same project if that's the case [smile]