emacs-devel
[Top][All Lists]
Advanced

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

Re: Q: BLV for function slots + BL obarray/hmap for symbol lookup?


From: Stefan Monnier
Subject: Re: Q: BLV for function slots + BL obarray/hmap for symbol lookup?
Date: Sat, 29 May 2021 09:56:27 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Just as curiosa to confirm, yes that worked, rather well :-). That was 
> actually
> what I asked for if you think, I just didn't thought of copying over the
> obarray.
>
> (setq-local obarray (copy-sequence obarray))
> (defvar mysymbol "A SYMBOL")
> (defun myfunc () "HELLO")
>
> nysymbol and myfunc were avialable only in that buffer.
>
> Don't know how efficient it is to copy entire obarray, in possibly
> serveral buffers, but for the intended purpose, as a buffer-local
> namespace works well. Thanks.

In terms of efficiency: the global obarray holds about 50k-100k symbols,
every symbols occupies 6 words (i.e. 48 bytes on a 64bit system), so the
copy should allocate about 3-5MB of memory.

That's not very large if you only expect to make a couple of such
obarrays in any Emacs session.  In any case, you may encounter more
serious difficulties along the way, such as the fact that reading `nil`
will not return the same symbol as when you read `()`.

It *can* be a solution for a situation like a DSL, but in any case it
needs to be used with a lot of care (e.g. you don't want to end up
`require`ing (or more generally `load`ing) a normal ELisp package in
a context where `obarray` refers to such a copy).


        Stefan




reply via email to

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