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.5 required=5.0 tests=AWL,NO_REAL_NAME,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id B712ABC6B for ; Wed, 23 Jan 2008 18:18:18 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAFsFl0fAXQInh2dsb2JhbACPKHYBAQEICimdYQ X-IronPort-AV: E=Sophos;i="4.25,239,1199660400"; d="scan'208";a="8259496" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 23 Jan 2008 18:18:18 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m0NHIFoV001383 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 23 Jan 2008 18:18:18 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAA4Gl0fPLfoknmdsb2JhbACPKHYBAQEBAQYEBgcKGJ1i X-IronPort-AV: E=Sophos;i="4.25,239,1199660400"; d="scan'208";a="7134829" Received: from parmail03.sgcib.com ([207.45.250.36]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Jan 2008 18:18:15 +0100 X-IronPort-AV: i="4.25,239,1199660400"; d="scan'208"; a="195222509:sNHT40129268" Content-class: urn:content-classes:message MIME-Version: 1.0 X-MimeOLE: Produced By Microsoft Exchange V6.5 Subject: RE: [Caml-list] Freeing allocated C-memory by GC (destructors) Date: Wed, 23 Jan 2008 18:18:12 +0100 Message-ID: <0172C3AE3A0E964797AF43E206C1048F0ED606@FRCOR-EXMB06.europe.am.socgen> In-Reply-To: <1201106774.47976f56aa4e0@webmail.in-berlin.de> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [Caml-list] Freeing allocated C-memory by GC (destructors) Thread-Index: Achd34ha7/V9QF2zQy+fvU0ahl9SFwABEH7w From: To: , X-OriginalArrivalTime: 23 Jan 2008 17:18:13.0729 (UTC) FILETIME=[EF81F510:01C85DE3] X-NAI-Spam-Score: -2.5 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Miltered: at concorde with ID 479776D7.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; finalizer:01 ocaml:01 val:01 camlexport:01 struct:01 mlfi:01 hash:01 serialize:01 deserialize:01 camlprim:01 camlparam:01 val:01 alloc:01 sizeof:01 camlreturn:01 Use custom_blocks, passing the corresponding functions (mainly the finalize= r) Here is an example of random generator defined in c and wrapped in ocaml #define Gen(v) (*((int **) Data_custom_val(v))) static void finalize_Gen(value v) { int * stream =3D Gen(v); free_Gen(stream); } CAMLexport struct custom_operations Gen_ops =3D { "mlfi_Gen_state", //custom_finalize_default, &finalize_Gen, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default }; CAMLprim value Gen_make(value init_seed, value rng_type, value rng_paramete= r, ...) { CAMLparam5(init_seed,rng_type,rng_parameter,...); CAMLlocal1(t); int *stream; unsigned long int seed;=20 int rngtype; int rngparameter; seed =3D Unsigned_long_val(init_seed); rngtype =3D getRngType(rng_type); rngparameter =3D getRngParameter(rng_parameter); /* we create here the custom block, with the correct free operator */ =20 t =3D alloc_custom(&Gen_ops, sizeof(int *), 0, 1); stream =3D init_Gen(rngtype,...,seed,rngparameter); Gen(t) =3D stream; CAMLreturn(t); } -----Message d'origine----- De=A0: caml-list-bounces@yquem.inria.fr [mailto:caml-list-bounces@yquem.inr= ia.fr] De la part de Oliver Bandel Envoy=E9=A0: mercredi 23 janvier 2008 17:46 =C0=A0: caml-list@inria.fr Objet=A0: [Caml-list] Freeing allocated C-memory by GC (destructors) Hello, after using some non-permanent allocating C-stuff together with OCaml, I think about going one step further and now have allocated memory from C represented as OCaml-variables (in the concrete example I have married some of my C-stuff that uses jpeglib to get information from picture-files, and now think about representing complete picture-data as OCaml-variables). So, I want to have the possibility to have malloced/calloced data avaliable in OCaml, and that the GC calls C-destructor- functions (using free(3)) when the values are of no use anymore. How to say the GC, which is the destructor-functions for a variable, which has been created? TIA, Oliver _______________________________________________ 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 Ce message et toutes les pieces jointes (ci-apres le "message") sont confid= entiels et etablis a l'intention exclusive de ses destinataires.=20 Toute utilisation ou diffusion non autorisee est interdite.=20 Tout message electronique est susceptible d'alteration.=20 Societe Generale Asset Management et ses filiales declinent toute responsab= ilite au titre de ce message s'il a ete altere, deforme ou falsifie.=20 =20 Decouvrez l'offre et les services de Societe Generale Asset Management sur = le site www.sgam.fr=20 =20 ********=20 =20 This message and any attachments (the "message") are confidential and inten= ded solely for the addressees.=20 Any unauthorised use or dissemination is prohibited.=20 E-mails are susceptible to alteration.=20 Neither Societe Generale Asset Management nor any of its subsidiaries or af= filiates shall be liable for the message if altered, changed or falsified.=20 =20 Find out more about Societe Generale Asset Management's proposal on www.sga= m=2Ecom