all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Passing buffers to function in elisp
@ 2023-02-21 21:18 Petteri Hintsanen
  2023-02-21 23:21 ` [External] : " Drew Adams
  2023-02-22  5:30 ` tomas
  0 siblings, 2 replies; 22+ messages in thread
From: Petteri Hintsanen @ 2023-02-21 21:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hello list,


Alan J. Perlis said "A LISP programmer knows the value of everything,
but the cost of nothing."


I'm reading some bytes into a temp buffer, like so:

  (with-temp-buffer
    (set-buffer-multibyte nil)
    (insert-file-contents-literally filename nil 0 64000))

then I pass these bytes to functions for processing, like this

    (func1 (buffer-string))

or sometimes just part of them

    (func2 (substring (buffer-string) 100 200))

Now:

. does this generate garbage?  (I believe it does.)
. if there are many funcalls like that, will there be lots of garbage?
  (I guess there will be.)
. is this bad style?  (I'm afraid it is, hence asking.)

Is it better just to assume in functions that the current buffer is the
data buffer and work on that, instead of passing data as function
arguments?

[Why am I doing like this?  It is /slightly/ easier to write tests when
functions get their data in their arguments.]


Also: is it good idea to try to limit the number temp buffers
(with-temp-buffer expressions)?  Or are they somehow recycled within the
elisp interpreter?


Thanks,
Petteri




^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-09-06 21:12 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-21 21:18 Passing buffers to function in elisp Petteri Hintsanen
2023-02-21 23:21 ` [External] : " Drew Adams
2023-02-22  5:35   ` tomas
2023-02-24 20:08     ` Petteri Hintsanen
2023-02-25  6:40       ` tomas
2023-02-25 11:23       ` Michael Heerdegen
2023-02-25 13:45         ` tomas
2023-02-25 18:31           ` Michael Heerdegen
2023-02-25 19:05             ` tomas
2023-02-25 23:52         ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-02-27 20:44           ` Petteri Hintsanen
2023-02-28  5:37             ` tomas
2023-03-03 15:19             ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-07 21:48               ` Petteri Hintsanen
2023-03-07 22:45                 ` Stefan Monnier
2023-03-08  5:38                   ` tomas
2023-09-06 19:05               ` Petteri Hintsanen
2023-09-06 21:12                 ` Stefan Monnier
2023-02-22  5:30 ` tomas
2023-02-23  9:34   ` Michael Heerdegen
2023-02-23  9:51     ` tomas
2023-02-23 16:19     ` Marcin Borkowski

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.