Skip to question
ASIC.FYI
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
ASIC.FYI/Interview questions/Implement best-fit allocation

Q290·Free·SystemVerilog

Implement best-fit allocation

Difficulty
Medium
Topic
Memory Systems
Language
SV
Interview prompt

Question

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.
Starting point

Question code

function bit alloc_best_fit(
  int unsigned size,
  output int unsigned addr
);
Reviewed example

Trace one case

Input
free capacities=[64,24,40]; request size=20
Expected output
select the 24-byte range; leave a 4-byte remainder

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

What to cover

Requirements

  1. Inspect all sufficient ranges.
  2. Select the minimum sufficient capacity.
  3. Preserve exact-fit and partial-fit behavior.
  4. Avoid signed sentinels for unsigned capacities.
Exact question handoffPractice Q290

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessA Free account unlocks the complete reviewed solution.
Continue learning

SystemVerilog

  • Memory Systems
  • Allocator
  • Best fit
  • Selection policy
Interview preparation guide →
Continue practicing

Related questions

Q212 · Memory SystemsBuild a first-fit range allocator→Q276 · Memory SystemsRandomize free-range allocation→Q291 · Memory SystemsReject invalid deallocation→
ASIC.FYI · Learn silicon end to end.info@asic.fyi