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: Jonathan Roewen <jonathan.roewen@g...>
Subject: [Caml-list] help with caml_stat_alloc
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);
}

Also, my interface in ocaml is:

external alloc : int32 -> int32 = "icfp_alloc"
external free : int32 -> unit = "icfp_free"
external get : int32 -> int32 -> int32 = "icfp_get"
external set : int32 -> int32 -> int32 -> unit = "icfp_set"
external copy : int32 -> int32 = "icfp_copy"

Some guidance would be much appreciated,

Jonathan