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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -