For this university project that I am doing (for which I have made several posts in the past), which is a kind of social network, it required users to exchange messages.
First, I designed my data structures to store ALL messages in a linked list, limiting the message size to 256 characters. However, I think my teachers would prefer it if I save the messages to disk and only read them when I need them. Of course, they will not say what they prefer, I need to make a choice and justify everything that I can, why I went along this route.
It should be borne in mind that I need to save only the last 20 messages from each user, no more.
Now I have a hash table that will act as an input, it will be inside the user profile. This hash table will be indexed by name (the user who sent the message). The value for each element will be a data structure containing an array size_twith 20 elements (20 messages, as I said above). The idea is to track file offsets on disk and recorded bytes. Then, when I need to read the message, I just need to use fseek()and read the necessary bytes.
I think this may work well ... I could use only one file to store all messages from all users on the network. I say one file, because a colleague asked the instructor to save messages from each user independently, that he replied that this might not be the best approach, because the file system has limitations. That’s why I’m thinking about switching to a single file.
However, this creates a problem ... Since I only need to save the last 20 posts, I need to discard the old ones when I reach this limit.
, ... , , fread() fwrite() / / . ", X "? , ... , , . ...
, ? ?