[RESOLVED] char myTree[350000] Bad practice?
Hi, I'm working on a piece of code written long time ago. Without getting in the details or too much context here, there is a function that declares an array of char of a size of 350,000 elements, in order to fill it (using a pointer) with the list of all running processes on the machine (using "ps -ejf" on a Linux box).
The size of the char array has been changed from 40,000 to 350,000 sometime along the years, probably because of a lack of space required.
What kind on data structure / storage would you use to store the running processes in order to eventually search for a value in it?
Thanks.
Re: char myTree[350000] Bad practice?
To keep a list of only process names, one can be std::list<std::string>.
To keep more info for each process, you can define a structure, then make a list having elements of that structure (e.g. std::list<PROCESS_INFO>)
Re: char myTree[350000] Bad practice?
rewrite the code to not require a fixed array.
properly parse the output of the command and store it in a C++ container (pick whichever one suits best).