SML# Document Version 3.7.1
19 Expressions

19.23 Size expression _sizeof(ty)

This is a constant expression denoting the size (in bytes) of the values of type ty. The type of this expression is ty size and its value is an integer indicating the number of bytes.

The size expressions are usually used to call polymorphic C functions. For example, the following is the import expression that imports memcpy in the C standard library for copying the first element of arrays:

val ’a#unboxed memcpy =
    _import "memcpy" : (’a array, ’a vector, ’a size) -> unit ptr

This function is called in the following way:

fun ’a#unboxed copy (a : ’a array, v) =
    if Array.length a > 0 andalso Vector.length v > 0
    then memcpy (a, v, _sizeof(’a))
    else ()