Return-Path: Delivered-To: apmail-incubator-lucene-net-dev-archive@locus.apache.org Received: (qmail 17365 invoked from network); 16 Oct 2007 21:35:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Oct 2007 21:35:53 -0000 Received: (qmail 40200 invoked by uid 500); 16 Oct 2007 21:35:40 -0000 Delivered-To: apmail-incubator-lucene-net-dev-archive@incubator.apache.org Received: (qmail 40049 invoked by uid 500); 16 Oct 2007 21:35:40 -0000 Mailing-List: contact lucene-net-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@incubator.apache.org Delivered-To: mailing list lucene-net-dev@incubator.apache.org Received: (qmail 40040 invoked by uid 99); 16 Oct 2007 21:35:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2007 14:35:40 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2007 21:35:41 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id CE2E8714245 for ; Tue, 16 Oct 2007 14:34:51 -0700 (PDT) Message-ID: <18833410.1192570491842.JavaMail.jira@brutus> Date: Tue, 16 Oct 2007 14:34:51 -0700 (PDT) From: "Jon Davis (JIRA)" To: lucene-net-dev@incubator.apache.org Subject: [jira] Issue Comment Edited: (LUCENENET-103) Need to implement ICloneable on RAMDirectory In-Reply-To: <32281116.1192559450811.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LUCENENET-103?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12535347 ] stimpy77 edited comment on LUCENENET-103 at 10/16/07 2:34 PM: --------------------------------------------------------------- I should add, the objective for cloning was to make it more performant. The Directory copy approach was slower. For our purposes, the difference was 1299ms for Directory.Copy, versus 669ms for a deep clone, and 9.66ms for a shallow clone (and a LOT less RAM usage). We are going with a shallow clone because this is a multi-threaded server and there are thread locks all over the Lucene objects, but we don't modify a RAMDirectory once it is loaded. Rather, we rebuild the RAMDirectory in the equivalent of a cron job, then clone it across multiple threads. In my environment I implemented ICloneable already, using the referenced hyperlink. namespace Lucene.Net.Store { ... public sealed class RAMDirectory : Directory, ICloneable { ... #region ICloneable Members /// /// Creates a clone of the RAMDirectory. /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// A RAMDirectory object. public object Clone(bool deep) { RAMDirectory clone = new RAMDirectory(); System.Collections.IDictionaryEnumerator enmr = files.GetEnumerator(); while (enmr.MoveNext()) { string name = (string)enmr.Key; RAMFile rf = (RAMFile)enmr.Value; clone.files.Add(name, rf.Clone(deep)); } return clone; } public object Clone() { return Clone(false); } #endregion } class RAMFile : ICloneable { ... #region ICloneable Members /// /// Creates a clone of the RAMFile. /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// A RAMFile object. public object Clone(bool deep) { RAMFile clone = new RAMFile(); if (!deep) { clone.buffers = (System.Collections.ArrayList) buffers.Clone(); } else { clone.buffers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); for (int i = 0; i < buffers.Count; i++) { byte[] buf = (byte[])buffers[i]; byte[] cloneBuf = (byte[])buf.Clone(); clone.buffers.Add(cloneBuf); } } clone.length = length; clone.lastModified = lastModified; return clone; } /// /// Performs a shallow copy of the object. /// /// public object Clone() { return Clone(false); } #endregion } } was (Author: stimpy77): In my environment I implemented ICloneable already, using the referenced hyperlink. namespace Lucene.Net.Store { ... public sealed class RAMDirectory : Directory, ICloneable { ... #region ICloneable Members /// /// Creates a clone of the RAMDirectory. /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// A RAMDirectory object. public object Clone(bool deep) { RAMDirectory clone = new RAMDirectory(); System.Collections.IDictionaryEnumerator enmr = files.GetEnumerator(); while (enmr.MoveNext()) { string name = (string)enmr.Key; RAMFile rf = (RAMFile)enmr.Value; clone.files.Add(name, rf.Clone(deep)); } return clone; } public object Clone() { return Clone(false); } #endregion } class RAMFile : ICloneable { ... #region ICloneable Members /// /// Creates a clone of the RAMFile. /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// /// If is true, the clone is made /// at the byte level. /// If is false, the clone is made /// at the buffers' references level. /// /// A RAMFile object. public object Clone(bool deep) { RAMFile clone = new RAMFile(); if (!deep) { clone.buffers = (System.Collections.ArrayList) buffers.Clone(); } else { clone.buffers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); for (int i = 0; i < buffers.Count; i++) { byte[] buf = (byte[])buffers[i]; byte[] cloneBuf = (byte[])buf.Clone(); clone.buffers.Add(cloneBuf); } } clone.length = length; clone.lastModified = lastModified; return clone; } /// /// Performs a shallow copy of the object. /// /// public object Clone() { return Clone(false); } #endregion } } > Need to implement ICloneable on RAMDirectory > -------------------------------------------- > > Key: LUCENENET-103 > URL: https://issues.apache.org/jira/browse/LUCENENET-103 > Project: Lucene.Net > Issue Type: Improvement > Environment: C# 2.0 > Reporter: Jon Davis > Priority: Minor > > IClonable needs to be added to Lucene.net's RAMDirectory. > See Lucene (Java) item resolution at: > http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg03725.html -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.