Example #1
0
nv_matrix_t *nv_matrix_realloc(nv_matrix_t *oldmat, int new_m)
{
	unsigned int offset = (unsigned int)(((char *)oldmat->v) - ((char *)oldmat));
	int mem_size = oldmat->step * new_m * sizeof(float) + sizeof(nv_matrix_t) + 0x10;
	nv_matrix_t *matrix = (nv_matrix_t *)nv_realloc(oldmat, mem_size);

	if (matrix == NULL) {
		return NULL;
	}
	matrix->m = new_m;
	matrix->cols = new_m;
	matrix->list_step = matrix->step * matrix->m;
	matrix->v = (float *)(((char *)matrix) + offset);

	return matrix;
}
Example #2
0
void *nvrealloc(void *orig_ptr,  size_t size) {

    unsigned long addr;
	void *new_ptr = NULL;

#ifdef USE_NVMALLOC
     new_ptr = (void *)nv_realloc(orig_ptr, size);
#else
	new_ptr = realloc(orig_ptr, size);	
#endif

     if(new_ptr == NULL){
		fprintf(stderr,"nv_realloc failed \n");
	 }
#ifdef USE_STATS
	addr = (unsigned long)orig_ptr;
    if(!addr){
        fprintf(stderr,"NVmalloc reallocation failed \n");
        return NULL;
    }else{
		if(hash_find(addr)) {

			if( addr == (unsigned long)new_ptr) {

				hash_insert(addr, size);
			}else {
	
				hash_delete(addr);
				hash_insert((unsigned long)new_ptr, size);
			}
		}else{
			hash_insert((unsigned long)new_ptr, size);
		}
	fprintf(stderr,"nvrealloc return %zu \n",size);
	}
#endif

    return new_ptr;
}