samedi 28 mai 2016

Smart pointer owns a dynamic container

I have a STL container (whichever you want), where I will be allocating objects dynamically acording to my requirements. I want to implement a smart pointer to achieve the following (expressed in somehow psedocode):

smart_pointer->my_container(unknown_storage)

My goal is having the smart pointer being the owner of my_container object, which has an unknown_storage; that is: I can add thousands of objects, or delete them, resize the container, shrink to fit, so forth. And, of course, when leaving the scope being sure that the smart_pointer has destroyed everything.

Thus, my questions:

  1. In general, how to implement this? con
  2. More specific, can you please advice which smart pointer and which container will be the "best" couple, in the sense of better performance, less space in memory, so forth.

Please, provide answers inside the context of C++11 / C++14 standards (nor Boost neither other non-standard libraries).

I appreciate in advance so much your help!

Aucun commentaire:

Enregistrer un commentaire