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/loader/README.md
+38-89
Original file line number
Diff line number
Diff line change
@@ -30,93 +30,23 @@ API
30
30
31
31
Besides demangling classes exported from your entry file to a handy object structure one can use like JS objects, instances are automatically populated with useful utility:
32
32
33
-
***I8**: `Int8Array`<br />
34
-
An 8-bit signed integer view on the memory.
35
-
36
-
```ts
37
-
var value =module.I8[ptr];
38
-
```
39
-
40
-
***U8**: `Uint8Array`<br />
41
-
An 8-bit unsigned integer view on the memory.
42
-
43
-
```ts
44
-
var value =module.U8[ptr];
45
-
```
46
-
47
-
***I16**: `Int16Array`<br />
48
-
A 16-bit signed integer view on the memory.
49
-
50
-
```ts
51
-
var value =module.I16[ptr>>>1];
52
-
```
53
-
54
-
***U16**: `Uint16Array`<br />
55
-
A 16-bit unsigned integer view on the memory.
56
-
57
-
```ts
58
-
var value =module.U16[ptr>>>1];
59
-
```
60
-
61
-
***I32**: `Int32Array`<br />
62
-
A 32-bit signed integer view on the memory.
63
-
64
-
```ts
65
-
var value =module.I32[ptr>>>2];
66
-
```
67
-
68
-
***U32**: `Uint32Array`<br />
69
-
A 32-bit unsigned integer view on the memory.
70
-
71
-
```ts
72
-
var value =module.U32[ptr>>>2];
73
-
```
74
-
75
-
***I64**: `BigInt64Array`<br />
76
-
A 64-bit signed integer view on the memory, if supported by the VM.
77
-
78
-
```ts
79
-
var value =module.I64[ptr>>>3];
80
-
```
81
-
82
-
***U64**: `BigUint64Array`<br />
83
-
A 64-bit unsigned integer view on the memory, if supported by the VM.
84
-
85
-
```ts
86
-
var value =module.U64[ptr>>>3];
87
-
```
88
-
89
-
***F32**: `Float32Array`<br />
90
-
A 32-bit float view on the memory.
91
-
92
-
```ts
93
-
var value =module.I32[ptr>>>2];
94
-
```
95
-
96
-
***F64**: `Float64Array`<br />
97
-
A 64-bit float view on the memory.
98
-
99
-
```ts
100
-
var value =module.F64[ptr>>>3];
101
-
```
102
-
103
33
***__start**(): `void`<br />
104
34
Explicit start function if the `--explicitStart` option is used. Must be called before any other exports if present.
105
35
106
36
***__allocString**(str: `string`): `number`<br />
107
37
Allocates a new string in the module's memory and returns a reference (pointer) to it.
Reads (copies) the value of a string from the module's memory.
117
47
118
48
```ts
119
-
var str =module.__getString(ref);
49
+
var str =module.__getString(ptr);
120
50
...
121
51
```
122
52
@@ -125,44 +55,63 @@ Besides demangling classes exported from your entry file to a handy object struc
125
55
Automatically retains interior pointers. The `id` is the unique runtime id of the respective array class. If you are using `Int32Array` for example, the best way to know the id is an `export const INT32ARRAY_ID = idof<Int32Array>()`. When done with the array, make sure to release it.
Gets a view on the values of an array in the module's memory. This differs from `__getArray` in that the data isn't copied but remains *live* in both directions. That's faster but also unsafe because if the array grows or becomes released, the view will no longer represent the correct memory region and modifying its values in this state will most likely corrupt memory. Use, but use with care.
143
73
144
-
***__retain**(ref: `number`): `number`<br />
145
-
Retains a reference externally, making sure that it doesn't become collected prematurely. Returns the reference.
74
+
If the type of the array is known beforehand, the following even faster and even more unsafe helpers can be used that don't do any type checking:
Allocates an instance of the class represented by the specified id. If you are using `MyClass` for example, the best way to know the id and the necessary size is an `export const MYCLASS_ID = idof<MyClass>()` and an `export const MYCLASS_SIZE = offsetof<MyClass>()`. Afterwards, use the respective views to assign values to the class's memory while making sure to retain interior references to other managed objects once. When done with the class, make sure to release it, which will automatically release any interior references once the class becomes collected.
152
99
153
100
```ts
154
-
var ref =module.__retain(module.__alloc(module.MYCLASS_SIZE, module.MYCLASS_ID));
0 commit comments