* [Caml-list] Are multiple return values optimized?
@ 2001-07-19 0:07 Krishnaswami, Neel
0 siblings, 0 replies; 3+ messages in thread
From: Krishnaswami, Neel @ 2001-07-19 0:07 UTC (permalink / raw)
To: 'caml-list@inria.fr'
Hello,
Are multiple return values optimized to avoid heap-allocation
like curried functions are? In Scheme and Lisp, I'm used to an
expression like
(define foo
(lambda () (values 1 2 3)))
(call-with-values foo
(lambda (x y z) (+ x y z))
evaluating without doing any heap-allocation. Will the analgous
OCaml
let foo() = (1, 2, 3)
let x, y, z = foo()
in x + y + z
also pass values on the stack or will a tuple be heap-allocated?
Simple experiments with ocamlopt -S suggest the latter, but it's
possible that there are optimized cases that I don't know how
to write.
--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
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/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Are multiple return values optimized?
2001-07-16 20:33 Krishnaswami, Neel
@ 2001-07-20 15:37 ` Xavier Leroy
0 siblings, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2001-07-20 15:37 UTC (permalink / raw)
To: Krishnaswami, Neel; +Cc: 'caml-list@inria.fr'
> Are multiple return values optimized to avoid heap-allocation
> like curried functions are?
No, a tuple of results is always heap-allocated. However, with
Caml's generational GC, the cost of allocating such short-lived tuples
is quite low.
- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Caml-list] Are multiple return values optimized?
@ 2001-07-16 20:33 Krishnaswami, Neel
2001-07-20 15:37 ` Xavier Leroy
0 siblings, 1 reply; 3+ messages in thread
From: Krishnaswami, Neel @ 2001-07-16 20:33 UTC (permalink / raw)
To: 'caml-list@inria.fr'
Hello,
Are multiple return values optimized to avoid heap-allocation
like curried functions are? In Scheme and Lisp, I'm used to an
expression like
(define foo
(lambda () (values 1 2 3)))
(call-with-values foo
(lambda (x y z) (+ x y z))
evaluating without doing any heap-allocation. Will the analgous
OCaml
let foo() = (1, 2, 3)
let x, y, z = foo()
in x + y + z
also pass values on the stack or will a tuple be heap-allocated?
Simple experiments with ocamlopt -S suggest the latter, but it's
possible that there are optimized cases that I don't know how
to write.
--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-07-20 15:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-19 0:07 [Caml-list] Are multiple return values optimized? Krishnaswami, Neel
-- strict thread matches above, loose matches on Subject: below --
2001-07-16 20:33 Krishnaswami, Neel
2001-07-20 15:37 ` Xavier Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox