CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1

    Storing 1 lakh Records in data structure

    Hi,

    Code:
    struct student
    {
      int age;
      char name[20];
       float weight;
      .............
      ........................
    };
    Assume that student structure size is 100 bytes. I want to store 1 lakh or more such student variables.Performance is the constraint. Which data structure can be used? Searching,sorting is not required. Storage is only requirement.

  2. #2
    Join Date
    Dec 2007
    Posts
    45

    Re: Storing 1 lakh Records in data structure

    What performance?
    If you need to quickly store (as in "add") a new student struct at any time, use list or deque, then you can even remove them quickly at any time.

    If the student count doesn't change much, I'd use vector. Vector does only 1 allocation and imroves performance of the rest of your program. Also when you iterate a vector (for each), CPU caching improves speed of that. If you do need to push_back a new student every now and then, use vector::reserve.
    - If you know what you want then you do not know yourself good enough.

  3. #3
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Storing 1 lakh Records in data structure

    in the age of C++ you can just used a vector as in
    vector<student> mylist; // provided you system as adequate RAM
    or if you want to do it old school way then.

    Code:
    typedef struct _student
    {
      int age;
      char name[20];
       float weight;
       student *next;
      student * previous;
    } student;
    that is double linked list.
    for those who do not know what 1 lakh means it is one hundreds thousand ,

    if you are going to write the structure to a file then make sure compiler added padding is removed.

  4. #4
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Storing 1 lakh Records in data structure

    If you are looking for performance, re-consider your char[20]. This will consume a lot of memory, regardless of what you put into it (not to mention overflow problems).

    What kind of performance are we talking about? adding and removing objects? traversing container? Accessing specific item? Creation of actual objects?

    Do you want speed, or memory?

    Something else you could look into is fixed size allocator.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  5. #5
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Storing 1 lakh Records in data structure

    Hi,

    One thing to consider is whether there will be many duplicates in the student names.

    If so, you might be able to use that to advantage to keep the data size small, particularly if you are able to separate first & last names. Store the list of names in a map, and store the key in the data structure.

    Alan

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