mercredi 14 mars 2018

C++ methods to precalculate object sizes to reduce number of memory allocations required?

I find in many things I have written in c or c++ I end up with mallocs all over the place. Can be 10s of mallocs in a single constructor.

What methods exist to try and allocate memory for object and it's contents in one go? In other words to make memory handling more efficient than to ask for memory many times over. Systematic object oriented methods, design patterns are preferred if exist.


Just to try make question less unclear:

(Let us assume that the argument list to the constructor provides us all the information to know just how large the object and all it's contents will be)

Aucun commentaire:

Enregistrer un commentaire