vendredi 30 janvier 2015

Is it a bad idea to replace C-style array with std::valarray?

I'm working with a code base that is poorly written and has a lot of memory leaks.


It uses a lot of structs that contains raw pointers, which are mostly used as dynamic arrays.


Although the structs are often passed between functions, the allocation and deallocation of those pointers are placed at random places and cannot be easily tracked/reasoned/understood.


I changed some of them to classes and those pointers to be RAIIed by the classes themselves. They works well and don't look very ugly except that I banned copy-construct and copy-assignment of those classes simply because I don't want to spend time implementing them.


Now I'm thinking, am I re-inventing the wheel? Why don't I replace C-style array with std:array or std::valarray?


I would prefer std::valarray because it uses heap memory and RAIIed. And std::array is not (yet) available in my development environment.


Is there anything that I need to be aware of before I start?


One I can think of is that there might not be an easy way to convert std::valarray or std::array back to C-style arrays, and part of our code does uses pointer arithmetic and need data to be presented as plain C-style arrays.


Anything else?


Aucun commentaire:

Enregistrer un commentaire