From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: LISP Questions - random, random elements and memory management Date: Thu, 19 Nov 2009 20:52:17 -0700 Message-ID: References: <20091119.101614.37733655.jeff@chaosphere.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1258689188 6473 80.91.229.12 (20 Nov 2009 03:53:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 20 Nov 2009 03:53:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 20 04:53:02 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NBKYP-00008B-Ps for geh-help-gnu-emacs@m.gmane.org; Fri, 20 Nov 2009 04:53:02 +0100 Original-Received: from localhost ([127.0.0.1]:47675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NBKYP-0007fJ-46 for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 22:53:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NBKY5-0007dW-63 for help-gnu-emacs@gnu.org; Thu, 19 Nov 2009 22:52:41 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NBKY0-0007Wt-Lz for help-gnu-emacs@gnu.org; Thu, 19 Nov 2009 22:52:40 -0500 Original-Received: from [199.232.76.173] (port=56459 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NBKY0-0007Wl-K1 for help-gnu-emacs@gnu.org; Thu, 19 Nov 2009 22:52:36 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:55265) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NBKY0-0007vl-4Y for help-gnu-emacs@gnu.org; Thu, 19 Nov 2009 22:52:36 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1NBKXx-0008T9-NQ for help-gnu-emacs@gnu.org; Fri, 20 Nov 2009 04:52:33 +0100 Original-Received: from c-71-237-24-138.hsd1.co.comcast.net ([71.237.24.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 Nov 2009 04:52:33 +0100 Original-Received: from kevin.d.rodgers by c-71-237-24-138.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 Nov 2009 04:52:33 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 51 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: c-71-237-24-138.hsd1.co.comcast.net User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) In-Reply-To: <20091119.101614.37733655.jeff@chaosphere.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69957 Archived-At: Jeff Clough wrote: > From: Barry Margolin > Date: Thu, 19 Nov 2009 08:44:24 -0500 > >> How about putting it in a text file that you load into a temporary >> buffer when you need it? Then kill the buffer when you're done with it. Isn't the point to read the words into a list? So assuming the file looks like: ("word1" "word2" "word3" ... "wordN") Then this kills the buffer automatically but keeps the list in memory: (defvar word-list nil) (with-temp-buffer (insert-file-contents-literally "wordlist.el") (setq word-list (read (current-buffer)))) And when he's done with the data, this should release it: (setq word-list nil) (garbage-collect) > I was thinking about this. The only real issue is with figuring out a > good lifecycle for the buffer that wouldn't leave the user confused > ("Hey, where did this buffer come from?") or result in the file being > loaded/unloaded frequently enough to cause delays. Instead of freeing the data immediately after using it, use run-at-time to create a timer to do so some time in the future. If in the meantime, it needs to be used, just cancel the timer (a new timer will be created when this use completes). You can tell whether you need to reload the list or not by testing whether word-list is nil. > At this point, after dicking around in the Emacs Lisp manual, I'm > going to keep this as a "load" in my .emacs and assume that anyone who > wants to use the code will either do the same, or set up an autoload > expression if they care about memory usage. When I know more about > provide/require, I'll probably revisit it. You could use provide/require/unload-feature, but it would be a level of indirection (the feature symbol) that just hides what you're really trying to do. -- Kevin Rodgers Denver, Colorado, USA