Hi!
I'm trying to create a queue with a single dynamic allocated buffer, which means that I don't want to allocate more memory for temporary variables, etc. The queue will be of strings.
So, I was thinking at a strategy and what do I need to keep track of.
I think I need 1 "begin" and 2 "end" pointers, because I may have two ranges in this buffer.
So, I may have a situation as follows
1 2 3
|
E2 B1 E1
|xxxxxxx| |xxxxxxxxx| |
|
where
x
are characters of a string. We have these two ranges because one ore more words that a user enqueued didn't fit between E1 and the end of the buffer, so we go in circle.
I was wondering what do you think about this approach, apart from the fact that this will lead not to the best use of this buffer, but at least we don't have to allocate intermediary buffers and deallocate them immediately after.