You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/dstructs/struct/README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,14 +102,16 @@ TODO: document constructor API
102
102
103
103
- The struct schema supports default values. In C, uninitialized members are zero-filled.
104
104
- The struct schema supports "casting modes", which govern member assignment operations and support placing (or relaxing) strict requirements on what types of values may be assigned to struct members. In C, members have no such limitations, with the C compiler performing implicit casting (e.g., a signed integer will be implicitly cast to an unsigned integer when a member has an unsigned integer data type).
105
-
- Only fixed-width types are supported (e.g., `int8`, `float64`, etc). In C, members can have types which may vary across platforms (e.g., `int`).
105
+
- Only fixed-width types are supported (e.g., `int8`, `float64`, etc). In C, members can have types which may vary across platforms (e.g., `int`, `enum`, `long double`, etc).
106
106
- Member types must be serializable to an ArrayBuffer (e.g., no functions, general objects, etc). In C, members have no such limitations (e.g., a member can be a function pointer).
107
107
- Union types must all have the same byte length. In C, members of union types can have different byte lengths.
108
108
- struct instances can have "hidden" (i.e., non-enumerable) fields. In C, all members are part of a `struct`'s public API.
109
109
- struct instances can have read-only fields. In C, one can use a `const` qualifier to prevent assignment after initialization; however, one can circumvent this restriction using pointer tricks.
110
110
- Member types can have an associated description, which is useful when wanting to inspect struct instances in interactive contexts, such as REPLs.
111
111
- struct instances support string and JSON serialization.
112
112
113
+
- A primary use case for emulating C `struct` behavior is to facilitate interoperation between JavaScript and C. For example, by creating a JavaScript struct instance which has the same alignment and layout as a C `struct`, one can pass a pointer to a struct instance's underlying byte buffer from JavaScript to C and then simply perform a cast to interpret as an equivalent C `struct`. This enables zero-copy interchange when, e.g., calling into Node.js native native add-ons and can greatly reduce overhead when working with heterogeneous composite data types.
0 commit comments