I need to find a way to store 250 KB of plain text numbers inside my program's executable file.
Usually, I would put the data in a separate file and let the program read it while it is running, but that's not an option here. Instead, the program and the data need to be in one executable file.
I have absolutely no idea how to do it (except writing 250.000 #defines :-) and I'd appreciate any suggestions.
How about an array of some sort. Just put that definition in a file and compile it into your program:
you can have the compiler tell you how many elements are in external data:
Lets assume the numbers are constants. Lets assume, that you can compute this list once, in "pre-compilation" stage. Lets assume that there is a function that can "return" that list.
Stage one: write an application that calls getFooNumber() and works perfectly. Nice.
Stage two: Take that function, and put it in another project. Now, lets write a small application that will generate the 250,000 lines of C code.
This will create the list Billy ONeal talked about.
Stage 3: The use the header file you just created in stage 2, and use it inside the first project to return from the new getFooNumber() the value from the lookup table.
Stage 4: Learn to use Qt, and understand that you can embed the file directly and load it using QFile(":application/numberz.txt").
Notes: * The C code is probably broken. I did not test it. * If you are usign Windows or Mac, you can probably do something similar with the resource system (MAC has a similar thing no?)
Just make a string of however many characters in your executable program, and then have another section of the program open it's self as a file, grab the bytes, find the string you have compiled and alter it however you want directly (make sure to put a unique string in there for locating the actual area with the string in binary), might need to shut the program down after executing another program which writes the data to the original program and re-executes it, when the original program is re-executed it can read the new written values from the string which was declared in it's binary and use that to perform what ever tasks.
Store it as a const array:
Presumably you know your data set so you can come up with the appropriate value for
NUMBER_MAX_LENGTH
in your case.You can also of course write a script that transforms a flat file of numbers into this format. If you want, you could even keep the numbers in a plain-text data file and have the script generate the corresponding C code as above during your build.
I wrote it that way because you said "plain text numbers", indicating that you need them as strings for some reason. If you'd rather have them as integers, it's even simpler:
Assuming that none of your numbers is too large to store in an int.
What platform are you running at? If you are on Windows and the numbers won't change in time, then just put your text file to program resources using resource linker, and read it in your code.