> 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
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gsl

Reply via email to