I need a class (in C++11) which stores a couple of fields(including a buffer). I started with malloc()
in a constructor and free()
in a destructor (I didn't touch C/C++ for quite some time so that was all I remembered).
Next thing I remembered (because of crashes) that I need to implement a copy constructor and an assignment operator. Now, I have a full screen of code just for a class with 3 fields (one of which is the buffer).
A question.
What should I use? (I am dazzled by amount of choices - std::vector
, std::array
, std::shared_ptr
, boost::scoped_ptr
and may be something else).
Functionality for this buffer which I am looking for are:
- as little as possible memory management
- getting rid of these copy constructors and assignment operators
- ability to use it as void* (I have to pass it to functions which accept "void*")
- ability to access read/write it randomly (I may need to get a random range out of it and write a random range to it)
- allocate it on the heap (buffer can be reasonably large)
- preferably usage of some standard facility
Aucun commentaire:
Enregistrer un commentaire