CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2014
    Posts
    2

    [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.

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207

    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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
  •  





Click Here to Expand Forum to Full Width

Featured