A method, device, and system are disclosed. In one embodiment, the method
comprises receiving a code segment to be inserted into a flash memory
storing code segments, selecting one or more contiguous code segments in
flash memory with a total size equal to or larger than the received code
segment, calculating the amount of data movement necessary for the one or
more selected contiguous code segments, and if the amount is minimum,
moving the one or more selected contiguous code segments and replacing
them with the received code segment.