List and array question
If you had a realworld app that say accepted new patients into a hospitol, using an array to enter patient objects could possibly fill and exceed array size. So we can use a List<> But Lists only accept references to ready made objects, usually from an oject[array] so it seems were back to square one? Are there other solutions?
I am having a lot of trouble articulating this question, please advise if not clear enough... I can try an example with code
Thanks,
Robert
Answers
So you would just make an array of 100 size and if it get near max just increase it in size.No. I would use a List<> with no specified size and add objects as needed.
It's all hypothetical William, but a very real challenge because some databases will quick exceed 100 in a short time. I was wondering about this because as I learned of Lists at first I thought I could replace the common array,
I disagree. I have had an application running multiple dictionaries which contained internal lists which exceeded thousand of records at a time being read from a database and written out in a conversion operation. Modern computers can handle large array sizes with large objects with no problem.
My point is that one is only looking at a certain number records at a time....not every one of them.
1. making a second temporary array and copy all of patobjdb in that array
2. find a way to use a destructor for the patobjdb array
3. then re-define patobjarray to a size of 200
Is there any better solutions than this painful solution?
Just create and use a List<> don't worry about sizes. Its unclear why you need to load every record at once. Its stored in a database correct?
William Wegerson (www.OmegaCoder.Com)- Proposed As Answer byHarry ZhuMSFT, ModeratorWednesday, November 11, 2009 3:03 AM
- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:24 AM
- No worries on patience....If R1 is a reference to a different record object no problem. I suggest you work on a test version to start you on the process. By using the List<>.Add( ) one can add all records as needed. HTH
William Wegerson (www.OmegaCoder.Com)- Proposed As Answer byHarry ZhuMSFT, ModeratorWednesday, November 11, 2009 3:02 AM
- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:24 AM
All Replies
- If one has so many records, that is a situation where one is saving/accessing the data in a database. List<> is a perfect vehicle for such operations. Its unclear why one would need to load more than 100 records at a time...but I am sure you will let us know what you need. How many records are we looking at here?
William Wegerson (www.OmegaCoder.Com) - Thanks William,
So you would just make an array of 100 size and if it get near max just increase it in size.
It's all hypothetical William, but a very real challenge because some databases will quick exceed 100 in a short time. I was wondering about this because as I learned of Lists at first I thought I could replace the common array,
like ~
patients[] patobjdb = new patients[100];
// ~ lets say in 4 hours we get 90 patients so now patobjdb[0 to 89] are filled with real active cases, say patient records
// ~ a warning program activates maybe requesting permission to make the array larger
because to use List<patients> patdb =new List<patients>();
// List is unlimited: but that doesn't help anything here, the object array patobjdb[needs increase]
// So the only thing I can think of is:
1. making a second temporary array and copy all of patobjdb in that array
2. find a way to use a destructor for the patobjdb array
3. then re-define patobjarray to a size of 200
Is there any better solutions than this painful solution?
So you would just make an array of 100 size and if it get near max just increase it in size.No. I would use a List<> with no specified size and add objects as needed.
It's all hypothetical William, but a very real challenge because some databases will quick exceed 100 in a short time. I was wondering about this because as I learned of Lists at first I thought I could replace the common array,
I disagree. I have had an application running multiple dictionaries which contained internal lists which exceeded thousand of records at a time being read from a database and written out in a conversion operation. Modern computers can handle large array sizes with large objects with no problem.
My point is that one is only looking at a certain number records at a time....not every one of them.
1. making a second temporary array and copy all of patobjdb in that array
2. find a way to use a destructor for the patobjdb array
3. then re-define patobjarray to a size of 200
Is there any better solutions than this painful solution?
Just create and use a List<> don't worry about sizes. Its unclear why you need to load every record at once. Its stored in a database correct?
William Wegerson (www.OmegaCoder.Com)- Proposed As Answer byHarry ZhuMSFT, ModeratorWednesday, November 11, 2009 3:03 AM
- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:24 AM
I might be testing your patience but I want to take a few baby steps into your explanantion:
Ok so I make the List<> perhaps as a type dictionary to use like a database and store it to a disk/file; no problems here, understood.
But then lets say i need to enter 3 new records into the database,
my_record_input( record R1) // where R1 represents for example Jim's record
~save it to List<> then save it to disk-file then next
my_record_input( record R1) // where R1 now represents for example Bob's record
~save it to List<> then save it to disk-file then next
my_record_input( record R1) // where R1 now represents for example Sam's record
~save it to List<> then save it to disk-file then next
In the above example R1 was reused for all 3 record entries, is that the way you do it, do you re-use the interface input'ed object?
Thanks,
Robert- No worries on patience....If R1 is a reference to a different record object no problem. I suggest you work on a test version to start you on the process. By using the List<>.Add( ) one can add all records as needed. HTH
William Wegerson (www.OmegaCoder.Com)- Proposed As Answer byHarry ZhuMSFT, ModeratorWednesday, November 11, 2009 3:02 AM
- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:24 AM


