MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / allocateBatch

Method allocateBatch

src/jrd/TempSpace.cpp:727–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

725//
726
727ULONG TempSpace::allocateBatch(ULONG count, FB_SIZE_T minSize, FB_SIZE_T maxSize, Segments& segments)
728{
729 // adjust passed chunk size to amount of free memory we have and number
730 // of runs still not allocated.
731 offset_t freeMem = 0;
732
733 for (bool found = freeSegments.getFirst(); found; found = freeSegments.getNext())
734 freeMem += freeSegments.current()->size;
735
736 freeMem = MIN(freeMem / count, maxSize);
737 freeMem = MAX(freeMem, minSize);
738 freeMem = MIN(freeMem, minBlockSize);
739 freeMem &= ~(FB_ALIGNMENT - 1);
740
741 bool is_positioned = freeSegments.getFirst();
742 while (segments.getCount() < count && is_positioned)
743 {
744 Segment* freeSpace = freeSegments.current();
745 offset_t freeSeek = freeSpace->position;
746 const offset_t freeEnd = freeSpace->position + freeSpace->size;
747
748 UCHAR* const mem = findMemory(freeSeek, freeEnd, freeMem);
749
750 if (mem)
751 {
752 fb_assert(freeSeek + freeMem <= freeEnd);
753#ifdef DEV_BUILD
754 offset_t seek1 = freeSeek;
755 UCHAR* const p = findMemory(seek1, freeEnd, freeMem);
756 fb_assert(p == mem);
757 fb_assert(seek1 == freeSeek);
758#endif
759 freeSegmentsBySize.removeSegment(freeSpace);
760
761 if (freeSeek != freeSpace->position)
762 {
763 const offset_t skip_size = freeSeek - freeSpace->position;
764 Segment* const skip_space = FB_NEW_POOL(pool) Segment(freeSpace->position, skip_size);
765
766 freeSpace->position += skip_size;
767 freeSpace->size -= skip_size;
768 fb_assert(freeSpace->size != 0);
769
770 if (!freeSegments.add(skip_space))
771 fb_assert(false);
772 freeSegmentsBySize.addSegment(skip_space);
773
774 if (!freeSegments.locate(freeSpace->position))
775 fb_assert(false);
776
777 freeSpace = freeSegments.current();
778 }
779
780 SegmentInMemory seg;
781 seg.memory = mem;
782 seg.position = freeSeek;
783 seg.size = freeMem;
784 segments.add(seg);

Callers 1

allocateMethod · 0.80

Calls 10

removeSegmentMethod · 0.80
addSegmentMethod · 0.80
SegmentClass · 0.70
getFirstMethod · 0.45
getNextMethod · 0.45
currentMethod · 0.45
getCountMethod · 0.45
addMethod · 0.45
locateMethod · 0.45
fastRemoveMethod · 0.45

Tested by

no test coverage detected