I hope that this question will not be too weighted in the discussion, but in a clear answer.
I studied C at university and just started writing my first useful program (no spec). I just stumbled upon a problem that I still have not dealt with, and I think they did not mention this in the lecture:
When I allocate memory that can be modified, I should not store pointers to the addresses of this allocated space. Because when I redistribute, the space can be moved to another place, which makes each pointer to this region useless. This leads me to the conclusion that I cannot store a linked list inside a space, and each element lives somewhere in this space, since redistribution can invalidate all the next and prev pointers.
This is a problem that I have never encountered, so I wanted to ask you if there is any solution for this. In particular: I have a shared memory area and you want to save all my data in it so that different processes can work on it. Since data (rows) will be added and deleted frequently and should be in a specific order, I thought a linked list would be a better way. Now I realized that I can’t do this. Or am I too blind to see the obvious solution? How would you do that? (I do not want to store everything in a file, it should remain in the (main) memory)
thanks and best regards, phil
source
share