I have searched in vane for any forum or course or book for tutorial that gives the complete picture. First, I'll never live long enough to get my Doctoral in all the new and constant barrage of additions to C++. There is a final purpose for wanting to program. That purpose is to get data, put it into an efficient capsule, manipulate it, then, WRITE IT TO THE DISK, STORE IT! Then delete the artifacts and exit without any damage, like memory leaks, etc. Then, to recreate the mechanisms, READ THE DATA BACK IN FROM THE DISK, manipulate it and rewrite it to the disk.
Apparently, in C++ the efficient collection, manipulatation of data is with Classes, Pointers. Forget Vectors and List. Apparently they are tinker toys, not usefull for large amounts of data. We have an array of 13,000 plus Classes, with each class containing thousands of int's double's strings. Some eight or ten arrays of 6000 doubles in the basic class. If all of this data, over 13,000 classes, lives in a large computer memory where is can be rapidly accessed and manipulated, we need an I/O method that allows us to WRITE and READ all that data to and from the DISK with a single READ or WRITE method. The following seems efficient:
FILE I/O
myClass AA[13000];
EFFICIENT MANIPULATION
The above works and seems efficient, but there is no: new, delete, or pointers. Apparently for that we need something like:
myClass *p;
try{ p = new myClass[13000]; }
catch(bas_alloc xa) {cout << ..; return 1}
Now comes thousands of ways of dealing with POINTERS and REFERENCES, etc.
But, myClass AA[13000]; is not the same as myClass *p; I have not found any instruction that combines the single Disk I/O of the first with the efficiency of all the hundreds of pointer gyrations and lessons. There is never a Complete Picture. What's the point of drownding in the minutia and dangers of this barage of new C++ functions when we never get a complete and succinct picture of: HOW to CREATE it, MANIPULATE it, WRITE it to the DISK, READ it back, MANIPULATE it, WRITE it back to the DISK, with safety and efficiency.
Can you show me a complete picture? Or perhaps just point me material that gives a complete picture.
To be able to read or write something from/to disk in a single read/write operation requires that the data be stored contiguously in memory.
This limits you to using essentially POD types and aggregates of POD types.
Having said that, your above code works ONLY if myClass follows that rule. If myClass is a class/struct containing at least one virtual function or multiple inheritance or any non POD-type/aggregate members then
the code does not work.
std::vector<> by definition stores elements contiguously in RAM provided that the elements are POD types or simple aggregates of POD types.
Pointers and classes have nothing to do with your question/problem.