Skip to the selected question
ASIC.FYI

ASIC Interview Question Bank

1,000+ hardware interview questions.Curated and reviewed by industry engineers.1,000+ hardware questions1,000+ questionsEngineer-reviewed
DescriptionQ290
Page ↗
Q290ArchFollow-up to Q212ASIC interview problem

Implement best-fit allocation

TechniquesAllocatorBest fitSelection policy
DifficultyMedium
TopicMemory Systems
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Replace first-fit with best-fit: choose the smallest free range that can satisfy the request. Explain the one-line comparison change for worst-fit.

Four free-range capacities filtered against an allocation request before best-fit selection
Best-fit chooses the smallest eligible range; the chosen result is intentionally left for the exercise.
Function headerSystemVerilog
function bit alloc_best_fit(
  int unsigned size,
  output int unsigned addr
);

Example input and output

Use this case to check your interpretation
Input
free capacities=[64,24,40]; request size=20
Output
select the 24-byte range; leave a 4-byte remainder
Explanation

All ranges are sufficient, but 24 is the smallest capacity and therefore the best fit.

02

Requirements (4)

  • Inspect all sufficient ranges.
  • Select the minimum sufficient capacity.
  • Preserve exact-fit and partial-fit behavior.
  • Avoid signed sentinels for unsigned capacities.