From: Luke
Subject: Memory Allocation
Date: 
Message-ID: <be1rhf$gv7$1@online.de>
Hello,

is there a way to allocate memory of a specific size in Lisp?

Especially I'd like to allocate memory of the size of a list i already have.

i.e. :
'(1 2 (2 3 (33 4 5) 3 4))
I want the size of that tree to be reserved in memory, but without the data
(to be faster that copy-tree).

greetings

Luke

From: Barry Margolin
Subject: Re: Memory Allocation
Date: 
Message-ID: <7x_Ma.30$Qd3.163@paloalto-snr1.gtei.net>
In article <············@online.de>, Luke <···················@gmx.de> wrote:
>Hello,
>
>is there a way to allocate memory of a specific size in Lisp?

No, Lisp allocates and releases memory as it's needed.

>Especially I'd like to allocate memory of the size of a list i already have.
>
>i.e. :
>'(1 2 (2 3 (33 4 5) 3 4))
>I want the size of that tree to be reserved in memory, but without the data
>(to be faster that copy-tree).

You can call make-list to allocate the top-level list:

(setq list-copy (make-list (length original-list)))

However, memory allocation is not so expensive that you typically need to
worry about it.  All it usually does is increment a pointer.

-- 
Barry Margolin, ··············@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Henrik Motakef
Subject: Re: Memory Allocation
Date: 
Message-ID: <pan.2003.07.03.18.54.27.437405@henrik-motakef.de>
On Thu, 03 Jul 2003 21:09:50 +0200, Luke wrote:

> is there a way to allocate memory of a specific size in Lisp?
> 
> Especially I'd like to allocate memory of the size of a list i already
> have.

Well, yes, sort of. You could use MAKE-LIST, or MAKE-ARRAY or whatever
fits your needs. But there is no malloc, you cannot just get a range of
untyped memory and then put typed objects there.
 
> i.e. :
> '(1 2 (2 3 (33 4 5) 3 4))
> I want the size of that tree to be reserved in memory, but without the
> data (to be faster that copy-tree).

Frankly, it sounds as if you were about to do something you better should
not. Can you describe the higher-level goal, so we can try to find the
best solution? Do you think that multiple calls to CONS are a performance
bottleneck in COPY-TREE?