Re: [Caml-list] Shared libraries with ocamlopt callable from C (without main())?

2009-01-11 Thread Xavier Leroy
 =  $ cat ./main.c =
 #include stdio.h
 #include libadd5wrapper.h
 int main (int argc,char **argv){
printf(Gimme - %d \n, add5wrapper());

Should be add5wrapper(argv) -- as gcc's warnings told you.

return 0;
 }
 
 Now I try to BUILD the whole thing:
 [...]
 Number 4 is where it breaks. I get a ton of errors and this is where
 it ends for me. Because # 4 is also the point where I definitely have
 no idea what I'm doing.

Two things:

- You're not linking in add5-prog.o as far as I can see

- In static mode, the Unix linker is very picky about the relative
  order of -lxxx arguments on the command-line.  For more information,
  see the Info pages for GNU ld.  You probably don't need -static anyway.

The following works:

ocamlopt -output-obj add5.ml -o add5-prog.o
gcc -I`ocamlc -where` -c add5wrapperlib.c
gcc -c main.c
gcc -o mainprog.opt main.o add5wrapperlib.o add5-prog.o \
   -L`ocamlc -where` -lasmrun -ldl -lm

Add -static to the last line if you know you really need it.

Hope this puts you back on tracks.

- Xavier Leroy

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Why does value restriction not apply to the empty list ?

2009-01-11 Thread Xavier Leroy
Antoine Delignat-Lavaud wrote:

 I chose to solve the problem of polymorphic references by adding value
 restriction* to my inferer, using ocaml to check my results.
 Not knowing whether the empty list should be considered a value or an
 expression, I copied Ocaml's behavior and made it a value.

Yes, the empty list is a value, like all other constants.

 As a result, my inferer gave the following expression the integer type :
 let el = [] in if hd el then 1 else hd el ;;
 which is the expected result since el has polymorphic type 'a list
 but does not look right because it is used as both a bool list and an
 int list.

It is perfectly right.  The empty list can of course be used both as a
bool list and an int list; that's exactly what parametric polymorphism
is all about.

Richard Jones wrote:

 But the same if statement within a function definition causes an error:

 # let f el =
   if List.length el  0 then (List.hd el)+(int_of_string (List.hd el)) else 
 0;;
   ^^
 This expression has type int but is here used with type string

This is Hindley-Milner polymorphism at work: only let-bound
variables can have polymorphic types, while function parameters are
monomorphic.

- Xavier Leroy

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] memory usage

2009-01-11 Thread John Lepikhin
Hello,

I have developed an application and have issue with memory usage.
Application was designed for work as server, 24x7. After several hours
of work, RSS memory grows up to 40-50MB. Each thread must not use more
than 100-200KB of memory (maximum 20 threads are run at the same time).
GC debug information:

Growing heap to 3840k bytes
Growing heap to 4320k bytes
Shrinking heap to 3840k bytes
Growing heap to 4320k bytes
Growing heap to 4800k bytes
Growing heap to 5280k bytes
Shrinking heap to 4800k bytes
Shrinking heap to 4320k bytes
Shrinking heap to 3840k bytes
Growing heap to 4320k bytes
Growing heap to 4800k bytes
Growing heap to 5280k bytes
Shrinking heap to 4800k bytes
Shrinking heap to 4320k bytes
Shrinking heap to 3840k bytes
Shrinking heap to 3360k bytes
Growing heap to 3840k bytes
Growing heap to 4320k bytes
Growing heap to 4800k bytes
Growing heap to 960k bytes
Shrinking heap to 4320k bytes
Shrinking heap to 3840k bytes
Shrinking heap to 3360k bytes
Shrinking heap to 2880k bytes
Growing heap to 3360k bytes
Shrinking heap to 2880k bytes
Shrinking heap to 2400k bytes
Growing heap to 2880k bytes
Growing heap to 3360k bytes
Growing heap to 3840k bytes
Shrinking heap to 3360k bytes
Shrinking heap to 2880k bytes
Growing heap to 3360k bytes
Shrinking heap to 2880k bytes

As you can see, heap size never gets bigger 5-6MB. I made core dump of
process. 90% of memory was filled with values which are created inside
threads and never been copied outside of them. Each thread is killed
after work is done, I am absolutely sure in it; all unused file
descriptors are closed. Playing with Gc.set has not brought notable
results.

Please, give me some start point to find the roots of the problem.

Sorry for my English.

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs