[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
talk:CppVector
This page is to discuss "CppVector". You can ask questions or make comments.
What is a talkpage?
That the paragraph was modified, however, made clear that it was not understood which point was made. I, Bilderbikkel, added some text describing what I wanted to show:
The coding style can also be debated:
[Edit this page] [Page history] [What links here] [Printer Friendly]
talk:CppVector
This page is to discuss "CppVector". You can ask questions or make comments.
What is a talkpage?
1th March 2007, Bilderbikkel
The code under paragraph 'Memory use' was changed by Jvorwald to this:int main(int argc, char *argv[]) { const unsigned int smallSize = 10; const unsigned int bigSize = 10000; const size_t nbytes_in_int(sizeof(int)); const size_t nbytes_in_char(sizeof(char)); int smallArray[smallSize]; int bigArray[bigSize]; std::vector<int> smallVector(smallSize); std::vector<int> bigVector(bigSize); std::cout << "char: " << nbytes_in_char << std::endl; std::cout << "int: " << nbytes_in_int << std::endl; std::cout << "Small array: " << sizeof(smallArray) << std::endl; std::cout << "Big array: " << sizeof(bigArray) << std::endl; std::cout << "Small vector: " << sizeof(smallVector) << " + " << smallSize << " * " << sizeof(smallVector[0]) << std::endl; std::cout << "Big vector: " << sizeof(bigVector) << " + " << bigSize << " * " << sizeof(bigVector[0]) << std::endl; for (size_t ii(0); ii<bigSize; ii++) bigVector[ii] = ii*2; const size_t nbytes(sizeof(bigVector) + bigSize * sizeof(bigVector[0])); const size_t nchar(nbytes/nbytes_in_char); char cc[nchar]; char *cptr; cptr = (char *)(&bigVector); for (size_t ii(0); ii<nchar; ii++) cc[ii] = cptr[ii]; std::vector<int> *vptr; vptr = (std::vector<int> *) cc; if ((*vptr)==bigVector) { std::cout << " Copied into char array correctly" << std::endl; std::cout << " &bigVector = " << &bigVector << ", vptr = " << vptr << std::endl; for (size_t ii(0); ii<bigVector.size(); ii+=1000) std::cout << " bigVector[" << ii << "] = " << bigVector[ii] << " (*vptr)[" << ii << "] = " << (*vptr)[ii] << std::endl; } else { std::cout << " Did not copy into char array correctly" << std::endl; } std::cout << std::endl << "Press anything to exit"; char ch; std::cin.clear(); std::cin.get(ch); return EXIT_SUCCESS; }
- include <iostream>
- include <vector>
That the paragraph was modified, however, made clear that it was not understood which point was made. I, Bilderbikkel, added some text describing what I wanted to show:
- a static array of size 100 is 10x bigger then a static array of size 10
- a std::vector of size 100 is as big as a std::vector of size 10
The coding style can also be debated:
- The code generates an access violation
- Why use 'int main(int argc, char *argv[])' if 'int main()' is also standard C++ when you do not use argc and argv to make a point?
- Why 'return EXIT_SUCCESS' when the Standard states that the closing bracket of main() must have the same effect as 'return 0;' ?
- The code uses non-standard variable names: why use 'ii' when 'i' is 1000x more common?
- Why use 'i++' when '++i' is to be preferred?
- Why use 'char ch; std::cin.clear(); std::cin.get(ch);' when a std::cin.get() does the job as well?
[Edit this page] [Page history] [What links here] [Printer Friendly]
