     CudaSafeCall( cudaMemcpy(dev_docIds, p.docIds, sizeof(int) * p.docsLength, cudaMemcpyHostToDevice) );
     CudaSafeCall( cudaMemcpy(dev_weights, p.weights, sizeof(float) * p.docsLength, cudaMemcpyHostToDevice) );
 
+    dev_postings_docIds_pointers[i] = dev_docIds;
+    dev_postings_weights_pointers[i] = dev_weights;
     free(p.weights); free(p.docIds);
   }
 }

  if (!terms && !docs) return;

  // free docs norm
  printf("Cuda: Deallocating old docs norm memory\n");
  cudaFree(dev_docsNorm);

  // free postings
  printf("Cuda: Deallocating old postings from memory\n");
  // WARNING: THIS PROBABLY WILL NOT DEALLOCATE POSTINGS COMPLETELY
  // NOT TESTED
  int i; for(i=0; i<terms; i++){
    cudaFree(&dev_postings[i].docIds);
    cudaFree(&dev_postings[i].weights);
  }
  cudaFree(dev_postings);
}

int blocks; // blocks number depend on nomber of docs in collection

// global variables that are allocated in device
// during index allocating in gpu,
// used during evaluation
// and freed afterwards
PostingTfIdf *dev_postings;

// these variables saves all pointers generated during
// allocation of postings into gpu memory.
// It is needed to copmletely deallocate postings from gpu memory
float **dev_postings_weights_pointers;
int **dev_postings_docIds_pointers;

float *dev_docsNorm;

int terms;
int docs;

