From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D428BBC6B for ; Wed, 15 Aug 2007 01:24:53 +0200 (CEST) Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.191]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7ENOqvs011326 for ; Wed, 15 Aug 2007 01:24:53 +0200 Received: by rv-out-0910.google.com with SMTP id f5so16213rvb for ; Tue, 14 Aug 2007 16:24:51 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=gJvYzdwfnWL5uDlanV71wicE/t3FzW8Sts/OONO+GRukSmI2LZj5WCEF8q7d0L4CLL9Uqz1wOT/9KHj8yyol+KYgKIhN7q+EEWOq2a119x7fq+1tw/FRyDzIz8aB6Stw9Cu2aSQ+W9ZdW7vw9MzktoM2gsPB3rIlhkC2rldkgj0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=bqH+BosSWmvwQ7XzMtxGfoPVprOhCr6Vu/g1LnQlvX200S5EUTNCwyMsV5GlAq1I+G6vd8+OX1eL6DSmiNoIrTcVAXm6hkZ2SqIwBOelVIYo41s24oYzOYwc+7fvei8DtNFRf2qLtP0SBvBSd7mZ10pM3/vS5+6x9yqV07/YVfs= Received: by 10.142.111.14 with SMTP id j14mr777901wfc.1187133891558; Tue, 14 Aug 2007 16:24:51 -0700 (PDT) Received: by 10.143.168.5 with HTTP; Tue, 14 Aug 2007 16:24:51 -0700 (PDT) Message-ID: <9d3ec8300708141624j676f8384ya93db222c2ed2b7b@mail.gmail.com> Date: Wed, 15 Aug 2007 01:24:51 +0200 From: "Till Varoquaux" To: "Richard Jones" Subject: Re: [Caml-list] Weak hash table for attaching extra data to an object Cc: caml-list@inria.fr In-Reply-To: <20070814162206.GA1651@furbychan.cocan.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070814101535.GA14485@furbychan.cocan.org> <20070814162206.GA1651@furbychan.cocan.org> X-j-chkmail-Score: MSGID : 46C239C4.001 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 46C239C4.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; hash:01 hash:01 stdlib:01 overwritten:01 bindings:01 beginner's:01 ocaml:01 bug:01 garbage:01 beginners:01 wrote:01 caml-list:01 caml-list:01 remi:01 bin:01 On 8/14/07, Richard Jones wrote: > Attached is my attempt to make a WeakMetadata module (a weak hash > table where only the key is weak and the value is used to store > metadata about the key). It is derived from Remi Vanicat's Hweak > module, which is itself derived from the weak set in stdlib. > > Unfortunately it relies on the following being safe. I have no idea > if this is safe or not. > > Array.create 0 (Obj.magic ()) You seem to be asking for trouble here. From what I read in your code this *should* work. It is however highly dependent on the garbage collector implementation: the first bit contains tells it whether this is a block or not. I would recommend using options instead (and again you might just use my library but that shameless self promotion). Using options will have a performance impact. You can can see your solution as a clever (yet brittle) optimization hack. However if you are hellbent on performances you might also consider having direct access to your keys (fore quality) and collisions stored in another table. Regards, Till > Also it doesn't clean up the extra data (metadata) very aggressively. > It basically waits for it to get overwritten when further bindings are > added to a bucket. So if the metadata is very large it would be worth > adding some sort of "compact" method. > > Rich. > > -- > Richard Jones > Red Hat > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > > -- http://till-varoquaux.blogspot.com/