balloc 1.0.0 → 1.2.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/README.MD +25 -2
- package/README.ar.md +25 -2
- package/README.en.md +25 -2
- package/README.es.md +25 -2
- package/README.jp.md +25 -2
- package/README.pt.md +24 -5
- package/README.zh.md +25 -2
- package/change.log.md +7 -0
- package/docs/API /342/200/224 balloc.ar.md" +36 -0
- package/docs/API /342/200/224 balloc.en.md" +36 -0
- package/docs/API /342/200/224 balloc.es.md" +36 -0
- package/docs/API /342/200/224 balloc.jp.md" +36 -0
- package/docs/API /342/200/224 balloc.pt.md" +171 -12
- package/docs/API /342/200/224 balloc.zh.md" +36 -0
- package/package.json +24 -8
- package/src/ar/balloc.cjs +474 -309
- package/src/ar/balloc.js +1 -1
- package/src/ar/balloc.mjs +566 -383
- package/src/en/balloc.cjs +387 -221
- package/src/en/balloc.js +1 -1
- package/src/en/balloc.mjs +477 -293
- package/src/es/balloc.cjs +383 -234
- package/src/es/balloc.js +1 -1
- package/src/es/balloc.mjs +485 -319
- package/src/jp/balloc.cjs +409 -277
- package/src/jp/balloc.js +1 -1
- package/src/jp/balloc.mjs +501 -351
- package/src/pt/balloc.cjs +212 -62
- package/src/pt/balloc.js +1 -1
- package/src/pt/balloc.mjs +287 -119
- package/src/zh/balloc.cjs +328 -197
- package/src/zh/balloc.js +1 -1
- package/src/zh/balloc.mjs +423 -275
- package/types/ar/balloc.d.mts +390 -278
- package/types/en/balloc.d.mts +319 -206
- package/types/es/balloc.d.mts +306 -210
- package/types/jp/balloc.d.mts +332 -253
- package/types/pt/balloc.d.mts +143 -46
- package/types/zh/balloc.d.mts +262 -184
package/README.MD
CHANGED
|
@@ -304,7 +304,7 @@ The complete API documentation is available in the [`./docs`](./docs) directory
|
|
|
304
304
|
| Chinese | [./docs/API — balloc.zh.md](./docs/API%20—%20balloc.zh.md) |
|
|
305
305
|
| Spanish | [./docs/API — balloc.es.md](./docs/API%20—%20balloc.es.md) |
|
|
306
306
|
| English | [./docs/API — balloc.en.md](./docs/API%20—%20balloc.en.md) |
|
|
307
|
-
| Japanese | [./docs/API — balloc.
|
|
307
|
+
| Japanese | [./docs/API — balloc.jp.md](./docs/API%20—%20balloc.jp.md) |
|
|
308
308
|
| Portuguese | [./docs/API — balloc.pt.md](./docs/API%20—%20balloc.pt.md) |
|
|
309
309
|
|
|
310
310
|
|
|
@@ -351,6 +351,8 @@ The following is a summary of these groups:
|
|
|
351
351
|
| API | Description |
|
|
352
352
|
| --- | --- |
|
|
353
353
|
| `has()` | Search for a value |
|
|
354
|
+
| `indexOf()` | Search for a value (first match) |
|
|
355
|
+
| `lastIndexOf()` | Search for a value (last match) |
|
|
354
356
|
| `get()` | Read an element |
|
|
355
357
|
| `set()` | Write an element |
|
|
356
358
|
| `clear()` | Clear occupancy and fill the block |
|
|
@@ -358,6 +360,7 @@ The following is a summary of these groups:
|
|
|
358
360
|
| `fillAll()` | Fill and occupy the entire block |
|
|
359
361
|
| `put()` | Copy an array into a block |
|
|
360
362
|
| `pick()` | Copy occupied elements out of a block |
|
|
363
|
+
| `withView()` | Borrow a typed view over occupied elements |
|
|
361
364
|
|
|
362
365
|
### Block interchange
|
|
363
366
|
|
|
@@ -383,12 +386,32 @@ The following is a summary of these groups:
|
|
|
383
386
|
| `byteSize()` | Physical block size in bytes |
|
|
384
387
|
| `occupied()` | Number of occupied elements |
|
|
385
388
|
| `length()` | Physical element capacity |
|
|
389
|
+
| `isFull()` | Check whether the block is completely occupied |
|
|
386
390
|
| `recycleCount()` | Number of recyclable regions |
|
|
387
391
|
| `recycleBytes` | Currently recyclable bytes |
|
|
388
392
|
| `allocatedBytes` | Bytes associated with non-recycled regions |
|
|
389
393
|
| `unallocatedBytes` | Space remaining after the bump pointer |
|
|
390
394
|
| `fragmentationRatio` | Recycled bytes / used heap area |
|
|
391
395
|
|
|
396
|
+
### Borrowing memory with `withView()`
|
|
397
|
+
|
|
398
|
+
`withView(handler, callback)` provides the callback with a `TypedArray` directly over the block's occupied region. The view is not a copy: changes made through it modify the block's contents. The callback is synchronous, receives the view as its only argument, and its return value is propagated by `withView()`.
|
|
399
|
+
|
|
400
|
+
The view must not be retained or used after the callback finishes. If the callback returns a Promise, the borrow is released immediately when that Promise is returned; it is not held until the Promise settles. The lock is also released if the callback throws.
|
|
401
|
+
|
|
402
|
+
While a block is borrowed, operations that directly modify it are blocked, including `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `free()`, and copy operations that use it as the destination. `swap()` is also blocked if either block is borrowed. Read operations and operations that use the block only as a source remain allowed.
|
|
403
|
+
|
|
404
|
+
Operations that replace or remap `dataBus`, such as `gc()` and bus growth triggered by `alloc()` or `realloc()`, are blocked while any view is active.
|
|
405
|
+
|
|
406
|
+
Example:
|
|
407
|
+
|
|
408
|
+
```js
|
|
409
|
+
const result = memory.withView(handler, view => {
|
|
410
|
+
view[0] = 42;
|
|
411
|
+
return view.length;
|
|
412
|
+
});
|
|
413
|
+
```
|
|
414
|
+
|
|
392
415
|
### Internal functions
|
|
393
416
|
|
|
394
417
|
These are a special class of API primarily used internally by the allocator and generally not recommended for day-to-day code, as they may cause undocumented side effects. They are intended for library extensions and modifications where a thorough understanding of the Balloc source code is essential.
|
|
@@ -426,7 +449,7 @@ If you like this project and want to support its development:
|
|
|
426
449
|
|
|
427
450
|
| Pix QR Code | Copy-and-Paste / Random Key |
|
|
428
451
|
| :---: | :--- |
|
|
429
|
-
|  | **Random Key:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
430
453
|
|
|
431
454
|
## License
|
|
432
455
|
|
package/README.ar.md
CHANGED
|
@@ -278,7 +278,7 @@ alloc()
|
|
|
278
278
|
| الصينية | [./docs/API — balloc.zh.md](./docs/API%20—%20balloc.zh.md) |
|
|
279
279
|
| الإسبانية | [./docs/API — balloc.es.md](./docs/API%20—%20balloc.es.md) |
|
|
280
280
|
| الإنجليزية | [./docs/API — balloc.en.md](./docs/API%20—%20balloc.en.md) |
|
|
281
|
-
| اليابانية | [./docs/API — balloc.
|
|
281
|
+
| اليابانية | [./docs/API — balloc.jp.md](./docs/API%20—%20balloc.jp.md) |
|
|
282
282
|
| البرتغالية | [./docs/API — balloc.pt.md](./docs/API%20—%20balloc.pt.md) |
|
|
283
283
|
|
|
284
284
|
تُصنَّف أساليب API بحسب الوظيفة ضمن المجموعات التالية:
|
|
@@ -324,6 +324,8 @@ alloc()
|
|
|
324
324
|
| API | الوصف |
|
|
325
325
|
|---|---|
|
|
326
326
|
| `has()` | البحث عن قيمة |
|
|
327
|
+
| `indexOf()` | البحث عن أول ظهور لقيمة |
|
|
328
|
+
| `lastIndexOf()` | البحث عن آخر ظهور لقيمة |
|
|
327
329
|
| `get()` | قراءة عنصر |
|
|
328
330
|
| `set()` | كتابة عنصر |
|
|
329
331
|
| `clear()` | مسح حالة الإشغال وملء الكتلة |
|
|
@@ -331,6 +333,7 @@ alloc()
|
|
|
331
333
|
| `fillAll()` | ملء الكتلة بالكامل وجعل جميع عناصرها مشغولة |
|
|
332
334
|
| `put()` | نسخ مصفوفة إلى كتلة |
|
|
333
335
|
| `pick()` | نسخ العناصر المشغولة من كتلة إلى خارجها |
|
|
336
|
+
| `withView()` | استعارة عرض TypedArray للعناصر المشغولة |
|
|
334
337
|
|
|
335
338
|
### تبادل البيانات بين الكتل
|
|
336
339
|
|
|
@@ -356,12 +359,32 @@ alloc()
|
|
|
356
359
|
| `byteSize()` | إرجاع الحجم المادي للكتلة بالبايت |
|
|
357
360
|
| `occupied()` | إرجاع عدد العناصر المشغولة |
|
|
358
361
|
| `length()` | إرجاع السعة المادية بالعناصر |
|
|
362
|
+
| `isFull()` | التحقق مما إذا كانت الكتلة مشغولة بالكامل |
|
|
359
363
|
| `recycleCount()` | إرجاع عدد المناطق القابلة لإعادة الاستخدام |
|
|
360
364
|
| `recycleBytes` | عدد البايتات القابلة لإعادة الاستخدام حاليًا |
|
|
361
365
|
| `allocatedBytes` | عدد البايتات المرتبطة بمناطق غير قابلة لإعادة الاستخدام |
|
|
362
366
|
| `unallocatedBytes` | المساحة المتبقية بعد مؤشر التخصيص المتزايد |
|
|
363
367
|
| `fragmentationRatio` | البايتات القابلة لإعادة الاستخدام / مساحة الكومة المستخدمة |
|
|
364
368
|
|
|
369
|
+
### استعارة الذاكرة باستخدام `withView()`
|
|
370
|
+
|
|
371
|
+
توفر `withView(handler, callback)` للدالة الراجعة `callback` مصفوفة `TypedArray` مرتبطة مباشرة بمنطقة العناصر المشغولة في الكتلة. هذه المصفوفة ليست نسخة؛ فالتغييرات التي تُجرى عليها تعدّل محتوى الكتلة نفسه. تُنفّذ الدالة الراجعة بصورة متزامنة، وتتلقى المصفوفة بوصفها وسيطها الوحيد، وتُعيد `withView()` القيمة التي تُرجعها الدالة.
|
|
372
|
+
|
|
373
|
+
يجب عدم الاحتفاظ بالمصفوفة أو استخدامها بعد انتهاء الدالة الراجعة. إذا أعادت الدالة Promise، تنتهي الاستعارة فور إعادة هذه الـPromise، ولا يستمر القفل حتى اكتمالها. ويُحرر القفل أيضًا إذا أطلقت الدالة استثناءً.
|
|
374
|
+
|
|
375
|
+
أثناء استعارة كتلة، تُحظر العمليات التي تعدّلها مباشرة، ومنها `push()` و`pop()` و`nudge()` و`pull()` و`set()` و`clear()` و`fill()` و`fillAll()` و`put()` و`realloc()` و`free()` وعمليات النسخ التي تكون الكتلة فيها وجهةً. كما تُحظر `swap()` إذا كانت أي من الكتلتين مستعارة. وتظل عمليات القراءة والعمليات التي تستخدم الكتلة مصدرًا فقط مسموحة.
|
|
376
|
+
|
|
377
|
+
تُحظر العمليات التي تستبدل `dataBus` أو تعيد تعيين موضعه، مثل `gc()` وتوسعة الناقل الناتجة عن `alloc()` أو `realloc()`، ما دامت أي مصفوفة نشطة.
|
|
378
|
+
|
|
379
|
+
مثال:
|
|
380
|
+
|
|
381
|
+
```js
|
|
382
|
+
const result = memory.withView(handler, view => {
|
|
383
|
+
view[0] = 42;
|
|
384
|
+
return view.length;
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
365
388
|
### الدوال الداخلية
|
|
366
389
|
|
|
367
390
|
تمثل هذه الدوال حالة خاصة من واجهة API، وتُستخدم أساسًا داخل المُخصِّص نفسه. لا يُوصى عادةً باستعمالها في الشيفرة اليومية، إذ قد تُحدث آثارًا جانبية غير موثقة. وهي مخصصة لتوسيع المكتبة أو تعديلها، ويتطلب استخدامها فهمًا كاملًا للشيفرة المصدرية لـBalloc.
|
|
@@ -398,7 +421,7 @@ alloc()
|
|
|
398
421
|
|
|
399
422
|
| رمز QR لخدمة Pix | مفتاح النسخ واللصق / المفتاح العشوائي |
|
|
400
423
|
| :---: | :--- |
|
|
401
|
-
|  | **المفتاح العشوائي:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
402
425
|
|
|
403
426
|
## الترخيص
|
|
404
427
|
|
package/README.en.md
CHANGED
|
@@ -304,7 +304,7 @@ The complete API documentation is available in the [`./docs`](./docs) directory
|
|
|
304
304
|
| Chinese | [./docs/API — balloc.zh.md](./docs/API%20—%20balloc.zh.md) |
|
|
305
305
|
| Spanish | [./docs/API — balloc.es.md](./docs/API%20—%20balloc.es.md) |
|
|
306
306
|
| English | [./docs/API — balloc.en.md](./docs/API%20—%20balloc.en.md) |
|
|
307
|
-
| Japanese | [./docs/API — balloc.
|
|
307
|
+
| Japanese | [./docs/API — balloc.jp.md](./docs/API%20—%20balloc.jp.md) |
|
|
308
308
|
| Portuguese | [./docs/API — balloc.pt.md](./docs/API%20—%20balloc.pt.md) |
|
|
309
309
|
|
|
310
310
|
|
|
@@ -351,6 +351,8 @@ The following is a summary of these groups:
|
|
|
351
351
|
| API | Description |
|
|
352
352
|
| --- | --- |
|
|
353
353
|
| `has()` | Search for a value |
|
|
354
|
+
| `indexOf()` | Search for a value (first match) |
|
|
355
|
+
| `lastIndexOf()` | Search for a value (last match) |
|
|
354
356
|
| `get()` | Read an element |
|
|
355
357
|
| `set()` | Write an element |
|
|
356
358
|
| `clear()` | Clear occupancy and fill the block |
|
|
@@ -358,6 +360,7 @@ The following is a summary of these groups:
|
|
|
358
360
|
| `fillAll()` | Fill and occupy the entire block |
|
|
359
361
|
| `put()` | Copy an array into a block |
|
|
360
362
|
| `pick()` | Copy occupied elements out of a block |
|
|
363
|
+
| `withView()` | Borrow a typed view over occupied elements |
|
|
361
364
|
|
|
362
365
|
### Block interchange
|
|
363
366
|
|
|
@@ -383,12 +386,32 @@ The following is a summary of these groups:
|
|
|
383
386
|
| `byteSize()` | Physical block size in bytes |
|
|
384
387
|
| `occupied()` | Number of occupied elements |
|
|
385
388
|
| `length()` | Physical element capacity |
|
|
389
|
+
| `isFull()` | Check whether the block is completely occupied |
|
|
386
390
|
| `recycleCount()` | Number of recyclable regions |
|
|
387
391
|
| `recycleBytes` | Currently recyclable bytes |
|
|
388
392
|
| `allocatedBytes` | Bytes associated with non-recycled regions |
|
|
389
393
|
| `unallocatedBytes` | Space remaining after the bump pointer |
|
|
390
394
|
| `fragmentationRatio` | Recycled bytes / used heap area |
|
|
391
395
|
|
|
396
|
+
### Borrowing memory with `withView()`
|
|
397
|
+
|
|
398
|
+
`withView(handler, callback)` provides the callback with a `TypedArray` directly over the block's occupied region. The view is not a copy: changes made through it modify the block's contents. The callback is synchronous, receives the view as its only argument, and its return value is propagated by `withView()`.
|
|
399
|
+
|
|
400
|
+
The view must not be retained or used after the callback finishes. If the callback returns a Promise, the borrow is released immediately when that Promise is returned; it is not held until the Promise settles. The lock is also released if the callback throws.
|
|
401
|
+
|
|
402
|
+
While a block is borrowed, operations that directly modify it are blocked, including `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `free()`, and copy operations that use it as the destination. `swap()` is also blocked if either block is borrowed. Read operations and operations that use the block only as a source remain allowed.
|
|
403
|
+
|
|
404
|
+
Operations that replace or remap `dataBus`, such as `gc()` and bus growth triggered by `alloc()` or `realloc()`, are blocked while any view is active.
|
|
405
|
+
|
|
406
|
+
Example:
|
|
407
|
+
|
|
408
|
+
```js
|
|
409
|
+
const result = memory.withView(handler, view => {
|
|
410
|
+
view[0] = 42;
|
|
411
|
+
return view.length;
|
|
412
|
+
});
|
|
413
|
+
```
|
|
414
|
+
|
|
392
415
|
### Internal functions
|
|
393
416
|
|
|
394
417
|
These are a special class of API primarily used internally by the allocator and generally not recommended for day-to-day code, as they may cause undocumented side effects. They are intended for library extensions and modifications where a thorough understanding of the Balloc source code is essential.
|
|
@@ -426,7 +449,7 @@ If you like this project and want to support its development:
|
|
|
426
449
|
|
|
427
450
|
| Pix QR Code | Copy-and-Paste / Random Key |
|
|
428
451
|
| :---: | :--- |
|
|
429
|
-
|  | **Random Key:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
430
453
|
|
|
431
454
|
## License
|
|
432
455
|
|
package/README.es.md
CHANGED
|
@@ -278,7 +278,7 @@ La documentación completa de la API está disponible en la carpeta [`./docs`](.
|
|
|
278
278
|
| Chino | [./docs/API — balloc.zh.md](./docs/API%20—%20balloc.zh.md) |
|
|
279
279
|
| Español | [./docs/API — balloc.es.md](./docs/API%20—%20balloc.es.md) |
|
|
280
280
|
| Inglés | [./docs/API — balloc.en.md](./docs/API%20—%20balloc.en.md) |
|
|
281
|
-
| Japonés | [./docs/API — balloc.
|
|
281
|
+
| Japonés | [./docs/API — balloc.jp.md](./docs/API%20—%20balloc.jp.md) |
|
|
282
282
|
| Portugués | [./docs/API — balloc.pt.md](./docs/API%20—%20balloc.pt.md) |
|
|
283
283
|
|
|
284
284
|
Los métodos de la API están agrupados por afinidad:
|
|
@@ -324,6 +324,8 @@ A continuación, un resumen de estos grupos:
|
|
|
324
324
|
| API | Descripción |
|
|
325
325
|
| --- | --- |
|
|
326
326
|
| `has()` | Buscar un valor |
|
|
327
|
+
| `indexOf()` | Buscar la primera aparición de un valor |
|
|
328
|
+
| `lastIndexOf()` | Buscar la última aparición de un valor |
|
|
327
329
|
| `get()` | Leer un elemento |
|
|
328
330
|
| `set()` | Escribir un elemento |
|
|
329
331
|
| `clear()` | Limpiar la ocupación y resetear el bloque |
|
|
@@ -331,6 +333,7 @@ A continuación, un resumen de estos grupos:
|
|
|
331
333
|
| `fillAll()` | Rellenar y ocupar todo el bloque |
|
|
332
334
|
| `put()` | Copiar un array a un bloque |
|
|
333
335
|
| `pick()` | Copiar elementos ocupados fuera de un bloque |
|
|
336
|
+
| `withView()` | Tomar prestada una vista tipada de los elementos ocupados |
|
|
334
337
|
|
|
335
338
|
### Intercambio entre bloques
|
|
336
339
|
|
|
@@ -356,12 +359,32 @@ A continuación, un resumen de estos grupos:
|
|
|
356
359
|
| `byteSize()` | Tamaño físico del bloque en bytes |
|
|
357
360
|
| `occupied()` | Recuento de elementos ocupados |
|
|
358
361
|
| `length()` | Capacidad física de elementos |
|
|
362
|
+
| `isFull()` | Comprobar si el bloque está completamente ocupado |
|
|
359
363
|
| `recycleCount()` | Número de regiones reciclables |
|
|
360
364
|
| `recycleBytes` | Bytes actualmente reciclables |
|
|
361
365
|
| `allocatedBytes` | Bytes asociados a regiones no recicladas |
|
|
362
366
|
| `unallocatedBytes` | Espacio restante tras el puntero de bump |
|
|
363
367
|
| `fragmentationRatio` | Bytes reciclados / área de heap usada |
|
|
364
368
|
|
|
369
|
+
### Préstamo de memoria con `withView()`
|
|
370
|
+
|
|
371
|
+
`withView(handler, callback)` proporciona al callback una `TypedArray` directamente sobre la región ocupada del bloque. La vista no es una copia: los cambios realizados en ella modifican el contenido del bloque. El callback es síncrono, recibe la vista como único argumento y su valor de retorno se propaga mediante `withView()`.
|
|
372
|
+
|
|
373
|
+
La vista no debe conservarse ni utilizarse después de que termine el callback. Si el callback devuelve una Promise, el préstamo se libera inmediatamente al devolverla, sin esperar a que se resuelva. El bloqueo también se libera si el callback lanza una excepción.
|
|
374
|
+
|
|
375
|
+
Mientras un bloque esté prestado, se bloquean las operaciones que lo modifican directamente, incluidas `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `free()` y las operaciones de copia que lo utilizan como destino. `swap()` también se bloquea si cualquiera de los dos bloques está prestado. Las lecturas y las operaciones que utilizan el bloque únicamente como origen siguen permitidas.
|
|
376
|
+
|
|
377
|
+
Las operaciones que sustituyen o reasignan `dataBus`, como `gc()` y el crecimiento del bus provocado por `alloc()` o `realloc()`, se bloquean mientras haya alguna vista activa.
|
|
378
|
+
|
|
379
|
+
Ejemplo:
|
|
380
|
+
|
|
381
|
+
```js
|
|
382
|
+
const result = memory.withView(handler, view => {
|
|
383
|
+
view[0] = 42;
|
|
384
|
+
return view.length;
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
365
388
|
### Funciones internas
|
|
366
389
|
|
|
367
390
|
Son un caso especial de API utilizada primariamente dentro del propio asignador y normalmente no se recomiendan para el uso diario, ya que pueden causar efectos secundarios no documentados. Su uso está destinado a extensiones y modificaciones de la biblioteca donde sea fundamental la comprensión total del código fuente de Balloc.
|
|
@@ -398,7 +421,7 @@ Si te gusta este proyecto y quieres apoyar su desarrollo:
|
|
|
398
421
|
|
|
399
422
|
| QR Code Pix | Clave Copia y Pega / Aleatoria |
|
|
400
423
|
| :---: | :--- |
|
|
401
|
-
|  | **Clave Aleatoria:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
402
425
|
|
|
403
426
|
## Licencia
|
|
404
427
|
|
package/README.jp.md
CHANGED
|
@@ -277,7 +277,7 @@ APIの完全なドキュメントは[`./docs`](./docs)フォルダーにあり
|
|
|
277
277
|
| 中国語 | [./docs/API — balloc.zh.md](./docs/API%20—%20balloc.zh.md) |
|
|
278
278
|
| スペイン語 | [./docs/API — balloc.es.md](./docs/API%20—%20balloc.es.md) |
|
|
279
279
|
| 英語 | [./docs/API — balloc.en.md](./docs/API%20—%20balloc.en.md) |
|
|
280
|
-
| 日本語 | [./docs/API — balloc.
|
|
280
|
+
| 日本語 | [./docs/API — balloc.jp.md](./docs/API%20—%20balloc.jp.md) |
|
|
281
281
|
| ポルトガル語 | [./docs/API — balloc.pt.md](./docs/API%20—%20balloc.pt.md) |
|
|
282
282
|
|
|
283
283
|
APIメソッドは機能ごとに次のグループに分類されています。
|
|
@@ -323,6 +323,8 @@ APIメソッドは機能ごとに次のグループに分類されています
|
|
|
323
323
|
| API | 説明 |
|
|
324
324
|
|---|---|
|
|
325
325
|
| `has()` | 値を検索する |
|
|
326
|
+
| `indexOf()` | 値が最初に現れる位置を検索する |
|
|
327
|
+
| `lastIndexOf()` | 値が最後に現れる位置を検索する |
|
|
326
328
|
| `get()` | 要素を読み取る |
|
|
327
329
|
| `set()` | 要素を書き込む |
|
|
328
330
|
| `clear()` | 使用状態をクリアし、ブロックを値で埋める |
|
|
@@ -330,6 +332,7 @@ APIメソッドは機能ごとに次のグループに分類されています
|
|
|
330
332
|
| `fillAll()` | ブロック全体を埋め、すべての要素を使用済みにする |
|
|
331
333
|
| `put()` | 配列をブロックにコピーする |
|
|
332
334
|
| `pick()` | 使用中の要素をブロックから外部へコピーする |
|
|
335
|
+
| `withView()` | 使用中の要素に対応する型付きビューを借用する |
|
|
333
336
|
|
|
334
337
|
### ブロック間のデータ交換
|
|
335
338
|
|
|
@@ -355,12 +358,32 @@ APIメソッドは機能ごとに次のグループに分類されています
|
|
|
355
358
|
| `byteSize()` | ブロックの物理サイズをバイト単位で返す |
|
|
356
359
|
| `occupied()` | 使用中の要素数を返す |
|
|
357
360
|
| `length()` | 物理容量(要素数)を返す |
|
|
361
|
+
| `isFull()` | ブロックが完全に使用中か確認する |
|
|
358
362
|
| `recycleCount()` | 再利用可能な領域の数を返す |
|
|
359
363
|
| `recycleBytes` | 現在再利用可能なバイト数 |
|
|
360
364
|
| `allocatedBytes` | 再利用対象ではない領域に割り当てられているバイト数 |
|
|
361
365
|
| `unallocatedBytes` | バンプポインター以降の残り領域のバイト数 |
|
|
362
366
|
| `fragmentationRatio` | 再利用済みバイト数/使用中ヒープ領域 |
|
|
363
367
|
|
|
368
|
+
### `withView()` によるメモリの借用
|
|
369
|
+
|
|
370
|
+
`withView(handler, callback)` は、ブロックの使用中領域に直接対応する `TypedArray` をコールバックに渡します。このビューはコピーではありません。ビューを通じて行った変更はブロックの内容に反映されます。コールバックは同期的に実行され、唯一の引数としてビューを受け取り、その戻り値は `withView()` から返されます。
|
|
371
|
+
|
|
372
|
+
コールバックの終了後にビューを保持したり使用したりしてはいけません。コールバックがPromiseを返した場合、借用はPromiseの解決を待たず、そのPromiseが返された時点で終了します。コールバックが例外を送出した場合もロックは解除されます。
|
|
373
|
+
|
|
374
|
+
ブロックの借用中は、そのブロックを直接変更する操作が禁止されます。対象には `push()`、`pop()`、`nudge()`、`pull()`、`set()`、`clear()`、`fill()`、`fillAll()`、`put()`、`realloc()`、`free()`、および借用中のブロックをコピー先とする操作が含まれます。いずれかのブロックが借用中の場合、`swap()` も禁止されます。読み取り操作と、ブロックをコピー元としてのみ使用する操作は引き続き許可されます。
|
|
375
|
+
|
|
376
|
+
アクティブなビューが存在する間は、`gc()` や `alloc()`/`realloc()` によるバスの拡張など、`dataBus` を置き換えたり再マッピングしたりする操作も禁止されます。
|
|
377
|
+
|
|
378
|
+
例:
|
|
379
|
+
|
|
380
|
+
```js
|
|
381
|
+
const result = memory.withView(handler, view => {
|
|
382
|
+
view[0] = 42;
|
|
383
|
+
return view.length;
|
|
384
|
+
});
|
|
385
|
+
```
|
|
386
|
+
|
|
364
387
|
### 内部関数
|
|
365
388
|
|
|
366
389
|
内部関数は、主にアロケータ内部で使用される特殊なAPIです。未記載の副作用が生じる可能性があるため、日常的なコードでの使用は通常推奨されません。Ballocのソースコードを十分に理解したうえで行う、ライブラリの拡張や変更を目的としています。
|
|
@@ -397,7 +420,7 @@ APIメソッドは機能ごとに次のグループに分類されています
|
|
|
397
420
|
|
|
398
421
|
| Pix QRコード | コピー&ペースト用キー/ランダムキー |
|
|
399
422
|
| :---: | :--- |
|
|
400
|
-
|  | **ランダムキー:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
401
424
|
|
|
402
425
|
## ライセンス
|
|
403
426
|
|
package/README.pt.md
CHANGED
|
@@ -350,14 +350,14 @@ Segue um resumo desses agrupamentos:
|
|
|
350
350
|
|
|
351
351
|
| API | Descrição |
|
|
352
352
|
| --- | --- |
|
|
353
|
-
| `has()` |
|
|
354
|
-
| `get()` | Ler um elemento |
|
|
353
|
+
| `has()` | Verificar a existência de um valor |
|
|
354
|
+
| `indexOf()` | Localizar a primeira ocorrência de um valor |\n| `lastIndexOf()` | Localizar a última ocorrência de um valor |\n| `get()` | Ler um elemento |
|
|
355
355
|
| `set()` | Escrever um elemento |
|
|
356
356
|
| `clear()` | Limpar a ocupação e preencher o bloco |
|
|
357
357
|
| `fill()` | Preencher um intervalo |
|
|
358
358
|
| `fillAll()` | Preencher e ocupar todo o bloco |
|
|
359
359
|
| `put()` | Copiar um array para um bloco |
|
|
360
|
-
| `pick()` | Copiar elementos ocupados para fora de um bloco |
|
|
360
|
+
| `pick()` | Copiar elementos ocupados para fora de um bloco |\n| `withView()` | Emprestar uma view tipada sobre os elementos ocupados |
|
|
361
361
|
|
|
362
362
|
### Intercâmbio entre blocos
|
|
363
363
|
|
|
@@ -382,13 +382,32 @@ Segue um resumo desses agrupamentos:
|
|
|
382
382
|
| --- | --- |
|
|
383
383
|
| `byteSize()` | Tamanho físico do bloco em bytes |
|
|
384
384
|
| `occupied()` | Contagem de elementos ocupados |
|
|
385
|
-
| `length()` | Capacidade física de elementos |
|
|
385
|
+
| `length()` | Capacidade física de elementos |\n| `isFull()` | Verificar se o bloco está completamente ocupado |
|
|
386
386
|
| `recycleCount()` | Número de regiões recicláveis |
|
|
387
387
|
| `recycleBytes` | Bytes atualmente recicláveis |
|
|
388
388
|
| `allocatedBytes` | Bytes associados a regiões não recicladas |
|
|
389
389
|
| `unallocatedBytes` | Espaço restante após o ponteiro do bump |
|
|
390
390
|
| `fragmentationRatio` | Bytes reciclados / área de heap usada |
|
|
391
391
|
|
|
392
|
+
### Empréstimo de memória com `withView()`
|
|
393
|
+
|
|
394
|
+
`withView(handler, callback)` fornece ao callback uma `TypedArray` diretamente sobre a região ocupada do bloco. A view não é uma cópia: alterações feitas nela modificam o conteúdo do bloco. O callback é síncrono, recebe a view como único argumento e seu valor de retorno é propagado por `withView()`.
|
|
395
|
+
|
|
396
|
+
A view não deve ser retida nem utilizada após o término do callback. Se o callback retornar uma Promise, o empréstimo será liberado imediatamente após o retorno da Promise, sem aguardar sua resolução. O bloqueio é liberado mesmo quando o callback lança uma exceção.
|
|
397
|
+
|
|
398
|
+
Enquanto o bloco estiver emprestado, operações que o modificam diretamente — incluindo `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `free()` e operações de cópia que o tenham como destino — são bloqueadas. `swap()` também é bloqueado se qualquer dos blocos estiver emprestado. Leituras e operações que utilizam o bloco apenas como origem permanecem permitidas.
|
|
399
|
+
|
|
400
|
+
Operações que substituem ou remapeiam o `dataBus`, como `gc()` e o crescimento do barramento por `alloc()` ou `realloc()`, são bloqueadas enquanto existir qualquer view ativa.
|
|
401
|
+
|
|
402
|
+
Exemplo:
|
|
403
|
+
|
|
404
|
+
```js
|
|
405
|
+
const result = memory.withView(handler, view => {
|
|
406
|
+
view[0] = 42;
|
|
407
|
+
return view.length;
|
|
408
|
+
});
|
|
409
|
+
```
|
|
410
|
+
|
|
392
411
|
### Funções internas
|
|
393
412
|
|
|
394
413
|
São um caso especial de API utilizada primariamente dentro do próprio alocador e normalmente não recomendadas para uso no código do dia a dia, pois podem causar efeitos colaterais não documentados. Seu uso destina-se a extensões e modificações da biblioteca onde é fundamental o entendimento e a compreensão total do código-fonte de Balloc.
|
|
@@ -426,7 +445,7 @@ Se você gosta deste projeto e quer apoiar o seu desenvolvimento:
|
|
|
426
445
|
|
|
427
446
|
| QR Code Pix | Chave Copia e Cola / Aleatória |
|
|
428
447
|
| :---: | :--- |
|
|
429
|
-
|  | **Chave Aleatória:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
430
449
|
|
|
431
450
|
## Licença
|
|
432
451
|
|
package/README.zh.md
CHANGED
|
@@ -277,7 +277,7 @@ Balloc 提供以下几种数据访问模型:
|
|
|
277
277
|
| 中文 | [./docs/API — balloc.zh.md](./docs/API%20—%20balloc.zh.md) |
|
|
278
278
|
| 西班牙语 | [./docs/API — balloc.es.md](./docs/API%20—%20balloc.es.md) |
|
|
279
279
|
| 英语 | [./docs/API — balloc.en.md](./docs/API%20—%20balloc.en.md) |
|
|
280
|
-
| 日语 | [./docs/API — balloc.
|
|
280
|
+
| 日语 | [./docs/API — balloc.jp.md](./docs/API%20—%20balloc.jp.md) |
|
|
281
281
|
| 葡萄牙语 | [./docs/API — balloc.pt.md](./docs/API%20—%20balloc.pt.md) |
|
|
282
282
|
|
|
283
283
|
API 方法按功能归为以下类别:
|
|
@@ -323,6 +323,8 @@ API 方法按功能归为以下类别:
|
|
|
323
323
|
| API | 说明 |
|
|
324
324
|
|---|---|
|
|
325
325
|
| `has()` | 搜索指定值 |
|
|
326
|
+
| `indexOf()` | 查找值首次出现的位置 |
|
|
327
|
+
| `lastIndexOf()` | 查找值最后一次出现的位置 |
|
|
326
328
|
| `get()` | 读取元素 |
|
|
327
329
|
| `set()` | 写入元素 |
|
|
328
330
|
| `clear()` | 清除占用状态并填充数据块 |
|
|
@@ -330,6 +332,7 @@ API 方法按功能归为以下类别:
|
|
|
330
332
|
| `fillAll()` | 填充整个数据块并将其全部标记为已占用 |
|
|
331
333
|
| `put()` | 将数组复制到数据块 |
|
|
332
334
|
| `pick()` | 将已占用的元素复制出数据块 |
|
|
335
|
+
| `withView()` | 借用覆盖已占用元素的类型化视图 |
|
|
333
336
|
|
|
334
337
|
### 数据块间交换
|
|
335
338
|
|
|
@@ -355,12 +358,32 @@ API 方法按功能归为以下类别:
|
|
|
355
358
|
| `byteSize()` | 返回数据块的物理大小,单位为字节 |
|
|
356
359
|
| `occupied()` | 返回已占用的元素数量 |
|
|
357
360
|
| `length()` | 返回物理容量(元素数量) |
|
|
361
|
+
| `isFull()` | 检查数据块是否已完全占用 |
|
|
358
362
|
| `recycleCount()` | 返回可回收区域的数量 |
|
|
359
363
|
| `recycleBytes` | 当前可回收的字节数 |
|
|
360
364
|
| `allocatedBytes` | 已分配给非回收区域的字节数 |
|
|
361
365
|
| `unallocatedBytes` | bump 指针之后的剩余空间 |
|
|
362
366
|
| `fragmentationRatio` | 可回收字节数/已使用堆区域 |
|
|
363
367
|
|
|
368
|
+
### 使用 `withView()` 借用内存
|
|
369
|
+
|
|
370
|
+
`withView(handler, callback)` 会向回调函数提供一个直接映射到数据块已占用区域的 `TypedArray`。该视图不是副本:通过它进行的修改会直接改变数据块内容。回调同步执行,只接收该视图作为唯一参数;回调的返回值会由 `withView()` 原样返回。
|
|
371
|
+
|
|
372
|
+
回调结束后,不得保留或继续使用该视图。如果回调返回 Promise,借用会在 Promise 被返回时立即结束,不会等待 Promise 完成。即使回调抛出异常,锁也会被释放。
|
|
373
|
+
|
|
374
|
+
数据块处于借用状态时,所有直接修改该数据块的操作都会被阻止,包括 `push()`、`pop()`、`nudge()`、`pull()`、`set()`、`clear()`、`fill()`、`fillAll()`、`put()`、`realloc()`、`free()`,以及将该数据块作为目标的复制操作。如果任一数据块处于借用状态,`swap()` 也会被阻止。读取操作以及仅将该数据块用作源的操作仍可执行。
|
|
375
|
+
|
|
376
|
+
只要存在活动视图,就会阻止替换或重新映射 `dataBus` 的操作,例如 `gc()`,以及由 `alloc()` 或 `realloc()` 触发的总线扩容。
|
|
377
|
+
|
|
378
|
+
示例:
|
|
379
|
+
|
|
380
|
+
```js
|
|
381
|
+
const result = memory.withView(handler, view => {
|
|
382
|
+
view[0] = 42;
|
|
383
|
+
return view.length;
|
|
384
|
+
});
|
|
385
|
+
```
|
|
386
|
+
|
|
364
387
|
### 内部函数
|
|
365
388
|
|
|
366
389
|
内部函数属于特殊 API,主要供分配器内部使用。由于可能产生未文档化的副作用,通常不建议在日常业务代码中调用。它们面向对 Balloc 源码有充分理解、需要扩展或修改库的开发者。
|
|
@@ -397,7 +420,7 @@ API 方法按功能归为以下类别:
|
|
|
397
420
|
|
|
398
421
|
| Pix 二维码 | 复制粘贴密钥/随机密钥 |
|
|
399
422
|
| :---: | :--- |
|
|
400
|
-
|  | **随机密钥:**<br>`e87d773a-0b97-4410-8fc3-f7ec04cce6a2` |
|
|
401
424
|
|
|
402
425
|
## 许可证
|
|
403
426
|
|
package/change.log.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# version 1.2
|
|
2
|
+
- Fix duplicate memory allocation in constructor - https://github.com/AugustoVasques75/balloc/issues/4
|
|
3
|
+
- Add `indexOf()` method - https://github.com/AugustoVasques75/balloc/issues/1
|
|
4
|
+
- Add `lastIndexOf()` method
|
|
5
|
+
- Add method isFull() - https://github.com/AugustoVasques75/balloc/issues/2
|
|
6
|
+
- Typo correction
|
|
7
|
+
- Add `withView()` method to address the Direct Mutable Access to Allocation Storage issue: https://github.com/AugustoVasques75/balloc/issues/3
|
|
@@ -120,6 +120,29 @@ byteSize(handler) → bytes físicos reservados
|
|
|
120
120
|
|
|
121
121
|
---
|
|
122
122
|
|
|
123
|
+
## استعارة الذاكرة باستخدام `withView()`
|
|
124
|
+
|
|
125
|
+
تمرر `withView(handler, callback)` إلى الدالة الراجعة عرضًا typed view مرتبطًا مباشرة بمنطقة البيانات المشغولة في الكتلة. يشمل العرض العناصر المشغولة فقط، ولا يشمل السعة غير المستخدمة، وليس نسخة؛ فالتغييرات التي تُجرى من خلاله تعدّل محتوى الكتلة مباشرة.
|
|
126
|
+
|
|
127
|
+
تتم الاستعارة بصورة متزامنة. تتلقى الدالة الراجعة العرض بوصفه وسيطها الوحيد، وتُعاد القيمة التي تنتجها من `withView()`. يُحرر القفل داخل كتلة `finally`، حتى إذا أطلقت الدالة الراجعة استثناءً.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
const result = memory.withView(handler, view => {
|
|
131
|
+
view[0] = 42;
|
|
132
|
+
return view.length;
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
يجب عدم الاحتفاظ بالعرض أو استخدامه بعد انتهاء الدالة الراجعة. إذا أعادت الدالة Promise، تنتهي الاستعارة فور إعادة الـPromise، ولا يستمر القفل حتى اكتمالها.
|
|
137
|
+
|
|
138
|
+
### القيود أثناء الاستعارة
|
|
139
|
+
|
|
140
|
+
تؤدي محاولة استدعاء `withView()` مرة ثانية للمقبض نفسه إلى إطلاق `Error`. كما تطلق العمليات التالية `Error` إذا كانت ستعدّل الكتلة المستعارة: `push()` و`pop()` و`nudge()` و`pull()` و`set()` و`clear()` و`fill()` و`fillAll()` و`put()` و`realloc()` و`free()` و`copyWithin()`. تُحظر `copy()` و`append()` عندما تكون الكتلة المستعارة هي الوجهة، كما تُحظر `swap()` إذا كانت أي من الكتلتين مستعارة.
|
|
141
|
+
|
|
142
|
+
لا تُحظر عمليات القراءة. وفي `copy()` و`append()`، يمكن أن تكون كتلة المصدر مستعارة لأن هاتين العمليتين لا تعدّلان المصدر.
|
|
143
|
+
|
|
144
|
+
تُحظر أيضًا العمليات التي تستبدل `dataBus` أو تعيد تعيين موضعه ما دامت أي مصفوفة نشطة، بما في ذلك `gc()` وتوسعة `dataBus` الناتجة عن `alloc()` أو `realloc()`.
|
|
145
|
+
|
|
123
146
|
# 1. التهيئة (Instantiation)
|
|
124
147
|
|
|
125
148
|
## `new Balloc(size, bucketSize, metadataSize)`
|
|
@@ -535,6 +558,14 @@ boolean
|
|
|
535
558
|
|
|
536
559
|
---
|
|
537
560
|
|
|
561
|
+
## `indexOf(handler, searchElement, fromIndex = 0)`
|
|
562
|
+
|
|
563
|
+
البحث عن أول ظهور لقيمة. The search proceeds in ascending index order and considers only occupied elements, ignoring unused block capacity.
|
|
564
|
+
|
|
565
|
+
## `lastIndexOf(handler, searchElement, fromIndex = -1)`
|
|
566
|
+
|
|
567
|
+
البحث عن آخر ظهور لقيمة. The search proceeds in descending index order and considers only occupied elements, ignoring unused block capacity.
|
|
568
|
+
|
|
538
569
|
## `get(handler, index)`
|
|
539
570
|
|
|
540
571
|
يحصل على العنصر في الفهرس المحدد.
|
|
@@ -750,6 +781,11 @@ const count = memory.occupied(handler);
|
|
|
750
781
|
|
|
751
782
|
## `length(handler)`
|
|
752
783
|
|
|
784
|
+
### `isFull(handler)`
|
|
785
|
+
|
|
786
|
+
التحقق مما إذا كانت الكتلة مشغولة بالكامل. تعيد `true` عندما يساوي عدد العناصر المشغولة السعة الفيزيائية للكتلة؛ وإلا فتعيد `false`.
|
|
787
|
+
|
|
788
|
+
|
|
753
789
|
يرجع الكمية الإجمالية للفتحات الفيزيائية المتاحة.
|
|
754
790
|
|
|
755
791
|
السعة مستقلة عن الإشغال:
|
|
@@ -126,6 +126,29 @@ byteSize(handler) → reserved physical bytes
|
|
|
126
126
|
|
|
127
127
|
---
|
|
128
128
|
|
|
129
|
+
## Memory borrowing with `withView()`
|
|
130
|
+
|
|
131
|
+
`withView(handler, callback)` passes the callback a typed view directly over the block's occupied data region. The view covers only occupied elements, excludes unused capacity, and is not a copy: changes made through it immediately modify the block's contents.
|
|
132
|
+
|
|
133
|
+
The borrow is synchronous. The callback receives the view as its only argument, and its return value is propagated by `withView()`. The lock is released in a `finally` block, including when the callback throws.
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
const result = memory.withView(handler, view => {
|
|
137
|
+
view[0] = 42;
|
|
138
|
+
return view.length;
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Do not retain or use the view after the callback finishes. If the callback returns a Promise, the borrow ends as soon as the Promise is returned; it is not held until the Promise settles.
|
|
143
|
+
|
|
144
|
+
### Restrictions during a borrow
|
|
145
|
+
|
|
146
|
+
A second `withView()` call for the same handler throws `Error`. The following operations also throw `Error` when they would modify the borrowed block: `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `free()`, and `copyWithin()`. `copy()` and `append()` are blocked when the borrowed block is the destination. `swap()` is blocked when either block is borrowed.
|
|
147
|
+
|
|
148
|
+
Read operations are not blocked. In `copy()` and `append()`, the source block may be borrowed because these operations do not modify it.
|
|
149
|
+
|
|
150
|
+
Operations that replace or remap `dataBus` are also blocked while any view is active. This includes `gc()` and `dataBus` growth triggered by `alloc()` or `realloc()`.
|
|
151
|
+
|
|
129
152
|
# 1. Instantiation
|
|
130
153
|
|
|
131
154
|
## `new Balloc(size, bucketSize, metadataSize)`
|
|
@@ -491,6 +514,14 @@ boolean
|
|
|
491
514
|
|
|
492
515
|
---
|
|
493
516
|
|
|
517
|
+
## `indexOf(handler, searchElement, fromIndex = 0)`
|
|
518
|
+
|
|
519
|
+
Finds the first occurrence of a value, searching in ascending index order. Only occupied elements are searched; unused block capacity is ignored.
|
|
520
|
+
|
|
521
|
+
## `lastIndexOf(handler, searchElement, fromIndex = -1)`
|
|
522
|
+
|
|
523
|
+
Finds the last occurrence of a value, searching in descending index order. Only occupied elements are searched; unused block capacity is ignored.
|
|
524
|
+
|
|
494
525
|
## `get(handler, index)`
|
|
495
526
|
|
|
496
527
|
Gets the element at the specified index.
|
|
@@ -692,6 +723,11 @@ const count = memory.occupied(handler);
|
|
|
692
723
|
|
|
693
724
|
## `length(handler)`
|
|
694
725
|
|
|
726
|
+
### `isFull(handler)`
|
|
727
|
+
|
|
728
|
+
Returns `true` when the number of occupied elements equals the block's physical capacity; otherwise returns `false`.
|
|
729
|
+
|
|
730
|
+
|
|
695
731
|
Returns the total quantity of available physical slots.
|
|
696
732
|
|
|
697
733
|
Capacity is independent of occupancy:
|
|
@@ -122,6 +122,29 @@ byteSize(handler) → bytes físicos reservados
|
|
|
122
122
|
|
|
123
123
|
---
|
|
124
124
|
|
|
125
|
+
## Préstamo de memoria con `withView()`
|
|
126
|
+
|
|
127
|
+
`withView(handler, callback)` entrega al callback una vista tipada directamente sobre la región de datos ocupada del bloque. La vista incluye únicamente los elementos ocupados, excluye la capacidad libre y no es una copia: los cambios realizados en ella modifican inmediatamente el contenido del bloque.
|
|
128
|
+
|
|
129
|
+
El préstamo es síncrono. El callback recibe la vista como único argumento y su valor de retorno se propaga mediante `withView()`. El bloqueo se libera dentro de un bloque `finally`, incluso si el callback lanza una excepción.
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
const result = memory.withView(handler, view => {
|
|
133
|
+
view[0] = 42;
|
|
134
|
+
return view.length;
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
No se debe conservar ni utilizar la vista después de que termine el callback. Si el callback devuelve una Promise, el préstamo termina en cuanto se devuelve la Promise, sin esperar a que se resuelva.
|
|
139
|
+
|
|
140
|
+
### Restricciones durante el préstamo
|
|
141
|
+
|
|
142
|
+
Una segunda llamada a `withView()` para el mismo handler lanza `Error`. También lanzan `Error` las operaciones que modificarían el bloque prestado: `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `free()` y `copyWithin()`. `copy()` y `append()` se bloquean cuando el bloque prestado es el destino. `swap()` se bloquea si cualquiera de los dos bloques está prestado.
|
|
143
|
+
|
|
144
|
+
Las operaciones de lectura no se bloquean. En `copy()` y `append()`, el bloque de origen puede estar prestado porque estas operaciones no lo modifican.
|
|
145
|
+
|
|
146
|
+
Las operaciones que sustituyen o reasignan `dataBus` también se bloquean mientras haya alguna vista activa. Esto incluye `gc()` y el crecimiento de `dataBus` provocado por `alloc()` o `realloc()`.
|
|
147
|
+
|
|
125
148
|
# 1. Instanciación
|
|
126
149
|
|
|
127
150
|
## `new Balloc(size, bucketSize, metadataSize)`
|
|
@@ -465,6 +488,14 @@ boolean
|
|
|
465
488
|
|
|
466
489
|
---
|
|
467
490
|
|
|
491
|
+
## `indexOf(handler, searchElement, fromIndex = 0)`
|
|
492
|
+
|
|
493
|
+
Buscar la primera aparición de un valor. The search proceeds in ascending index order and considers only occupied elements, ignoring unused block capacity.
|
|
494
|
+
|
|
495
|
+
## `lastIndexOf(handler, searchElement, fromIndex = -1)`
|
|
496
|
+
|
|
497
|
+
Buscar la última aparición de un valor. The search proceeds in descending index order and considers only occupied elements, ignoring unused block capacity.
|
|
498
|
+
|
|
468
499
|
## `get(handler, index)`
|
|
469
500
|
|
|
470
501
|
Obtiene el elemento situado en el índice especificado.
|
|
@@ -649,6 +680,11 @@ const count = memory.occupied(handler);
|
|
|
649
680
|
|
|
650
681
|
## `length(handler)`
|
|
651
682
|
|
|
683
|
+
### `isFull(handler)`
|
|
684
|
+
|
|
685
|
+
Comprobar si el bloque está completamente ocupado. Devuelve `true` cuando el número de elementos ocupados coincide con la capacidad física del bloque; en caso contrario, devuelve `false`.
|
|
686
|
+
|
|
687
|
+
|
|
652
688
|
Devuelve el número total de slots físicos disponibles.
|
|
653
689
|
|
|
654
690
|
La capacidad es independiente de la ocupación:
|