help-gnu-emacs
[Top][All Lists]
Advanced

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

translate-region function on large files causes emacs to explode


From: Bijan Soleymani
Subject: translate-region function on large files causes emacs to explode
Date: Wed, 02 Oct 2002 14:36:27 GMT
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2a) Gecko/20020910

When I use the translate-region function to rot13 a large file
(600k) emacs expands to using 30 megs of memory. Killing the buffer
does not free the memory.

When I rot13 the bible (5 megs), emacs balloons to over 200 megs
and depending on the memory available on the machine, will pretty
much die. Again if this is successful killing all buffers will not
free any memory.

I have tried this on emacs 21.2 on Debian GNU/Linux (woody/stable),
20.7.1 on redhatt 6.1 (cartman), 21.2 on windows 2000 and 20.4.1
on solaris 2.7. The same thing happened on all of them.

I believe this might be a bug in the translate-region function
but I am not quite sure. I have looked into it, but it is a built-in
function written in C, and it looked a bit cryptic to me. The function
is in the file /src/editfns.c

I use the translate-region function to rot13 the current buffer as follows:

;First I have to make a translation table. This is a string of
;ordered characters where the position of the character in the
;string represents their ascii code:
;the first character will replace the character with ascii code
;1, the 65th character in the string will be the replacement for
;A (the character with ascii code 65) and so on...

;make a string that goes up to position 122 since lowercase z
;is character code 122

(setq rot13-table (make-string 123 ?a))



;set codes from 0 to 64 equal to themselves since i don't want
;to change them
(setq start 0)
(while (< start 65)
(aset rot13-table start start)
(setq start (+ start 1)))

;flip from A to M
(while (< start 78)
(aset rot13-table start (+ start 13))
(setq start (+ start 1)))

;flip from N to Z
(while (< start 91)
(aset rot13-table start (- start 13))
(setq start (+ start 1)))

;keep 91 to 96 the same
(while (< start 97)
(aset rot13-table start start)
(setq start (+ start 1)))

;flip from a to m
(while (< start 110)
(aset rot13-table start (+ start 13))
(setq start (+ start 1)))

;flip from m to z
(while (< start 123)
(aset rot13-table start (- start 13))
(setq start (+ start 1)))

;define function to rot13 region
(defun rot13-region (begin end)
"rot13 contents of current region"
(interactive "r")
(translate-region begin end rot13-table))

;define function to rot13 buffer
(defun rot13-buffer ()
"rot13 contents of current buffer"
(interactive)
(translate-region (point-min) (point-max) rot13-table)))



reply via email to

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