   Vectors and I/O
  I am trying to read a Image data from a .bmp file into an vector in "rb" mode,but obviously I have not succeeded. The problem is that my vector size is a hugenumber.I debugged it down a certain line. And that line is fread(...). I am notsure how to read a data into vector. With array it gives no issue, but with vector...I get a problem. Anyway can you check out this code : void HeightMap::LoadHeightMap(char *Image){FILE *pFile = NULL;long int FileSize = 0; //Hold the file sizepFile = fopen(Image,"rb"); //Read our image in binary modeif(!pFile){MessageBox(NULL,L"ERROR : File Was Not Read!",L"READING FILE...",MB_OK);return;}fseek(pFile,0,SEEK_END); //set the cursor to the end of fileFileSize = ftell(pFile); //get the file sizerewind(pFile);//Set the cursor back to beginningvecHeight.resize(FileSize); //From debugging : FileSize is read as 3126 from my 32x32 height.bmp fread(&vecHeight,FileSize,1,pFile); //Read our value into the vector <----ERROR OCCURS HERE. The Size is over 20^5if(vecHeight.size() != FileSize) //Check for proper allocation{MessageBox(NULL,L"ERROR : Unable to Distribute Data " ,L"EXTRACTING DATA",MB_OK);fclose(pFile);return;}fclose(pFile); /* Print out Data */for(uInt i =0;i<vecMap.size(); i++)  //uInt defined as unsigned int{for(uInt j =0; j< vecMap[j].size();j++){cout<<vecMap[j][0]<<endl;cout<<vecMap[j][1]<<endl;cout<<vecMap[j][2]<<endl;}cout<<endl;}}
Quote:Original post by tnuttyI am not sure how to read a data into vector.fread(&vecHeight[0],FileSize,1,pFile);;  why wouldn't &vector mean &vector[0]. Doesn't the '&' of an Array start from 0?;Quote:Original post by tnuttywhy wouldn't &vector mean &vector[0]. Doesn't the '&' of an Array start from 0?&vector is the address of the vector.  &vector[0] is the address of the first element of the vector.  They are not necessarily the same thing.  If you use the same syntax with an array it will also always work.A vector is not an array.  It just works and acts like one in many ways.  Getting at the address of the data is not one of the ways.   ;  Oh,ok. Thanks. I thought vectors was a form of arrays but with capability ofbegin dynamic and with more functions.   ;  I have my terrain code working with dynamic vectors, but The problem is itsslow. My texture is 256x256. I have enable culling front face. And I havea step Size of 20 for each quad. how can I make my application faster?;Quote:Original post by tnuttywhy wouldn't &vector mean &vector[0]. Doesn't the '&' of an Array start from 0?forgive me if i'm not understanding the problem.  To access the buffer of a std::vector, you use &vectorName.front()i believe using the address of vectorName[0] leaves a VERY remote possibiliy that the buffer isn't contigious, which is not the case for the address of front().;Quote:Original post by tnuttyI have my terrain code working with dynamic vectors, but The problem is itsslow. My texture is 256x256. I have enable culling front face. And I havea step Size of 20 for each quad. how can I make my application faster?What part is slow? Rendering or loading? What graphics API are you using? Can we see your code?Also, you'd probably be better posting a new topic rather than changing the question in this topic.Quote:Original post by godsenddeathi believe using the address of vectorName[0] leaves a VERY remote possibiliy that the buffer isn't contigious, which is not the case for the address of front().Nope - if it's not contiguous then it's not a vector.   ;  By definition the STL vector class stores its elements sequentually in a contigious block of memory, so &v[0] is defined behavior, although in this case I find its use subnormal.   ;  The " &vecName[0]  " is defined and it did work. ThanksI will start a new topic to help with the speed of my application   