► |  | The Racket Foreign Interface

1 | Overview
2 | Loading Foreign Libraries
3 | C Types
4 | Pointer Functions
5 | Derived Utilities
6 | Miscellaneous Support
7 | Unexported Primitive Functions
| Bibliography
| Index

▼ | 5 | Derived Utilities

5.1 | Safe Homogenous Vectors
5.2 | Safe C Vectors
5.3 | Tagged C Pointer Types
5.4 | Serializable C Struct Types
5.5 | Defining Bindings
5.6 | Allocation and Finalization
5.7 | Custodian Shutdown Registration
5.8 | Atomic Execution
5.9 | Speculatively Atomic Execution
5.10 | Objective-C FFI
5.11 | Cocoa Foundation
5.12 | COM (Common Object Model)
5.13 | File Security-Guard Checks
5.14 | Windows API Helpers

► | 5.11 | Cocoa Foundation

5.11.1 | Strings
5.11.2 | Allocation Pools

On this page:

5.11.1`` Strings
_ NSString
5.11.2`` Allocation Pools
call-with-autorelease
with-autorelease

top ← prev up next →

#### 5.11`` Cocoa Foundation

The ffi/unsafe/nsalloc and ffi/unsafe/nsstring libraries provide basic facilities for working with Cocoa and/or Mac OS Foundation libraries (usually along with ffi/objc).

##### 5.11.1`` Strings

(require ffi/unsafe/nsstring) | package: base

> value _NSString : ctype?

A type that converts between Racket strings and NSString* (a.k.a. CFStringRef) values. That is, use _NSString as a type for a foreign-function NSString* argument or result.

The _NSString conversion keeps a weak mapping from Racket strings to converted strings, so that converting the same string (in the equal? sense) multiple times may avoid allocating multiple NSString objects.

##### 5.11.2`` Allocation Pools

(require ffi/unsafe/nsalloc) | package: base

Calling any Foundation API that allocates requires an NSAutoreleasePool installed. The ffi/unsafe/nsalloc library provides a function and shorthand syntactic form for setting up such a context. (The _NSString type creates an autorelease pool implicitly while converting from/to a Racket string, however.)

> procedure (call-with-autorelease thunk) → any
> thunk : (-> any)

Calls thunk in atomic mode and with a fresh NSAutoreleasePool that is released after thunk returns.

> syntax (with-autorelease expr)

A shorthand for (call-with-autorelease (lambda () expr)).
top ← prev up next →