with-scoped-allocation ( c-types quot -- )


Vocabulary
alien.data

Inputs and outputs
c-typesa list of scoped allocation specifiers
quota quotation


Word description
Allocates values on the call stack, calls the quotation, then deallocates the values as soon as the quotation returns.

A scoped allocation specifier is either:
a C type name,
or a triple with shape { c-type initial: initial }, where c-type is a C type name and initial is a literal value.

If no initial value is specified, the contents of the allocated memory are undefined.

Warning
Reading or writing a scoped allocation buffer outside of the given quotation will cause memory corruption.


Examples
USING: accessors alien.c-types alien.data classes.struct kernel math math.functions prettyprint ; IN: scratchpad STRUCT: test-point { x int } { y int } ; : scoped-allocation-test ( -- x ) { test-point } [ 3 >>x 4 >>y [ x>> sq ] [ y>> sq ] bi + sqrt ] with-scoped-allocation ; scoped-allocation-test .
5.0


Definition