int physical_memorymgr_firstFreeAlignedBlockArray(size_t size, size_t alignment) { if (size==0) return -1; if (size==1) return physical_memorymgr_firstFreeAlignedBlock(alignment); for (uint32_t i = 0; i < physical_memorymgr_get_block_count(); i++) if (physical_memorymgr_memory_map[i] != 0xffffffff) for (int j = 0; j < 32; j++) { /* Test each bit in the dword */ int bit = 1<<j; if (!(physical_memorymgr_memory_map[i] & bit) && ((i*32 + j + 1) % alignment) == 0) { int startingBit = i*32; startingBit += bit; /* Get the free bit in the dword at index i */ uint32_t free = 0; /* Loop through each bit to see if its enough space */ for (uint32_t count = 0; count <= size; count++) { if (!IsPageInUse(startingBit+count)) free++; /* This is not in use */ if (free == size) return i*32 + j; /* free count == size needed; return index */ } } } return -1; }
int GetFillFactor(BYTE by, int itemsPerByte) { if (itemsPerByte > 1) { return by & 0x3F; // 6 low-order bits } else { if (IsPageInUse(by)) return (64-1); else return 0; } }