|
From: | Peter Johansson |
Subject: | Re: [Help-gsl] gsl_vector memory management help |
Date: | Wed, 28 Jul 2010 21:52:17 -0400 |
User-agent: | Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.7) Gecko/20100713 Thunderbird/3.1.1 |
Hi Noel, On 7/26/10 7:39 PM, Noel du Toit wrote:
The problem is that you have not implemented any copy constructor, which means you're using the compiler generated version that just copies all members. You need to implement a copy constructor that creates a new gsl_vector. Something like this IIRC:I am pretty new to C++, but as far as I can tell the memory allocation is correct, so I think it is my lack of understanding of the memory management on gsl_vector side that is causing this (hence the email to this list). Any help will be appreciated. Attached is the source code that I use, with the compile command at the top of the file.
myMember_t::myMember_t(const myMember_t other) { v = gsl_vector_alloc(DIM); gsl_vector_memcpy(v, other.v); }A good rule is that when you implement the destructor, you likely need to implement the copy constructor as well.
Cheers, Peter
[Prev in Thread] | Current Thread | [Next in Thread] |