Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error "read access violation" appears randomly

Error "read access violation" appears randomly

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CyxouD
    wrote on last edited by CyxouD
    #1

    Hello
    I was making my hashtable visual project based on linear probing and got some issue.
    I have a variable N,which was declared privately,that describes how many elements in hashtable, then i have a method **put **,where i get problem when incrementing N(N++) exactly after or in more put after resizing hashtable with method resize(I think they are connected with this issue may be?) .In debugger it is "Exception at 0x5028bff6, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)" and variable N,as i said,is 2 or 3(N=2,N=3). I would appreciate any help.

    Added:Hmm.. if i made this process manually(putting elements) and initialize with N=0 in constr then the same exception appears when N=2 in String 18 of method resize : temp->put(keys[i],vals[i]);

    void put(QString key,QString val)
        {
            if (val==NULL)
            {
                deleteKey(key);
                return;
            }
    
            **if (N>=M/2) resize(2*M);**
    
            int i;
            for (i=(qHash(key) & 0x7fffffff) % M;keys[i]!=NULL;i=(i+1) % M) {
              if (QString::compare(keys[i],key)==0) {vals[i]=val; return;}
            }
            keys[i]=key;
            vals[i]=val;
            N++; //here is exception
    
        } 
    
    
    void resize(int capacity)
        {
            LinearProbingHashST *temp=new LinearProbingHashST;
            temp->init(capacity);
            for (int i=0;i<M;i++) {
                if (keys[i]!=NULL){
                   temp->put(this->keys[i],this->vals[i]);
                }
           }
            keys=temp->keys;
            keys=temp->vals;
            M=temp->M;
            delete temp;
    
        }
    
    public:
        LinearProbingHashST()
        {
          init(INIT_CAPACITY);
        }
    
        void init(int capacity)
        {
            M=capacity;
            keys=new QString[M];
            vals=new QString[M];
            N=0;
        }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Do you ensure that M has a correct value ? How do you do the resize ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alex_malyu
        wrote on last edited by alex_malyu
        #3

        @CyxouD said:

         keys=temp->keys;
            keys=temp->vals;
        

        Above code seems contains undesired features.
        In any case such code complexity requires compilable simple test case.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved