c++ - Is there a way to return an abstraction from a function without using new (for performance reasons) -
for example have function pet_maker()
creates , returns cat
or dog
base pet
. want call function many many times, , pet
returned.
traditionally new
cat
or dog
in pet_maker()
, return pointer it, new
call slower doing on stack.
is there neat way can think of return abstraction without having new every time function called, or there other way can create , return abstractions?
using new pretty inevitable if want polymorphism. reason new works because looks free memory every time. write own operator new, could, in theory, example use pre-allocated memory chunks , fast.
this article covers many aspects of might need.
Comments
Post a Comment