Introduction

This sample tests the behavior of the OpenTK.BlittableValueType class. This class contains methods to simplify interop with unmanaged code: BlittableValueType.Check() returns true if the a specified type is safe for use with OpenGL/AL/CL, while BlittableValueType.StrideOf() returns the size of the type in bytes, after marshalling.

Because those methods are relatively expensive, their results are cached in BlittableValueType<T> automatically. Unlike System.Runtime.InteropServices.Marshal.SizeOf() and similar methods, BlittableValueType is safe to use in performance-sensitive code.

Controls

None.

Implementation

1. The sample defines a number of of simple and composite managed types (enums,  structs, generic structs, classes and generic classes and various combinations thereof.)

2. The Main method creates an instance of each type and calls BlittableValueType.Check to see whether each type is blittable and BlittableValueType.StrideOf to print the size of blittable instances.