From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 14833BBAF for ; Tue, 18 May 2010 16:59:05 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiQDAItI8kvRVdO7kGdsb2JhbACReYwACBUBAQEBCQkMBxEDH61fggCFWS6ITgEBAwWCaQiCGgQ X-IronPort-AV: E=Sophos;i="4.53,255,1272837600"; d="scan'208";a="63028855" Received: from mail-yw0-f187.google.com ([209.85.211.187]) by mail4-smtp-sop.national.inria.fr with ESMTP; 18 May 2010 16:58:40 +0200 Received: by ywh17 with SMTP id 17so814153ywh.3 for ; Tue, 18 May 2010 07:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=xNKZ0Dpj1xckIGE5u++ij2yVPEsn+Eg1AxRnmrJ4+AU=; b=L1RUJ4nB3YNfyj+i0uCf7yUhPTgBbfWFYv1Xq/EfEhsS12KpkqgIgxCVv6sh8ynHaO AUO8bQxOD41P6EVTa1N2LMEBi32GOjW4X6WJs6VpJ20FxfvKMrpZTQF0O1g3psq6JN+a hRkh8u2IiY0R6NO+c82gdlXz8wcxtoxOtQwN4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=uONU34VELCREstjudwDH1dZGA3TL45tSzj6VRP99+uWCgiEDy5bh22iJHdo0z/8KP+ cC702/w2OWcmKEAEvYW8dcH2TkbVMnl0mPS8+C2Q6+2Ba5Kr2abMOoD0LZvTZ47tRRDh 7ZJ2eTo0ieR2oD1PeBJW3oEVbwy5gkcSXOSc8= MIME-Version: 1.0 Received: by 10.229.241.205 with SMTP id lf13mr1488700qcb.100.1274194719651; Tue, 18 May 2010 07:58:39 -0700 (PDT) Received: by 10.229.87.81 with HTTP; Tue, 18 May 2010 07:58:39 -0700 (PDT) In-Reply-To: <87aarxitmv.fsf@frosties.localdomain> References: <87aarxitmv.fsf@frosties.localdomain> Date: Tue, 18 May 2010 10:58:39 -0400 Message-ID: Subject: Re: [Caml-list] What should the "size" in "caml_alloc_custom" be? From: lyn HONG To: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=0016363b90d2a3bab30486df9349 X-Spam: no; 0.00; alloc:01 allocating:01 ocaml:01 alloc:01 pointer:01 pointer:01 ocaml:01 malloc:01 function':01 malloc:01 function':01 mfg:98 mfg:98 wrote:01 wrote:01 --0016363b90d2a3bab30486df9349 Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 18, 2010 at 2:58 AM, Goswin von Brederlow wrote: > lyn HONG writes: > > > Hi all, > > > > I have a question about "allocating custom blocks" in "iterfacing C with > object > > Ocaml". when we call function "caml_alloc_custom(ops, size, used, max)" > in the > > C side, if the structure we want to allocate has a pointer, is the > "size" > > going to be size of the structure itself only, or should we also include > the > > memory block that pointer points to? > > > > Thanks, > > Lin > > The size is the number of ocaml words in the structure itself. The > pointer then points outside the ocaml heap to some C memory allocated by > malloc(). You should account for that size in the used/max pair. > > Thank you so much for the reply. So when we free the memory, what do we do with the block that pointer points to? Free it in the 'finalization function' associated to 'ops'? Best, Lin > MfG > Goswin > -- - lyn H --0016363b90d2a3bab30486df9349 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Tue, May 18, 2010 at 2:58 AM, Goswin = von Brederlow <go= swin-v-b@web.de> wrote:
lyn HONG <lynxiamen@gmail.com> writes:

> Hi all,
>
> I have a question about "allocating custom blocks" in "= iterfacing C with object
> Ocaml". when we call function "caml_alloc_custom(ops, size, = used, max)" in the
> C side, if the structure we want to allocate has a pointer, is the &qu= ot;size"=A0
> going to be size of the structure itself only, or should we also inclu= de the
> memory block that pointer points to?
>
> Thanks,
> Lin

The size is the number of ocaml words in the structure itself. = The
pointer then points outside the ocaml heap to some C memory allocated by malloc(). You should account for that size in the used/max pair.

Thank you so much for the reply.
So when we free = the memory, what do we do with the block that pointer points to? Free it in= the 'finalization function' associated to 'ops'?

Best,
Lin
=A0
MfG
=A0 =A0 =A0 =A0Goswin



--
- lyn H
--0016363b90d2a3bab30486df9349--