Loading ...
Sorry, an error occurred while loading the content.

12886Re: "ocaml_beginners"::[] Monitor memory usgae from executing ocaml code

Expand Messages
  • r.schmitt@ocaml.de
    Aug 2, 2011
    • 0 Attachment
      On Tue, 2 Aug 2011 09:09:19 +0200
      rixed@... wrote:
      > IIRC from the runtime code, the main idea is to have all major heap
      > values grouped together so that it's faster to tell if a value is in
      > the major heap (thus must be traversed by the GC) by looking at its
      > address (while a mere malloc would scatter objects here and there).

      I don't think, this is the reason, why so much additional space is requested.
      The memory manager always over-requests new memory according to
      Gc.control.space_overhead.

      You can temporarily set it down, if you only allocate a big array once
      and you know, that you don’t need that much memory after that:
      ---
      let cur = Gc.get() in
      let ns = { cur with Gc.space_overhead = 3 } in
      Gc.set ns ;
      Array.make big_i 0. ;
      Gc.set cur ;
      ---

      This way, only the needed memory is allocated (with a comparable small
      overhead).

      The manual (http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html)
      don't say much about space_overhead, but I would read it in the way
      I‘ve outlined above (I've took a very quick look at the source code and
      can't find anything that contradicts this interpretation. But perhaps
      somebody who is familiar with the runtime/source code could clarify
      this point. )


      > Which is also how malloc works.

      Yes and no. The additional requested space (in percentage) is
      negligible, if you allocate large amounts of memory with malloc/C (at
      least, if you don’t tweak it). It’s only relevant for very small
      requests.
    • Show all 11 messages in this topic