public void FreeAddress(int address) { // ak to bolo adresa na konci tak zmazať všetky volne adresy od konca až po platne data if (address == LastAddress - _blockSize) // LastAddress - _blockSize -> posledna pridelena adresa.. na LastAddress ešte nič nie je { var blocksToErase = 1; for (int i = _freeAddresses.Count - 1; i >= 0; i--) { var key = _freeAddresses.Items[i].Key; if (key == address - _blockSize) { address = key; ++blocksToErase; } else { break; } } _fileStream.Seek(0, SeekOrigin.Begin); _fileStream.SetLength(LastAddress - blocksToErase * _blockSize); if (blocksToErase > 1) // lebo ak je 1, tak sa tam ani nedostala { --blocksToErase; _freeAddresses.RemoveRange(_freeAddresses.Count - blocksToErase, blocksToErase); } } else { _freeAddresses.Add(address, address); } }