Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 12FA471FC for ; Thu, 11 Aug 2011 11:17:27 +0000 (UTC) Received: (qmail 93217 invoked by uid 500); 11 Aug 2011 11:17:23 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 92785 invoked by uid 500); 11 Aug 2011 11:17:15 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 92759 invoked by uid 99); 11 Aug 2011 11:17:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 11:17:05 +0000 X-ASF-Spam-Status: No, hits=0.7 required=5.0 tests=FREEMAIL_FROM,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [80.67.169.19] (HELO solo.fdn.fr) (80.67.169.19) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 11:16:57 +0000 Received: from lehrin (reverse-229.fdn.fr [80.67.176.229]) by smtp.fdn.fr (Postfix) with ESMTP id 9CAEF44098 for ; Thu, 11 Aug 2011 13:16:34 +0200 (CEST) Received: by lehrin (Postfix, from userid 5001) id 68D6B4075; Thu, 11 Aug 2011 13:16:34 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on lehrin.spaceroots.org X-Spam-Level: Received: from lehrin.spaceroots.org (lehrin.spaceroots.org [127.0.0.1]) by lehrin (Postfix) with ESMTP id 910524072 for ; Thu, 11 Aug 2011 13:16:32 +0200 (CEST) Message-ID: <4E43BA10.6080305@free.fr> Date: Thu, 11 Aug 2011 13:16:32 +0200 From: Luc Maisonobe User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110419 Thunderbird/3.1.9 MIME-Version: 1.0 To: Commons Developers List Subject: Re: [math] Read-only RealVector References: <1313048561.2738.2.camel@knuffelchen> <1313052399.2877.6.camel@knuffelchen> <4E43A1BB.3050508@free.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Old-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,FREEMAIL_FROM autolearn=unavailable version=3.3.1 Le 11/08/2011 12:24, S�bastien Brisard a �crit : >> >> Well, in fact I would very much like to have immutable vectors too. >> Immutability is really a way to simplify implementations. Surprisingly it >> sometimes also decrease time and memory consumption, because defensive >> copies littering user code can be avoided. >> > Luc, I have a silly question. Why do you think immutable vectors would > prevent defensive copy ? Creating an immutable vector from an existing > mutable vector would require a defensive copy, wouldn't it? Yes, of course. What I meant is that when users don't have the choice and are forced to use only mutable objects, then in many places they do defensive copying, just because they do not even know if some other code will attempt to modify the object in place after they have retrieved it. So you end up with "B b = a.getB().clone()" to protect the B instance. When instances are known to be immutable, you don't copy them (and you often neither implement Cloneable nor set up copy constructors). > Thats the reason why I'm talking about read-only vectors, and not > immutable vectors. > The solver would keep a reference to the underlying (mutable) vector, > so would be able to modify (indirectly) the read-only vector. > The observer would only have a reference to the read-only vector, so > would not be able to modify the underlying vector. The problem with this approach is that the observer could not preserve the instance across several calls (for example to compare the instance from one previous call to the current one). If a specific observer wants to do that, then it needs to be able to copy the instance. If the observer knows the object is immutable, it will only preserve the reference. Luc > > S�bastien > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org