help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Help with GSL Matrices


From: James Bergstra
Subject: Re: [Help-gsl] Help with GSL Matrices
Date: Thu, 25 May 2006 17:45:32 -0400
User-agent: Mutt/1.4.2.1i

> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]