caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dmitry Bely <dbely@mail.ru>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Documentation request: allocation of bigarrays in C
Date: Sun, 02 Apr 2006 17:56:19 +0400	[thread overview]
Message-ID: <zmj484jg.fsf@mail.ru> (raw)
In-Reply-To: <442E5314.9080804@crans.org> (Li-Thiao-T's message of "Sat, 01 Apr 2006 12:16:52 +0200")

Li-Thiao-Té Sébastien <sayan@crans.org> writes:

>>>If you want to be GC-friendly, use the bigarray
>>>allocation macros with a NULL pointer to allocate memory then get a
>>>pointer to the data array.
>> If you need GC-controlled bigarray, why simply not to use
>> Bigarray.Genarray.create?
>>
> Why is there a C bigarray allocation function at all then ? :)

alloc_bigarray_xxx()? Their primary purpose is to allocate a proxy
structure for an external C-allocated data (that cannot be finalized).
data==NULL behaviour IMHO is not for the final user but only for
Bigarray.Genarray.create internal use.

> In my case, I want to read a relatively big file (50MB) containing
> arrays of floats . I use C functions for the raw speed then pass the
> bigarrays to OCaml to do some reordering of the data, and higher-level
> processing.

You should use Bigarray.Genarray.create then pass the created bigarray to C
side using Data_bigarray_val(). Note that the bigarray is allocated with
malloc() outside the Ocaml heap.

> I do not open the file in Ocaml then send a string to C for parsing,
> but rather open the file in C and return the bigarray list to
> Ocaml. (cf my previous mistake on creating Ocaml lists in C on this
> mailing-list)
>
> I have hundreds of such files that I may want to load and compare
> interactively, so reclaiming unused memory is a big bonus.

Sure - Ocaml-allocated bigarrays will be finalized as usual.

- Dmitry Bely


  parent reply	other threads:[~2006-04-02 14:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-31 14:02 sayan
2006-03-31 17:57 ` [Caml-list] " Dmitry Bely
2006-04-01 10:16   ` Li-Thiao-Té Sébastien
2006-04-01 10:30     ` Jonathan Roewen
2006-04-01 14:42       ` Li-Thiao-Té Sébastien
2006-04-02 13:56     ` Dmitry Bely [this message]
2006-04-02 20:54       ` Li-Thiao-Té Sébastien
2006-04-03  9:24         ` Dmitry Bely
2006-04-03 23:45         ` Nathaniel Gray

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=zmj484jg.fsf@mail.ru \
    --to=dbely@mail.ru \
    --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).