all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: LISP Questions - random, random elements and memory management
Date: Thu, 19 Nov 2009 20:52:17 -0700	[thread overview]
Message-ID: <he53pa$66v$1@ger.gmane.org> (raw)
In-Reply-To: <20091119.101614.37733655.jeff@chaosphere.com>

Jeff Clough wrote:
> From: Barry Margolin <barmar@alum.mit.edu>
> 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





  reply	other threads:[~2009-11-20  3:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-18 12:54 LISP Questions - random, random elements and memory management Jeff Clough
2009-11-18 13:09 ` Jeff Clough
2009-11-19  2:53   ` Kevin Rodgers
2009-11-19  3:03 ` Kevin Rodgers
2009-11-19 11:56   ` Jeff Clough
     [not found]   ` <mailman.11040.1258631785.2239.help-gnu-emacs@gnu.org>
2009-11-19 13:44     ` Barry Margolin
2009-11-19 15:16       ` Jeff Clough
2009-11-20  3:52         ` Kevin Rodgers [this message]
     [not found]         ` <mailman.11114.1258689162.2239.help-gnu-emacs@gnu.org>
2009-11-20  6:28           ` Barry Margolin
     [not found]       ` <mailman.11056.1258643746.2239.help-gnu-emacs@gnu.org>
2009-11-19 17:40         ` Colin S. Miller
2009-11-19 18:57           ` Jeff Clough

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='he53pa$66v$1@ger.gmane.org' \
    --to=kevin.d.rodgers@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.