getfem-users
[Top][All Lists]
Advanced

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

Re: [Getfem-users] A Question about gmm++


From: Yves Renard
Subject: Re: [Getfem-users] A Question about gmm++
Date: Tue, 22 May 2007 09:18:51 +0200
User-agent: KMail/1.9.5

Le mardi 22 mai 2007 04:50, vous avez écrit :
> Dear Sir,
>
> Could you do me a favor please?
> In my application, I create dynamically many dense matrices using new
> operator such like:
>
> Q = new gmm::dense_matrix< double >(N,M);
>
> and using delete operator to release them.
>
> My question is: Is it guaranteed that the objects are perfectly
> destroyed by using simple delete operator?
>

Yes, except if an error or an exception is thrown between the new and the 
delete (or in a function called). It is better to use an safe pointer like

std::auto_ptr<gmm::dense_matrix< double > > Q = new gmm::dense_matrix< double 
>(N,M);

The pointed object is automatically deleted. (but the copy of these pointers 
is problematic. If you need to copy the pointers, you have to use smart 
pointers such as boost ones).

In fact, it depends on the reason you need pointers. If, for instance, you 
need an arbitrary number of matrices, you can use a std::vector< 
gmm::dense_matrix< double > > which is safer.

Yves.

-------------------------------------------------------------------------
  Yves Renard (address@hidden)       tel : (33) 04.72.43.80.11
  Pole de Mathematiques, INSA de Lyon          fax : (33) 04.72.43.85.29
  Institut Camille Jordan - CNRS UMR 5208
  20, rue Albert Einstein
  69621 Villeurbanne Cedex, FRANCE
  http://math.univ-lyon1.fr/~renard
-------------------------------------------------------------------------



reply via email to

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