From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 1344E7EE20 for ; Sat, 17 Nov 2012 19:43:00 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.83,270,1352070000"; d="scan'208";a="162848859" Received: from 4be54-7-78-230-69-17.fbx.proxad.net (HELO [192.168.0.23]) ([78.230.69.17]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA; 17 Nov 2012 19:42:59 +0100 Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Apple Message framework v1283) From: Samuel Hornus In-Reply-To: Date: Sat, 17 Nov 2012 19:42:58 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <0BEF3A04-3297-4084-BE4D-13ACCC4D431E@inria.fr> References: <70435661-3754-4815-9EEF-B52F33D29B5F@inria.fr> To: O Caml X-Mailer: Apple Mail (2.1283) Subject: Re: [Caml-list] Segfault in C++ stub with many 'new' allocations On 17 nov. 2012, at 19:35, Kakadu wrote: > 2) AFAIR there are functions like register_global_root which prevents GC = from moving values. Thank you Kakadu. It is interesting to know that one can use this function = directly. I knew its existence only through the CAML[x]param* macros=85 Regarding my first question, if it can help, here is the relevant part of m= y C++ code: ---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- ANNbd_tree * create_bd_tree_flat(ANNcoord * arr, int n, int dim) { // ANNcoord =3D double // ANNpoint =3D double* // ANNpointArray =3D double** ANNbd_tree * ptr; std::cerr << "\nCreating flat Bd_tree with " << n << " points of dim " = << dim; ANNpointArray ptarr =3D new ANNpoint[n]; for( int i =3D 0; i < n; ++i ) { ptarr[i] =3D arr + dim * i; } std::cerr << " CHK "; ptr =3D new ANNbd_tree(ptarr,n,dim); // Crashes here when 'n' is big std::cerr << "done"; return ptr; } extern "C" value ann_create_bd_tree_flat_ba (value ba, value n, value dim) { CAMLparam3(ba,n,dim); ANNbd_tree * ptr =3D create_bd_tree_flat((ANNcoord*)Caml_ba_data_val(ba= ), Int_val(n), Int_val(dim)); CAMLreturn ((value)ptr); } ---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- The second function is called from OCaml, and the crash happens in the firs= t function, in the constructor ANNbd_tree() ("CHK" is printed on the termin= al, "done" is not) --=20 Sam=