Dynamic Array Of Structures - Often Changing - HOW?

Hi All,

I need to code processing of files in C - That part is easy.
The content of these files is linked, so I need to hold the record data that I read from one file until I get some more information relating to that record, or get an end record for it, which will be in another, later, file.

I was thinking dynamic array of structure, which works in principle, but I'm not sure about removing only some of the data - I don't know that it's possible?

I want to hold the information in memory, appending new information, and only get rid of the allocated memory for a particular instance of my data once I receive an end record for it, write it away and free memory, retaining structures for all the other records.

I guess the easiest way to explain it is to say it's like a restaurant order (in processing, but the data is a structure).

How about an array of pointers to your order struct using the table number (minus 1 or whatever) for the index. You're looking at the size of a pointer in your environment times the number of tables (probably something like 400,000 bytes) just for accessing orders but the lookup would be extremely fast (O(1)), and if most of the tables have an order most of the time, you're really not wasting much memory. And hey...it's 400k, right?

Thanks for the replies.
Do I really need to do a tree, since I know the indexed value is there any alternative to give me direct access to that particular item in the list. In essence if I can have something like a database where I can update certain fields in the structure based on the structure key being known ?

a good way to approach this type of problem is to start simple, with a data structure that just uses a linear search to find the matching key. yes, not efficient but easy to program with just an array big enough to hold all the entries. . then if you want more direct access you have a choice of data structures and algorithms. binary search of a sorted array, a tree, a hash table. they each have tradeoffs. binary search and sort are supported by the C standard library so its a good next step.