Thanks James. That helps. I have few more questions:
1. How can we determine if a gsl matrix is free or not? 2. Does gsl_matrix_swap_rows work by copying memory or by some other (possibly similar to pointer in spirit) mechanism. Thanks, Adarsh >> I have two gsl matrices, say A & B. I want to free the memory in A, and >> then make A owner of contents of B and free (name) B for further >> allocation. I am wondering if this is possible in the current >> architecture >> without memcpy? > >> If yes, can someone send me a small code snippet that would achieve the >> same. > > matrix->block is the memory block that stores the values > matrix->owner is an integer that indicates whether the block should be > freed with the matrix > > gsl_matrix * A = gsl_matrix_alloc(1,1); > gsl_matrix * B = gsl_matrix_alloc(9,9); > > assert(A->owner); > assert(B->owner); > > gsl_block_free(A->block); //free A's memory block without freeing A > A->block = B->block; //A takes ownership of B's block > A->data = B->data; //A points into B's block > B->owner = 0; //B is relieved of ownership > gsl_matrix_free(B); //B is free'd, but his block isn't > > > > > -- > James Bergstra > http://www-etud.iro.umontreal.ca/~bergstrj > > > > _______________________________________________ > Help-gsl mailing list > Help-gsl@gnu.org > http://lists.gnu.org/mailman/listinfo/help-gsl > _______________________________________________ Help-gsl mailing list Help-gsl@gnu.org http://lists.gnu.org/mailman/listinfo/help-gsl