I am unable to figure it out. As, why I am getting the error
malloc: *** error for object 0x7fd812403a80: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Following is the snippets of the code. If I comment out the function call to method 'pre_compute_nCr', then the code works as expected. However, its only calling function 'pre_compute_nCr', it pops the above mentioned error. In the code, 'binom_obj (i,j)' returns the value of 'i choose k'
  void pre_compute_nCr (int n, std::vector<std::vector<uint64_t>>& n_chos_k) {
        n_chos_k[0].push_back(0);
        for (int i = 1; i < n; ++i) n_chos_k[i].resize(i, 0);
        jaz::Binom<int> binom_obj;
        for (uint64_t i = 1; i < n; ++i) {
            for (uint64_t j = 0; j <= i; ++j) {
                n_chos_k[i][j] = binom_obj(i, j);
            }  // for j  
        } // for i
    }
    int dynamicProgramming(int n, XX xx_obj) {
        std::vector<std::vector<uint64_t>> n_chos_k;
        n_chos_k.resize(n);
        pre_compute_nCr(n, n_chos_k);
        return 0;
    }
Aucun commentaire:
Enregistrer un commentaire