As you can see, you can either allocate/deallocate raw memory or use the allocate/deallocate templates.
However I also want to separate between engine-allocated memory and user-allcoated memorym, such as total bytes and objects allocated.I am not sure how to do it good way - the brute way is just to duplicate each allocate-method/template and add "interrnal" prefix or something, but it takes up space, looks ugly and shouldnt be part of interface.
So that means I have to have two Allocators?
Also, I want to go through my IMemoryManager interface (which the previous snippet is a part of - the actuall allocate/deallocate is passed to the engine allocator,a member of the memorymanager) - so I still have to solve not having duplicate methods.
(Adding a specific Enum parameter makes it hard in the templated function dosn't it, to distinguish from T, arg0, arg1, etc)
Wait... so you're using your allocator to pass the constructor parameters to each object as you create it? I must have missed that on the first read-through of the code, sorry.
That seems really awkward. Any particular reason you are doing it this way?
Anyways, I don't see any reason why you can't do what I originally suggested, just using a template parameter instead of a function parameter.
I thought it would be too cumbersome and ugly to do placement new and constructor/destructor call everywhere in the code. Is there a better way to do it?
Is that recommended? For example, overriding it globally could possibly cause conflicts with other libraries, and you'd need a static memory allocator?
Doing it by class-by-class basis (and then with polymorphism) seems like alot of work.
That said the obvious downside to what I have now is the number of constructor arguments. Is there anything else that springs to mind?
Also - say if I would pass an enum to one of my templated functions above, how would it distinct that enum/flag for say arg0, if my function would look more like this:
template <class T, class arg0>
inline T* AllocateObject(arg0 a0, AllocatorMode mode = NULL) { return new (Allocate(sizeof(T)),mode) T(a0); }
You can also experiment with making the allocation mode parameter the last template parameter and making it default to something, although I'm not sure how various compilers would cope with that much template argument deduction going on (it should work in anything relatively modern though).
Also - is there a nice solution to include an unspecified amount of template function arguments, like variadic functions in C?
Since the problem I have is I feel restricted by the amount of arguments I can pass to my template functions, and I feel like passing a container of arguments is too much of a hassle.
C++11 has variadic templates, but you need a conformant compiler; I don't know offhand which compilers have full variadic template support at this point. Another option is Boost which has some macro magic for generating the templates automatically.