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

Method allocateBlock

src/common/classes/alloc.cpp:1654–1687  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1652 ~FreeObjects();
1653
1654 FreeObjPtr allocateBlock(MemPool* pool, size_t from, size_t& size)
1655 {
1656 size_t full_size = size + (from ? 0 : ListBuilder::MEM_OVERHEAD);
1657 if (full_size > Limits::TOP_LIMIT)
1658 return NULL;
1659
1660 unsigned slot = Limits::getSlot(full_size, SLOT_ALLOC);
1661 full_size = Limits::getSize(slot);
1662
1663 FreeObjPtr blk = ListBuilder::getElement(&freeObjects[slot]);
1664 if (!blk && from)
1665 {
1666 for (unsigned slot1 = slot - 1; Limits::getSize(slot1) >= from; --slot1)
1667 {
1668 blk = ListBuilder::getElement(&freeObjects[slot1]);
1669 if (blk)
1670 {
1671 full_size = Limits::getSize(slot1);
1672 break;
1673 }
1674
1675 // This should not happen but try to be as safe as possible
1676 fb_assert(slot1 > 0);
1677 if (!slot1)
1678 break;
1679 }
1680 }
1681
1682 if (!blk)
1683 blk = newBlock(pool, slot);
1684
1685 size = full_size - ListBuilder::MEM_OVERHEAD;
1686 return blk;
1687 }
1688
1689 bool deallocateBlock(FreeObjPtr blk)
1690 {

Callers 1

allocateInternalMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected