Advertisement
EddyLuten

ScopeStack Variadic Allocator Thingy

Oct 7th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. /* Basically, taking advantage of VS's variadic macros (http://msdn.microsoft.com/en-us/library/ms177415(v=vs.80).aspx), notice the allocation call inside of the macro: */
  2. #define stack_new(type, sa, ...) new (sa.Allocate(sizeof(type))) type(__VA_ARGS__);
  3.  
  4. /* So all you'd do is pass in the type, allocator, and the class's parameters, and you're good to go without the yucky template specialization: */
  5. {
  6.   StackAllocator stack_alloc(linear_allocator);
  7.  
  8.   SomeObject* so = stack_new(SomeObject, stack_alloc, param1, param2, param3, param4); //etc.
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement