unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mikael Djurfeldt <djurfeldt@nada.kth.se>
Cc: guile-user@gnu.org
Subject: Re: memory costs of storing lambdas?
Date: Thu, 01 May 2003 11:36:02 +0200	[thread overview]
Message-ID: <xy7u1cf57r1.fsf@nada.kth.se> (raw)
In-Reply-To: <16047.44607.580379.626517@localhost.localdomain> (Han-Wen Nienhuys's message of "Wed, 30 Apr 2003 13:06:39 +0200")

Han-Wen Nienhuys <hanwen@cs.uu.nl> 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


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2003-05-01  9:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-30 11:06 memory costs of storing lambdas? Han-Wen Nienhuys
2003-05-01  9:36 ` Mikael Djurfeldt [this message]
2003-05-01 11:38   ` memory costs of storing lambdas? (correction) Mikael Djurfeldt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xy7u1cf57r1.fsf@nada.kth.se \
    --to=djurfeldt@nada.kth.se \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).