MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxGrowChunks

Function fxGrowChunks

xs/sources/xsMemory.c:619–661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617}
618
619void* fxGrowChunks(txMachine* the, txSize size)
620{
621 txByte* buffer;
622 txBlock* block = C_NULL;
623
624 if (!the->minimumChunksSize && the->firstBlock) {
625 fxReport(the, "# Chunk allocation: %d bytes failed in fixed size heap\n", size);
626 fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
627 }
628
629 if ((the->firstBlock != C_NULL) && (!(the->collectFlag & XS_SKIPPED_COLLECT_FLAG))) {
630 txSize modulo = size % (the->minimumChunksSize ? the->minimumChunksSize : 16);
631 if (modulo)
632 size = fxAddChunkSizes(the, size, the->minimumChunksSize - modulo);
633 }
634 size = fxAddChunkSizes(the, size, sizeof(txBlock));
635 buffer = fxAllocateChunks(the, size);
636 if (buffer) {
637 #ifdef mxSnapshot
638 c_memset(buffer, 0, size);
639 #endif
640 if ((the->firstBlock != C_NULL) && (the->firstBlock->limit == buffer)) {
641 the->firstBlock->limit += size;
642 block = the->firstBlock;
643 }
644 else {
645 block = (txBlock*)buffer;
646 block->nextBlock = the->firstBlock;
647 block->current = buffer + sizeof(txBlock);
648 block->limit = buffer + size;
649 block->temporary = C_NULL;
650 the->firstBlock = block;
651 size -= sizeof(txBlock);
652 }
653 the->maximumChunksSize = fxAddChunkSizes(the, the->maximumChunksSize, size);
654 #if mxReport
655 fxReport(the, "# Chunk allocation: reserved %ld used %ld peak %ld bytes\n",
656 (long)the->maximumChunksSize, (long)the->currentChunksSize, (long)the->peakChunksSize);
657 #endif
658 }
659 the->collectFlag &= ~XS_TRASHING_CHUNKS_FLAG;
660 return block;
661}
662
663void fxGrowKeys(txMachine* the, txID theCount)
664{

Callers 2

fxAllocateFunction · 0.85
fxGrowChunkFunction · 0.85

Calls 2

fxAbortFunction · 0.70
fxAllocateChunksFunction · 0.70

Tested by

no test coverage detected