As a side project, I am working on some home conquering issues that try to write several different implementations as a learning tool for C and C ++. Of course, the fastest way to generate low numbers is to already have them, so I want to start setting up the data file of the primary list of the hard disk. I want to write all the code that generates prime numbers, but I have no problem using already made storage methods. I have very little experience when it comes to actual coding, but I understand most of the theory. (note that for most of this I will talk about mathematical integers, not int variables)
Therefore, I have a few questions for you, experts:
1) The naive approach would consist only in binary notation of integers as they are created. However, in my head I present a list with elements separated by some kind of flag, so integers larger than 32 bits can be saved (if I get to this point). This is clearly inefficient, but something where the raw data for the array [4723, 12782, 8357] will look like 4723F12782F8357, that is, numbers are stored in the database ten with 16 bits per digit and separated F. It is obvious that the data on the capabilities of the digits ABCDE will not be used, so this is not a very efficient system, but you understand what I mean. This will also make more sense as numbers get longer, since any smallest record in any fixed-length system should be as large as the largest. I'm sure,that there must be something already written in C or C ++ that does this efficiently.
2) Another possibility is the length declaration system, where before storing each integer, a fixed length (say, 1 byte) of the data part announces how long the integer (in bits) will be. This, obviously, gives similar advantages to the previous option, with an added bonus, without losing the possibility of numbers.
Does anyone know how to store this type of data? Is a type variable I can store prime numbers so as not to fall within size limits? Even better, what is the most efficient way to store a simple list of integers to your hard drive in an easily extractable format?