c++ - How do I edit the contents of a Qvector that is within a Qvector -


i'm writing program simulate cache. i'm using qvector structure. have qvector of qvectors of ints. when try edit integers, causes runtime error:

*** glibc detected *** ./comporgproject3: free(): invalid next size (fast): 0x00000000010d2550 *** ======= backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7fd31b469b96] ./comporgproject3[0x402558] ./comporgproject3[0x402bf3] ./comporgproject3[0x402005] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fd31b40c76d] ./comporgproject3[0x4023c1] ======= memory map: ======== 00400000-00405000 r-xp 00000000 08:01 404625                             /home/**/documents/comporgproject3/comporgproject3 00604000-00605000 r--p 00004000 08:01 404625                             /home/**/documents/comporgproject3/comporgproject3 00605000-00606000 rw-p 00005000 08:01 404625                             /home/**/documents/comporgproject3/comporgproject3 010cb000-010ec000 rw-p 00000000 00:00 0      

here cod being run: main:

#include <fstream> #include <qstringlist> #include <iostream> #include <qfile> #include <qtextstream> #include <qdebug> #include <cstdlib> #include <string> #include "cache.h"  using namespace std;  int main() {      qfile instfile;     instfile.setfilename("test.trace");      int cachesizes[4] = {1024, 4096, 16384, 65536};     int blocksizes[4] = {8, 16, 32, 64};     qstring types[4] = {"dm", "2w", "4w" , "fa"};      if(!instfile.open(qiodevice::readonly))     {         return -1;     }      qtextstream in(&instfile);      qstringlist instlist;     while(!in.atend())     {         qstring temp;         temp = in.readline();         instlist.append(temp);     }      for(int = 0; < instlist.size(); i++)     {         cout << instlist.at(i).tostdstring() << "\n";     }      for(int = 0; < 4; i++)     {         for(int j = 0; j < 4; j++)         {             for(int k = 0; k < 4; k++)             {                 cache c(cachesizes[i], blocksizes[j], types[k], instlist);                 c.simulatecache();             }         }     }      return 0;  } 

this simulate function have qvectors:

void cache::simulatecache() {      if(this->instlist.size() < 1)     {         screenout << "cannot simulate cache: there no instructions";     }     else     {         screenout << "starting simulation...\n";         int entry_per_block = block_size / 4;         block_count = cache_size / block_size;         qvector<qvector<int> > ca(block_count);         for(int = 0; < block_count; i++)         {             ca[i].resize(entry_per_block);         }         screenout << "qvector created.\n";          for(int = 0; < this->instlist.size(); i++)         {             qstringlist inst_parts = instlist.at(i).split(qregexp(" "));             qstring insttype = inst_parts.at(0);             int mem_addr = inst_parts.at(1).toint(0, 16);              if(this->type.compare("dm") == 0)             {                 int block_index = (int) (mem_addr / block_size) % block_count;                 int block_offset = mem_addr % block_size;                  if(ca.at(block_index).at(block_offset) == mem_addr)                 {                     this->hits++;                     if(insttype.compare("w") == 0)                     {                         this->cachetomem+=block_size;                     }                 }                 else                 {                     this->misses++;                     this->memtocache += block_size;                     ca[block_index][block_offset] = mem_addr;                      if(insttype.compare("w") == 0)                     {                         this->cachetomem+=block_size;                     }                     for(int = block_offset - 1; >= 0; i--)                     {                  //ca[block_index][i] = mem_addr - ((block_offset - i) * 4);                         //ca[block_index].insert(i, mem_addr - ((block_offset - i) * 4) );                     }                     for(int = block_offset + 1; < entry_per_block; i++)                     {                  //ca[block_index][i] = mem_addr + ((i - block_offset) * 4));                         //ca[block_index].insert(i, mem_addr + ((i - block_offset) * 4));                     }                 }              }          }          hit_rate = hits / instlist.size();         screenout << hit_rate << "\n";     } } 

this line causing error, believe:

ca[block_index][block_offset] = mem_addr; 

here simple example of using nested qvector. may want check out link:

http://www.qtcentre.org/threads/49026-2d-array-in-qt-qvector-or-qlist

also want throw qdebug statements code see if have many elements think do.

qvector < qvector < int > > matrix;  matrix.resize(10); for(int = 0; i< matrix.size(); i++) {     // note can't use foreach here!     matrix[i].resize(10); }  // sanity check: qdebug() << matrix.size() << matrix.at(0).size();  for(int r = 0; r < matrix.size(); r++) {     for(int c = 0; c < matrix.at(r).size(); c++)     {         matrix[r][c] = 10;         // qdebug() << matrix[r][c];     } } 

hope helps.

edit: here example check out:

qt 3d-array qt-objekts qvector


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -