balloc 1.3.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.MD +171 -318
- package/docs/API /342/200/224 balloc.en.md" +472 -1156
- package/docs/MIGRATION /342/200/224 balloc.en.md" +208 -0
- package/package.json +2 -44
- package/src/README.MD +0 -0
- package/src/en/balloc.cjs +515 -933
- package/src/en/balloc.js +1 -1
- package/src/en/balloc.mjs +561 -1064
- package/types/README.MD +0 -0
- package/types/en/balloc.d.mts +279 -554
- package/README.ar.md +0 -409
- package/README.en.md +0 -437
- package/README.es.md +0 -409
- package/README.jp.md +0 -408
- package/README.pt.md +0 -433
- package/README.zh.md +0 -408
- package/docs/API /342/200/224 balloc.ar.md" +0 -1453
- package/docs/API /342/200/224 balloc.es.md" +0 -1269
- package/docs/API /342/200/224 balloc.jp.md" +0 -1208
- package/docs/API /342/200/224 balloc.pt.md" +0 -1339
- package/docs/API /342/200/224 balloc.zh.md" +0 -1268
- package/src/ar/balloc.cjs +0 -1273
- package/src/ar/balloc.js +0 -2
- package/src/ar/balloc.mjs +0 -1548
- package/src/es/balloc.cjs +0 -1288
- package/src/es/balloc.js +0 -2
- package/src/es/balloc.mjs +0 -1563
- package/src/jp/balloc.cjs +0 -1228
- package/src/jp/balloc.js +0 -2
- package/src/jp/balloc.mjs +0 -1503
- package/src/pt/balloc.cjs +0 -1293
- package/src/pt/balloc.js +0 -2
- package/src/pt/balloc.mjs +0 -1568
- package/src/zh/balloc.cjs +0 -1175
- package/src/zh/balloc.js +0 -2
- package/src/zh/balloc.mjs +0 -1450
- package/types/ar/balloc.d.mts +0 -762
- package/types/es/balloc.d.mts +0 -777
- package/types/jp/balloc.d.mts +0 -717
- package/types/pt/balloc.d.mts +0 -781
- package/types/zh/balloc.d.mts +0 -664
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Migration Guide: Balloc 1.x to 2.0.0
|
|
2
|
+
|
|
3
|
+
## 1. Scope and compatibility
|
|
4
|
+
|
|
5
|
+
Balloc 2.0.0 is a redesign of the allocator's storage model. It is not a drop-in replacement for 1.x. Existing applications must be adapted and tested; changing the package version alone is insufficient.
|
|
6
|
+
|
|
7
|
+
This guide compares the 1.4.0 implementation with the 2.0.0 public API. The 1.x line contains multiple releases, so verify behavior against the exact version deployed by your application before applying the examples.
|
|
8
|
+
|
|
9
|
+
The main migration tasks are:
|
|
10
|
+
|
|
11
|
+
1. Replace assumptions about a shared heap with independent block storage.
|
|
12
|
+
2. Revisit constructor arguments and allocation size units.
|
|
13
|
+
3. Update code that reads allocator internals or heap diagnostics.
|
|
14
|
+
4. Review block operations whose semantics or return values changed.
|
|
15
|
+
5. Treat serialized data as a format migration, not as a transparent upgrade.
|
|
16
|
+
|
|
17
|
+
## 2. Architectural changes
|
|
18
|
+
|
|
19
|
+
| Concern | 1.x | 2.0.0 |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| Data storage | One allocator-managed `dataBus` shared by blocks. | Each block owns an independent `ArrayBuffer`. |
|
|
22
|
+
| Metadata | Separate `controlBus` with block headers. | Per-block records held by the allocator instance. |
|
|
23
|
+
| Allocation | Bump allocation from the shared heap, with power-of-two block capacities. | A new `ArrayBuffer` is allocated for each block. |
|
|
24
|
+
| Reuse | Freed regions and headers can be recycled. | Freed handles are invalidated and never reused. |
|
|
25
|
+
| Compaction | `gc()` compacts live regions in the shared heap. | No shared heap or compaction operation exists. |
|
|
26
|
+
| Handle | Encodes an 11-bit generation and a 32-bit header address. | Monotonically increasing numeric identifier in the unsigned 32-bit range. |
|
|
27
|
+
| Block capacity | Rounded to a power of two in elements. | Determined by the requested byte size and element width. |
|
|
28
|
+
|
|
29
|
+
In 1.x, a block was a region inside allocator-owned storage. In 2.0.0, a block is an independently allocated typed view over its own buffer. Operations that previously depended on moving, recycling, or compacting regions must be redesigned around the lifetime of each block.
|
|
30
|
+
|
|
31
|
+
Do not persist handles as durable identifiers. In both models, handles belong to an allocator instance and are not a portable representation of block contents. In 2.0.0, a freed handle is not reassigned to a later allocation.
|
|
32
|
+
|
|
33
|
+
## 3. Constructor migration
|
|
34
|
+
|
|
35
|
+
The constructor signature changed:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
// 1.x
|
|
39
|
+
const memory = new Balloc(size, bucketSize, metadataSize);
|
|
40
|
+
|
|
41
|
+
// 2.0.0
|
|
42
|
+
const memory = new Balloc(maxByteSize, defaultBucketType);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| Argument | 1.x meaning | 2.0.0 meaning |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| First | Initial `dataBus` capacity in bytes; default `65535`. | Upper bound used to validate allocation sizes; default `0x80000000`. |
|
|
48
|
+
| Second | Required allocator-wide element type; default `"32u"`. | Optional default element type; default `null`. When null, each `alloc()` call defaults to `"32u"`. |
|
|
49
|
+
| Third | Initial `controlBus` capacity in bytes; default `1024`. | Removed. |
|
|
50
|
+
|
|
51
|
+
The first argument is particularly important: a value that limited the initial heap in 1.x now limits individual allocation requests in 2.0.0. It no longer preallocates a shared heap. Do not carry the old value forward without deciding what maximum block size the application actually needs.
|
|
52
|
+
|
|
53
|
+
The second argument remains a bucket identifier, but 2.0.0 allows the type to be selected per allocation unless a constructor-level default is supplied.
|
|
54
|
+
|
|
55
|
+
Example:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
// 1.x: allocator-wide Uint16 elements; initial data and metadata buffers.
|
|
59
|
+
const memory = new Balloc(65535, "16u", 1024);
|
|
60
|
+
const handler = memory.alloc(100); // requested element count
|
|
61
|
+
|
|
62
|
+
// 2.0.0: optional default type; alloc() size is in bytes.
|
|
63
|
+
const memory = new Balloc(0x80000000, "16u");
|
|
64
|
+
const handler = memory.alloc(200); // 200 bytes = 100 Uint16 elements
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
If the application previously relied on one fixed type, setting the second constructor argument in 2.0.0 preserves that policy. If the application needs mixed element types, leave it null and pass a type to each allocation.
|
|
68
|
+
|
|
69
|
+
## 4. Allocation size units
|
|
70
|
+
|
|
71
|
+
This is a source of silent migration errors.
|
|
72
|
+
|
|
73
|
+
- In 1.x, `alloc(size)` takes a minimum **number of elements**. The allocator rounds capacity up to a power of two.
|
|
74
|
+
- In 2.0.0, `alloc(size, bucketType)` takes a **number of bytes**. The size must be a safe integer, at least 2, below the configured maximum, and aligned to the selected element width. Capacity is the byte size divided by bytes per element; it is not rounded to a power of two.
|
|
75
|
+
|
|
76
|
+
For example, allocating 100 elements of `"32u"` in 1.x requested 100 elements and reserved a power-of-two capacity of 128 elements. In 2.0.0, the equivalent initial capacity is 400 bytes:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
// 1.x
|
|
80
|
+
const handler = memory.alloc(100); // 100 requested elements; capacity rounded up
|
|
81
|
+
|
|
82
|
+
// 2.0.0
|
|
83
|
+
const handler = memory.alloc(100 * Uint32Array.BYTES_PER_ELEMENT, "32u");
|
|
84
|
+
// 400 bytes, exactly 100 Uint32 elements
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The default allocation is also different. In 1.x, `alloc()` defaulted to 16 elements. In 2.0.0, `alloc()` defaults to 16 bytes and `"32u"`, which provides 4 elements. Specify the size and type explicitly when preserving previous capacity matters.
|
|
88
|
+
|
|
89
|
+
A useful conversion for a fixed element count is:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
const byteSize = elementCount * bytesPerElement;
|
|
93
|
+
const handler = memory.alloc(byteSize, bucketType);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Validate that the resulting byte size is aligned to the element width and remains below `maxByteSize`.
|
|
97
|
+
|
|
98
|
+
## 5. Block lifecycle and resizing
|
|
99
|
+
|
|
100
|
+
The lifecycle methods remain recognizable, but their storage effects differ.
|
|
101
|
+
|
|
102
|
+
| Operation | Migration notes |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `alloc()` | Revisit size units and bucket type; see the previous section. |
|
|
105
|
+
| `realloc(handler)` | In 1.x, capacity doubled by one power-of-two step. In 2.0.0, omitted `newSize` doubles element capacity; an explicit `newSize` is the requested capacity in **elements**, not bytes. |
|
|
106
|
+
| `shrink(handler)` | Both versions reduce capacity based on occupancy. In 2.0.0, a new buffer is allocated and occupied elements are copied; there is no released region to recycle. |
|
|
107
|
+
| `free(handler)` | Both invalidate the handle. In 2.0.0, the block registry entry is removed and that numeric handle is never reused. |
|
|
108
|
+
|
|
109
|
+
In 2.0.0, `realloc()` and `shrink()` replace the block's backing buffer. Any previously obtained direct view of the old buffer must not be treated as a live view of the resized block. Use `withView()` for scoped access and do not retain borrowed views after its callback returns.
|
|
110
|
+
|
|
111
|
+
Example of explicit resizing in 2.0.0:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
const handler = memory.alloc(64, "32u"); // 16 elements
|
|
115
|
+
memory.put(handler, [10, 20, 30, 40]);
|
|
116
|
+
memory.realloc(handler, 32); // 32 elements
|
|
117
|
+
memory.shrink(handler); // capacity based on occupancy
|
|
118
|
+
memory.free(handler);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 6. Data access and operation semantics
|
|
122
|
+
|
|
123
|
+
Most stack, queue, indexed, and bulk method names remain available. That does not guarantee identical behavior. Review code that depends on return types, capacity, occupancy, or the exact region affected.
|
|
124
|
+
|
|
125
|
+
### Important differences
|
|
126
|
+
|
|
127
|
+
- `length(handler)` continues to report capacity in elements, not bytes.
|
|
128
|
+
- `byteSize(handler)` reports physical capacity in bytes.
|
|
129
|
+
- `occupied(handler)` reports the logical occupied element count.
|
|
130
|
+
- `pick(handler)` returns a copy of the occupied prefix; it is not a live view.
|
|
131
|
+
- `withView(...handlers, callback)` provides scoped zero-copy views of occupied prefixes. Do not retain or return those views or derived subviews after the callback. The borrow is synchronous; returning a Promise does not extend it.
|
|
132
|
+
- `fill(handler, value, start, end)` in 1.x set occupancy to the full capacity after filling, regardless of the selected range. In 2.0.0 occupancy becomes `max(previousOccupancy, end)`. Code that relied on `fill()` to mark the whole block occupied should use `fillAll()`.
|
|
133
|
+
- `copy(source, destination, slots)` returns the destination's typed-array view in 2.0.0. The 1.x implementation returned a `Uint8Array` view over the shared data bus. Do not rely on the old return value as a global heap view.
|
|
134
|
+
- `clone(handler)` creates independent storage in both versions. In 2.0.0 the clone copies the source typed array, including unoccupied slots, and preserves occupancy and bucket type.
|
|
135
|
+
- `swap(source, target)` exchanges the block objects associated with the two handles in 2.0.0. The 1.x implementation exchanged the memory regions described by the headers. Code must not assume that internal storage identity or metadata behaves the same way.
|
|
136
|
+
|
|
137
|
+
The queue operations `nudge()` and `pull()` remain operations on the occupied prefix. Verify application-specific assumptions about queue ordering and occupancy rather than accessing the underlying buffer directly.
|
|
138
|
+
|
|
139
|
+
### Example: replacing direct heap access
|
|
140
|
+
|
|
141
|
+
Code that depended on `dataBus`, `controlBus`, `auxiliary`, `dataPointer`, `controlPointer`, or decoded header metadata is coupled to the 1.x implementation. Those structures are not a supported 2.0.0 access interface.
|
|
142
|
+
|
|
143
|
+
Use the public block API instead:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
// Read a copy of the occupied values.
|
|
147
|
+
const values = memory.pick(handler);
|
|
148
|
+
|
|
149
|
+
// Mutate occupied values without copying, within the callback's lifetime.
|
|
150
|
+
memory.withView(handler, view => {
|
|
151
|
+
for (let i = 0; i < view.length; i++) view[i] *= 2;
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 7. Removed heap management and diagnostics
|
|
156
|
+
|
|
157
|
+
The following 1.x facilities have no direct 2.0.0 equivalent:
|
|
158
|
+
|
|
159
|
+
- `gc()`: shared-heap compaction.
|
|
160
|
+
- `recycleCount()` and `recycleBytes`: recycled-region counters.
|
|
161
|
+
- `allocatedBytes` and `unallocatedBytes`: shared-heap accounting.
|
|
162
|
+
- `fragmentationRatio`: shared-heap fragmentation metric.
|
|
163
|
+
- Internal heap and metadata helpers such as `grow()`, `headerGrow()`, `recyclePush()`, `recyclePop()`, `extractMetadata()`, and `bakeCookie()`.
|
|
164
|
+
|
|
165
|
+
Remove calls to these facilities. Do not replace `gc()` with a loop that calls `shrink()` indiscriminately: shrinking is a per-block capacity operation, not heap compaction. If the application needs memory accounting, maintain application-level metrics using the block-level values `byteSize()`, `length()`, and `occupied()`. These values describe live blocks, not a shared heap's fragmentation or unallocated tail.
|
|
166
|
+
|
|
167
|
+
## 8. Serialization compatibility
|
|
168
|
+
|
|
169
|
+
Do not assume that serialized data produced by 1.x can be loaded by 2.0.0.
|
|
170
|
+
|
|
171
|
+
Version 2.0.0 uses a CBOR version 2 envelope containing the bucket type, capacity in elements, occupancy, and a typed-array payload containing only occupied elements. Its `load()` validates that envelope and rejects unsupported versions or incompatible payloads. The 1.x serialization contract is different; existing serialized artifacts must be treated as legacy data.
|
|
172
|
+
|
|
173
|
+
Migration procedure:
|
|
174
|
+
|
|
175
|
+
1. Keep a reader or executable environment using the exact 1.x version that produced the data.
|
|
176
|
+
2. Decode each legacy artifact with that version.
|
|
177
|
+
3. Extract the logical records or occupied typed-array values and their element type.
|
|
178
|
+
4. Allocate a corresponding block in 2.0.0, accounting for the new byte-based `alloc()` argument.
|
|
179
|
+
5. Populate the new block and serialize it using 2.0.0 `dump()`.
|
|
180
|
+
6. Verify element type, ordering, occupancy, and application-level meaning after round-trip restoration.
|
|
181
|
+
|
|
182
|
+
Do not attempt to migrate serialized bytes by editing the CBOR envelope manually unless the legacy format is fully specified and independently validated.
|
|
183
|
+
|
|
184
|
+
## 9. Data-ingestion adapters
|
|
185
|
+
|
|
186
|
+
The `loadData(adapter)` method remains synchronous and delegates to `adapter.load(allocator)`. The adapter still owns the allocations it creates and must clean them up if ingestion fails. Review adapters for assumptions about constructor-wide element types, allocation units, and access to shared heap internals.
|
|
187
|
+
|
|
188
|
+
The adapter's return value is passed through unchanged in 2.0.0; it is not validated as a handle.
|
|
189
|
+
|
|
190
|
+
## 10. Migration checklist
|
|
191
|
+
|
|
192
|
+
- [ ] Pin the exact 1.x version used by the application and inventory every Balloc call site.
|
|
193
|
+
- [ ] Replace the old constructor's initial-heap interpretation with an intentional 2.0.0 maximum-allocation limit.
|
|
194
|
+
- [ ] Remove the obsolete third constructor argument.
|
|
195
|
+
- [ ] Decide whether to set a constructor-level default bucket type or specify a type per allocation.
|
|
196
|
+
- [ ] Convert every `alloc()` request from element counts to byte sizes.
|
|
197
|
+
- [ ] Recalculate expected capacities; 2.0.0 does not round allocation capacity to a power of two.
|
|
198
|
+
- [ ] Review `realloc()` calls: explicit sizes are element counts in 2.0.0.
|
|
199
|
+
- [ ] Replace `fill()` calls that intended full occupancy with `fillAll()`.
|
|
200
|
+
- [ ] Remove `gc()`, recycling metrics, and all direct access to heap/header internals.
|
|
201
|
+
- [ ] Review any code that retains views across callbacks or resizing operations.
|
|
202
|
+
- [ ] Migrate persisted CBOR data through a 1.x decoder and a 2.0.0 re-encoding step.
|
|
203
|
+
- [ ] Test capacity, occupancy, element types, Number/BigInt conversions, error handling, and block release.
|
|
204
|
+
- [ ] Run integration tests against the actual workload before deploying.
|
|
205
|
+
|
|
206
|
+
## 11. Final compatibility note
|
|
207
|
+
|
|
208
|
+
The public method names retained by 2.0.0 are not evidence of behavioral compatibility. The storage architecture, allocation units, handle representation, diagnostics, and serialization contract changed. Treat the upgrade as a deliberate port to a block-oriented allocator and validate application behavior at the data and lifecycle levels.
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balloc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"homepage": "https://github.com/AugustoVasques75/balloc",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/AugustoVasques75/balloc.git"
|
|
8
8
|
},
|
|
9
|
-
"description": "
|
|
9
|
+
"description": "Allocation memory allocator",
|
|
10
10
|
"main": "./src/en/balloc.mjs",
|
|
11
11
|
"unpkg": "./src/en/balloc.js",
|
|
12
12
|
"jsdelivr": "./src/en/balloc.js",
|
|
@@ -18,12 +18,6 @@
|
|
|
18
18
|
"types/",
|
|
19
19
|
"LICENSE",
|
|
20
20
|
"README.MD",
|
|
21
|
-
"README.ar.md",
|
|
22
|
-
"README.en.md",
|
|
23
|
-
"README.es.md",
|
|
24
|
-
"README.pt.md",
|
|
25
|
-
"README.jp.md",
|
|
26
|
-
"README.zh.md",
|
|
27
21
|
"CHANGELOG.md"
|
|
28
22
|
],
|
|
29
23
|
"exports": {
|
|
@@ -32,42 +26,6 @@
|
|
|
32
26
|
"import": "./src/en/balloc.mjs",
|
|
33
27
|
"require": "./src/en/balloc.cjs",
|
|
34
28
|
"default": "./src/en/balloc.js"
|
|
35
|
-
},
|
|
36
|
-
"./ar": {
|
|
37
|
-
"types": "./types/ar/balloc.d.mts",
|
|
38
|
-
"import": "./src/ar/balloc.mjs",
|
|
39
|
-
"require": "./src/ar/balloc.cjs",
|
|
40
|
-
"default": "./src/ar/balloc.js"
|
|
41
|
-
},
|
|
42
|
-
"./en": {
|
|
43
|
-
"types": "./types/en/balloc.d.mts",
|
|
44
|
-
"import": "./src/en/balloc.mjs",
|
|
45
|
-
"require": "./src/en/balloc.cjs",
|
|
46
|
-
"default": "./src/en/balloc.js"
|
|
47
|
-
},
|
|
48
|
-
"./es": {
|
|
49
|
-
"types": "./types/es/balloc.d.mts",
|
|
50
|
-
"import": "./src/es/balloc.mjs",
|
|
51
|
-
"require": "./src/es/balloc.cjs",
|
|
52
|
-
"default": "./src/es/balloc.js"
|
|
53
|
-
},
|
|
54
|
-
"./jp": {
|
|
55
|
-
"types": "./types/jp/balloc.d.mts",
|
|
56
|
-
"import": "./src/jp/balloc.mjs",
|
|
57
|
-
"require": "./src/jp/balloc.cjs",
|
|
58
|
-
"default": "./src/jp/balloc.js"
|
|
59
|
-
},
|
|
60
|
-
"./pt": {
|
|
61
|
-
"types": "./types/pt/balloc.d.mts",
|
|
62
|
-
"import": "./src/pt/balloc.mjs",
|
|
63
|
-
"require": "./src/pt/balloc.cjs",
|
|
64
|
-
"default": "./src/pt/balloc.js"
|
|
65
|
-
},
|
|
66
|
-
"./zh": {
|
|
67
|
-
"types": "./types/zh/balloc.d.mts",
|
|
68
|
-
"import": "./src/zh/balloc.mjs",
|
|
69
|
-
"require": "./src/zh/balloc.cjs",
|
|
70
|
-
"default": "./src/zh/balloc.js"
|
|
71
29
|
}
|
|
72
30
|
},
|
|
73
31
|
"scripts": {
|
package/src/README.MD
ADDED
|
File without changes
|