caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] c-interface question...
@ 2003-09-18  8:31 Michael Wohlwend
  2003-09-18 12:08 ` David Baelde
  2003-09-18 18:12 ` David Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Wohlwend @ 2003-09-18  8:31 UTC (permalink / raw)
  To: caml-list

Hi,

to play with the c-interface I tried to change the digest module to allow 
calculating a md5 sum piece by piece (i.e. making the function init, 
updtae and finalize avalable).
one question about the parameters of

external md5_new : unit -> md5_context = "md5_new"

should it be:

CAMLprim value md5_new()
{
CAMLparam0();
...
CAMLreturn(...);
}

or
CAMLprim value md5_new(value unit)
{
CAMLparam1(unit);
...
CAMLreturn(...);
}


as it receives a unit-paramter?
(the same for returning unit: CAMLreturn0 or CAMLreturn(Val_unit) ? )

thanks for answering,
  Michael




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] c-interface question...
  2003-09-18  8:31 [Caml-list] c-interface question Michael Wohlwend
@ 2003-09-18 12:08 ` David Baelde
  2003-09-18 18:12 ` David Brown
  1 sibling, 0 replies; 4+ messages in thread
From: David Baelde @ 2003-09-18 12:08 UTC (permalink / raw)
  To: Michael Wohlwend, caml-list

[-- Attachment #1: Type: text/plain, Size: 409 bytes --]


 I'm not an expert, but I can quote the tutorial.
 Here is their code for a unit -> window bound function.

value curses_initscr(value unit)
{
  CAMLparam1 (unit);
  CAMLreturn ((value) initscr()); 
}

 That's why I use CAMLprim f (value unit) { CAMLreturn(Val_unit) }

--
        David Baelde
	Etudiant en Info à l'ENS Lyon
        _______
   .^.   O
   /V\ .°
  // \\
 /(   )\
  ^^-^^

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] c-interface question...
  2003-09-18  8:31 [Caml-list] c-interface question Michael Wohlwend
  2003-09-18 12:08 ` David Baelde
@ 2003-09-18 18:12 ` David Brown
  2003-09-19 14:44   ` Richard Jones
  1 sibling, 1 reply; 4+ messages in thread
From: David Brown @ 2003-09-18 18:12 UTC (permalink / raw)
  To: Michael Wohlwend; +Cc: caml-list

On Thu, Sep 18, 2003 at 10:31:20AM +0200, Michael Wohlwend wrote:

> external md5_new : unit -> md5_context = "md5_new"
> 
> should it be:
> 
> CAMLparam1(unit);

> as it receives a unit-paramter?

It won't hurt anything to do this, other than performance.  The only
arguments that need to be declared in a CAMLparamx declaration are those
that can be moved or collected by the garbage collector.  Specifically,
integer values do not need to be declared.

There is also no need to CAMLparam an argument that you do not use, even
if it is a heap value.

An added "optimization" is that if an argument is only used before the
first allocation you call, it also doesn't need to be declared.

It helps to think about what is happening here.  Things that allocate
memory may trigger a garbage collection.  If you have arguments or
variables that might be affected by the garbage collector, you need to
tell the gc about them.  That is what CAMLparamx and CAMLlocal do.

A function that only allocates one thing, and doesn't reference its
variables after the allocation doesn't need to use any of these macros.

Dave Brown

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] c-interface question...
  2003-09-18 18:12 ` David Brown
@ 2003-09-19 14:44   ` Richard Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Jones @ 2003-09-19 14:44 UTC (permalink / raw)
  Cc: caml-list

On Thu, Sep 18, 2003 at 11:12:15AM -0700, David Brown wrote:
> An added "optimization" is that if an argument is only used before the
> first allocation you call, it also doesn't need to be declared.
> 
> It helps to think about what is happening here.  Things that allocate
> memory may trigger a garbage collection.  If you have arguments or
> variables that might be affected by the garbage collector, you need to
> tell the gc about them.  That is what CAMLparamx and CAMLlocal do.

Interesting ... so the garbage collector can never run asynchronously?
That should simplify my code ...

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
MONOLITH is an advanced framework for writing web applications in C, easier
than using Perl & Java, much faster and smaller, reusable widget-based arch,
database-backed, discussion, chat, calendaring:
http://www.annexia.org/freeware/monolith/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-09-19 14:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-18  8:31 [Caml-list] c-interface question Michael Wohlwend
2003-09-18 12:08 ` David Baelde
2003-09-18 18:12 ` David Brown
2003-09-19 14:44   ` Richard Jones

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).