News for hackers. Stuff that matters.
Re:Hidden Costs of Memory Allocation by cdevfr on Wednesday December 10, 2014 @07:14AM (#8728768)
Sure it is possible. Just pass the constructor your type:

my_type* t = New( MyType ) ;

Where MyType passes information to New() of what to create.

...

I don't know what I'm downvoted.

This clearly works. The naive solution without macros would have MyType be a simple integer and New() has a switch statement. But it is easy to avoid that.

Re:Hidden Costs of Memory Allocation by pmr_ on Wednesday December 10, 2014 @09:12AM (#8729193)
You are being downvoted because the language comes with well-defined and specifically designed ways to customize allocation/deallocation. Your approach choses to ignore those facilities and even adds a runtime decision to code that absolutely has no need for it. You are reinventing the wheel and it is not even round.
Re:Hidden Costs of Memory Allocation by pjc50 on Wednesday December 10, 2014 @09:17AM (#8729216)
Because what you've written doesn't make much sense? You can't pass a type as a function parameter to a user defined function, and if you mean the builtin "new" (no capital) then that uses the normal allocator.
Re:Hidden Costs of Memory Allocation by fla on Wednesday December 10, 2014 @10:40AM (#8729696)
I think he meant that MyType is an enum and New is a user-defined function with a huge switch that does allocate (with placement new?) the correct type based on the value of MyType. Yea works, but introduces runtime overhead and is the gate to maintenance hell.
Re:Hidden Costs of Memory Allocation by cdevfr on Wednesday December 10, 2014 @10:21AM (#8729575)
It is basic OOP in C. Look it up.