* Allocate space by number of bytes * @param nbytes Number of bytes. * Note: This function always allocate space that aligns to 64bit.
(nbytes: number)
| 355 | * Note: This function always allocate space that aligns to 64bit. |
| 356 | */ |
| 357 | allocRawBytes(nbytes: number): PtrOffset { |
| 358 | // always aligns to 64bit |
| 359 | nbytes = ((nbytes + 7) >> 3) << 3; |
| 360 | |
| 361 | if (this.stackTop + nbytes > this.buffer.byteLength) { |
| 362 | const newSize = Math.max( |
| 363 | this.buffer.byteLength * 2, |
| 364 | this.stackTop + nbytes |
| 365 | ); |
| 366 | const oldU8 = this.viewU8; |
| 367 | this.buffer = new ArrayBuffer(newSize); |
| 368 | this.updateViews(); |
| 369 | this.viewU8.set(oldU8); |
| 370 | if (this.basePtr != 0) { |
| 371 | this.cFreeSpace(this.basePtr); |
| 372 | } |
| 373 | this.basePtr = this.cAllocSpace(newSize); |
| 374 | } |
| 375 | const retOffset = this.stackTop; |
| 376 | this.stackTop += nbytes; |
| 377 | return retOffset; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Allocate space for pointers. |
no test coverage detected