-
March 11th, 2011, 12:02 AM
#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.
-
March 11th, 2011, 03:14 AM
#2
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.
-
March 11th, 2011, 03:21 AM
#3
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.
-
March 11th, 2011, 04:00 AM
#4
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.
-
March 11th, 2011, 04:33 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|