caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Samuel Hornus <Samuel.Hornus@inria.fr>
To: O Caml <caml-list@inria.fr>
Subject: Re: [Caml-list] Segfault in C++ stub with many 'new' allocations
Date: Sat, 17 Nov 2012 19:42:58 +0100	[thread overview]
Message-ID: <0BEF3A04-3297-4084-BE4D-13ACCC4D431E@inria.fr> (raw)
In-Reply-To: <CAGmVoG2e6jG3s1-f==UsPq9MKxziS+N8PK2DfqwC8c4zawM9pQ@mail.gmail.com>


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…

Regarding my first question, if it can help, here is the relevant part of my C++ code:
---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
ANNbd_tree * create_bd_tree_flat(ANNcoord * arr, int n, int dim)
{
	// ANNcoord = double
	// ANNpoint = double*
	// ANNpointArray = double**

    ANNbd_tree * ptr;
    std::cerr << "\nCreating flat Bd_tree with " << n << " points of dim " << dim;

    ANNpointArray ptarr = new ANNpoint[n];
    for( int i = 0; i < n; ++i )
    {
        ptarr[i] = arr + dim * i;
    }
    std::cerr << " CHK ";
    ptr = 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 = 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 first function, in the constructor ANNbd_tree() ("CHK" is printed on the terminal, "done" is not)
-- 
Sam

  reply	other threads:[~2012-11-17 18:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-17 18:29 Samuel Hornus
2012-11-17 18:35 ` Kakadu
2012-11-17 18:42   ` Samuel Hornus [this message]
2012-11-17 19:10     ` Török Edwin
2012-11-17 19:18       ` Samuel Hornus
2012-11-17 19:50       ` Markus Mottl
2012-11-17 19:46 ` Markus Mottl
2012-11-17 22:45   ` Samuel Hornus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0BEF3A04-3297-4084-BE4D-13ACCC4D431E@inria.fr \
    --to=samuel.hornus@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).