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


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.

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

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 .