protected function find_free_space(array $map, $size)
{
$c = count($map);
if ($c < 1) {
return 0;
}
$_end = $this->max_size;
usort($map, array($this, 'sort_map'));
$imap = array_values($map);
$i = 0;
$eoa = $c - 1;
//end of array
if ($imap[0][0] > $size) {
return 0;
}
for (; $i < $c; $i++) {
$free_from = $imap[$i][self::map_key_fin] + 1;
if ($i == $eoa) {
$free_to = $_end;
} else {
$free_to = $imap[$i + 1][self::map_key_start] - 1;
}
if ($free_to - $free_from >= $size) {
return $free_from;
}
}
$this->ReportError('Can not find enough space in memory', __LINE__);
return false;
}