-
June 5th, 2014, 08:01 AM
#1
[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.
-
June 5th, 2014, 10:54 AM
#2
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>)
Last edited by ovidiucucu; June 5th, 2014 at 10:57 AM.
-
June 6th, 2014, 06:49 AM
#3
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).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|