MCPcopy Create free account
hub / github.com/GamerHack/GamerHack.github.io / Memory

Class Memory

g2all/900/module/mem.js:432–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}*/
431
432export class Memory {
433 constructor(main, worker, obj, addr_addr) {
434 this._main = main;
435 this._worker = worker;
436 this._obj = obj;
437 this._addr_low = addr_addr.lo;
438 this._addr_high = addr_addr.hi;
439
440 main[view_m_length / 4] = 0xffffffff;
441
442 init_module(this);
443
444 const off_mvec = view_m_vector;
445 // use this to create WastefulTypedArrays to avoid a GC crash
446 const buf = new ArrayBuffer(0);
447
448 const src = new Uint8Array(buf);
449 const sset = new Uint32Array(buf);
450 const sset_p = this.addrof(sset);
451 sset_p.write64(off_mvec, this.addrof(src).add(off_mvec));
452 sset_p.write32(view_m_length, 3);
453 this._cpysrc = src;
454 this._src_setter = sset;
455
456 const dst = new Uint8Array(buf);
457 const dset = new Uint32Array(buf);
458 const dset_p = this.addrof(dset);
459 dset_p.write64(off_mvec, this.addrof(dst).add(off_mvec));
460 dset_p.write32(view_m_length, 3);
461 dset[2] = 0xffffffff;
462 this._cpydst = dst;
463 this._dst_setter = dset;
464 }
465
466 // dst and src may overlap
467 cpy(dst, src, len) {
468 if (!(isInteger(len) && 0 <= len && len <= 0xffffffff)) {
469 throw TypeError('len not a unsigned 32-bit integer');
470 }
471
472 const dvals = lohi_from_one(dst);
473 const svals = lohi_from_one(src);
474 const dset = this._dst_setter;
475 const sset = this._src_setter;
476
477 dset[0] = dvals[0];
478 dset[1] = dvals[1];
479 sset[0] = svals[0];
480 sset[1] = svals[1];
481 sset[2] = len;
482
483 this._cpydst.set(this._cpysrc);
484 }
485
486 // allocate Garbage Collector managed memory. returns [address_of_memory,
487 // backer]. backer is the JSCell that is keeping the returned memory alive,
488 // you can drop it once you have another GC object reference the address.
489 // the backer is an implementation detail. don't use it to mutate the

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected