caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: carette@mcmaster.ca
Cc: "'Richard Jones'" <rich@annexia.org>, caml-list <caml-list@inria.fr>
Subject: RE: [Caml-list] Out_of_memory exception in output_value
Date: 29 May 2004 05:44:42 +1000	[thread overview]
Message-ID: <1085773482.3036.81.camel@pelican.wigram> (raw)
In-Reply-To: <003701c444d3$7163a340$1b447182@cas.mcmaster.ca>

On Sat, 2004-05-29 at 02:47, Jacques Carette wrote:
> > It turns out that during output_value, the OCaml code allocates a
> > block of memory to contain the marshalled representation of the data.
> > Each time it runs out of room, it doubles the size of that block using
> > realloc().
> 
> Wouldn't it be more system-friendly to try successively factors *2, *1.5,
> *1.1, and *1.05 before actually failing? 

I have a published book chapter part of which deals with
this issue in some detail, including some performance
measurements.

The general solution is much cleaner -- to use
a user supplied allocation function something like:

new_size = f old_size requested_size

Doubling the size, or indeed even using a pure multiplier,
is only one possible option: simply adding a fixed amout
is another option, and an arbitrary function handles
both cases and many more. So a general solution is to make
the operation polymorphic by making the calculator function
an argument (in practice with a sensible default).

My experiments were with variable length arrays used
to hold big integers, so some operations produced
small increases (like addition) whereas other
produced increases much faster (like multiplication).

A quick and easy fix would be to use a global variable
containing the function which the client can reset.
Yeah, I hate global state but here the actual function
chosen has no semantic impact, it only affects performance
(unless you run out of memory .. of course). So this
time a global might be OK :)

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



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


  reply	other threads:[~2004-05-28 19:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-28  9:10 Richard Jones
2004-05-28 14:31 ` Richard Jones
2004-05-28 16:47   ` Jacques Carette
2004-05-28 19:44     ` skaller [this message]
2004-05-28 20:54       ` Eric Dahlman
2004-05-29  7:13         ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1085773482.3036.81.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=carette@mcmaster.ca \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).