Next Previous Up Top Contents Index

1.8 Allocating and deallocating C storage

with-stack-structure

Statement macro

Summary

Allocates an object within the scope of the body of the code.

Signature

with-stack-structure (name :: wrapper-type 
                      #key element-count extra-bytes) 
  body 
end [with-stack-structure]

Arguments

name
A Dylan variable name.

wrapper-type
A Dylan name.

element-count
An instance of <integer>.

extra-bytes
An instance of <integer>.

Library

c-ffi

Module

c-ffi

Description

Allocates an object name within the scope of a body. The element-count and extra-bytes options behave as in make. The memory that was allocated is freed after body exits.

This macro gives the object dynamic extent.

? define C-struct <PointStruct>
    slot x-coord :: <C-unsigned-short>;
    slot y-coord :: <C-unsigned-short>;
    pointer-type-name: <PointStruct*>
  end C-struct;

// Defined <PointStruct>, x-coord, x-coord-setter, // y-coord, and y-coord-setter.

? define constant <Point> = <PointStruct*>; // Defined <Point>.

? define C-function PlotPoint parameter point :: <Point>; c-name: "PlotPoint"; end C-function; // Defined PlotPoint.

? define method plot (x, y) with-stack-structure (point :: <Point>) point.x-coord := 20; point.y-coord := 30; PlotPoint(point); end; end; // Defined plot.

? plot(20, 20);

? plot(50, 50);


C FFI and Win 32 Reference - 31 MAR 2000

Next Previous Up Top Contents Index