chickadee » jiffi » define-struct-allocators

(define-struct-allocators ...)syntax

Defines various procedures to allocate or free memory for a struct/union type defined with define-armor-type. You can omit any procedures that you don't need. Also generates type declarations for the procedures that are defined.

See "Which allocator should I use?" in the Getting Started guide.

Usage:

(define-struct-allocators
  (ARMOR-NAME "STRUCT_NAME" PRED WRAP)
  free:       FREE                 ; optional
  alloc:      ALLOC                ; optional
  alloc/blob: ALLOC/BLOB           ; optional
  make:       MAKE                 ; optional
  make/af:    MAKE/AUTOFREE        ; optional
  make/blob:  MAKE/BLOB            ; optional
  defaults:   (SLOT-DEFAULT ...)   ; optional

ARMOR-NAME is the name of the record type that is returned by WRAP, such as the record name that was passed to define-armor-type.

"STRUCT_NAME" is a string containing the name of the C struct/union, exactly as it appears in C.

PRED is an existing type predicate procedure for the armor type, such as a procedure defined with define-armor-type.

WRAP is an existing procedures that wraps bare data in an armor instance, such as an armor wrapper procedure defined with define-armor-type.

FREE is the procedure name to define as a struct freer. If FREE is #f or the keyword clause is omitted, the procedure will not be defined.

ALLOC and ALLOC/BLOB are the procedure names to define as struct memory allocators. If any is #f or its keyword clause is omitted, that procedure will not be defined.

MAKE, MAKE/AUTOFREE, and MAKE/BLOB are the procedure names to define as struct makers. If any is #f or its keyword clause is omitted, that procedure will not be defined.

Each SLOT-DEFAULT is the default value of each additional SLOT defined with define-armor-type. MAKE, MAKE/AUTOFREE, and MAKE/BLOB will pass the SLOT-DEFAULTs as extra arguments to WRAP.

Example:

(define-struct-allocators
  (event "FOO_Event" event? wrap-event)
  free:       free-event!
  alloc:      alloc-event
  alloc/blob: alloc-event/blob
  make:       make-event
  make/af:    make-event/autofree
  make/blob:  make-event/blob
  defaults:   ("e1" 'e2))     ; defaults for `extra1' and `extra2'