Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] help with caml_stat_alloc
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Anatoly Zaretsky <anatoly.zaretsky@g...>
Subject: Re: [Caml-list] help with caml_stat_alloc
On 7/24/06, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
> Hi,
>
> I'm trying to allocate some memory outside of the caml heap, and I
> think caml_stat_alloc is the right function to use. Anyways, it's
> generating seg-faults, so I'm hoping someone can help me fix my
> implementation.
>
> CAMLprim value icfp_alloc(value size) {
>         int sz = Int32_val(size) + 1;
>         int *p = (int *)caml_stat_alloc(sz);
>         p[--sz] = sz;
>         /*while ( sz > 0 ) {
>                 p[--sz] = 0;
>         }*/
>         return caml_copy_int32(p);
> }

>From byterun/memory.h:
CAMLextern void * caml_stat_alloc (asize_t);              /* Size in bytes. */

So p[--sz] is out of allocated region.

--
Tolik