There are at least 2 ways, one is to store the data in a flat file and other is to store it in the database.
In case of flat file, you create a file format like:
[current position]<-- here is no new line
[data 1 length][data 1 in serialized format]<-- here is no new line
[data 2 length][data 2 in serialized format]
[data 3 length][data 3 in serialized format]
[data etc. length][data etc. in serialized format]
When you have a :
- push(), you append to the file
- pop(), you use RandomAccess and seek out the element on current
[current position]
, and after that increment [current position]
with [data x length]
.
In case of database, you create a table like:
[id][element data columns]
1
2
3
etc.
When you have a :
- push(), you append to the database
- pop(), you use query element by it's id at current_item++; what is stored at your class info.
More things to note: If you need to remove elements, then it might be better, if you do not remove items as soon as you pop(), but later and many items at a time. You should get more then one element when you read, and not bother flat file / database each time you need an item.