[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: memory costs of storing lambdas?
From: |
Mikael Djurfeldt |
Subject: |
Re: memory costs of storing lambdas? |
Date: |
Thu, 01 May 2003 11:36:02 +0200 |
User-agent: |
Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3 (gnu/linux) |
Han-Wen Nienhuys <address@hidden> writes:
> 1. using anon functions:
>
> (define (style-setter style)
> (lambda (head) (set-note-head-style head style)))
> ...
>
> \property Voice.NoteHead \set #'style-procedure
> = #(style-setter "cross")
>
> During the lilypond run, the anonymous function is called. Storage
> cost: one anonymous function
According to eval.c:scm_closure and procs.h:
closure = < closcar, env >
closcar = < code, properties >
code = < formals, body >
So, the extra cost (not counting the cost of the list of expressions
in `body') is 3 pairs + pairs in formals list.
In your case, you also surround the closure with an environment
captured by the closure. This environment has the structure
(explained in the Guile docs):
new-env = < frame, env >
frame = < formals, values >
formals = < 'style, '() >
values = < style-value, '() >
So, you have 4 pairs for the environment, 3 pairs for closure
overhead, 1 pair for formals list, 1 pair for list of expressions in
body, and, 3 pairs for the expression. So, in total, the object
returned by `style-setter' above will consume 12 pairs.
> During the lilypond-run, a note-head pointer is prepended to the
> argument list, and the list (set-note-head-style head style) is
> evaluated.
>
> Storage cost: a list of length 2.
If you have only two items to store, the most efficient data structure
available is one pair.
For more items, the most efficient structure is a GOOPS object or a
vector. The cost of ordinary (not applicable) GOOPS objects is one
pair + mallocated memory of size sizeof(ptr) * n where n is number of
items.
Best regards,
Mikael
- Re: memory costs of storing lambdas?,
Mikael Djurfeldt <=