Hello,
I made an arbitrary precision integer library a few weeks ago. It works well, but is bounded by 256^(8*sizeof(size_t))
because it uses a simple dynamically allocated array to do its work. I want some way to have theoretically unbounded storage. I think that file io is probably best, but then I realized that stdio functions (and thus their fstream counterparts) use size_t to indicate the position in a file, so at best I will merely double the number of bits I can store. As such I thought of a format that would in a way 'cascade' files in the following way:
Typical file: +/- (indicates sign), data stored in little-endian, base-256.
File for really really big numbers: f (indicates that this is a file of files), list of files that represent integers, in little-endian base 115792089237316195423570985008687907853269984665640564039457584007913129639936 (256^32 if wolfram is to be believed).
My issue is that this will take a LOT of work to incorporate, and I want to know that it will work. I also have questions concerning implementation. For example, when a number gets too big to be stored as a dynamic array I want to shift it to a temporary file in the above format. However, since this is an active number I would like to keep the file structure open so that I don't have to keep opening and closing it. The issue is that as far as I know, its when you close the file that you actually save it.
My first question then is: is it okay to keep the file open and still use it as large storage?
Then there is the issue of the really really big numbers. A file of files would require that I open and close each file every time I need it right? There is no way to keep it open and then 'find' it?
My second question then is: is there any way to NOT have to re-open those files every time I need them?
Finally, I am wondering, if I want to use temporary files I will have to remove them in my destructor, however the remove function in the stdio library only accepts file names, not files themselves.
My third question then is: is there any way to get the file name out of a FILE structure in stdio.
I realize that using stdio in a way makes this a more c-esque question, but my program is in c++ so fstream IS an option, except that I definately need speed and as far as I know I can get more of it from stdio.
tl;dr: If you keep a FILE (stdio file type) pointer open, can you still use it for long-term storage in your program without having to continuously close and open it? Is there any way to keep a FILE pointer open and then access it via its file name without having to close and reopen it? Is there any way to get the file name out of a FILE pointer?