I'm writing a code where I have to generate a key.bin file containing 10000 keys(1 key = 16 bytes random no.), read the Key file, and store it in the RAM. Can anyone tell me how I got about it? I'm relatively new to this, so any guidance would be great.
Thanks.
As @heap-underrun has pointed out, it is unclear if you're talking about general RAM used in PCs or some special type of memory in some other device. I will just assume that you're talking about regular RAM in PC.
When you run a program, all the variables in the program are stored in the RAM until the program terminates. So, all you need to do is to read the file in your program and store the data in a variable. Then the data will be stored in RAM till your program terminates. https://www.cplusplus.com/doc/tutorial/files/ should be a good reference to file I/O in C++.
I will give a simple example here. Assuming your file looks like this
00001
00002
00003
...
A simple C++ code to read the file is,
#include<fstream>
using namespace std;
int main(){
int n = 10000; //number of keys in file
long double keys[n]; //because you said 16 bit number
//and long double is 16 bit
ifstream FILE;
FILE.open("key.bin"); //include full path if the file is in
//a different directory
for(int i = 0; i < n; i++){
FILE >> keys[i];
}
FILE.close();
}
Now, all the keys are in keys
array. You can access the data and do whatever you want. If you are still unclear about something, put it in the comments.