From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.user Subject: Re: memory costs of storing lambdas? Date: Thu, 01 May 2003 11:36:02 +0200 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: References: <16047.44607.580379.626517@localhost.localdomain> Reply-To: djurfeldt@nada.kth.se NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1051781891 23329 80.91.224.249 (1 May 2003 09:38:11 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 1 May 2003 09:38:11 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu May 01 11:38:09 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19BAW1-000645-00 for ; Thu, 01 May 2003 11:38:09 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19BAVo-0003cW-00 for guile-user@m.gmane.org; Thu, 01 May 2003 05:37:56 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19BAV3-00037h-00 for guile-user@gnu.org; Thu, 01 May 2003 05:37:09 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19BAUm-0002ck-00 for guile-user@gnu.org; Thu, 01 May 2003 05:36:53 -0400 Original-Received: from kvast.blakulla.net ([213.212.20.77]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19BAU2-0001mO-00 for guile-user@gnu.org; Thu, 01 May 2003 05:36:06 -0400 Original-Received: from barbara.blakulla.net ([213.212.21.238] helo=linnaeus) by kvast.blakulla.net with esmtp (Exim 3.36 #1 (Debian)) id 19BATz-0005Zm-00; Thu, 01 May 2003 11:36:03 +0200 Original-Received: from mdj by linnaeus with local (Exim 3.36 #1 (Debian)) id 19BATy-0001rg-00; Thu, 01 May 2003 11:36:02 +0200 Original-To: hanwen@cs.uu.nl In-Reply-To: <16047.44607.580379.626517@localhost.localdomain> (Han-Wen Nienhuys's message of "Wed, 30 Apr 2003 13:06:39 +0200") User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3 (gnu/linux) Original-cc: djurfeldt@nada.kth.se X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General Guile related discussions List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:1888 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:1888 Han-Wen Nienhuys 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