Is flat addressing model generally superior to a segmented one? If so, why? If not, what instances would call for each over the other and why?

My understanding of memory models surrounds the IA32/x86-64 Architecture. So if you give architecture specific examples, they will be most helpful if kept relevant to that.

  • 3
    Segmented addressing was a stop-gap to be able to address more than 2^16 bytes in 16 bit software. Given that we're moving to 64 bit processors, I can't see that anyone would ever need segmented addressing again. Developing for a segmented architecture is a royal pain. The answer to your first question is pretty trivially "yes". Aug 3 '13 at 19:14
  • @StevenBurnap: The internet will soon be larger than a 64-bit address space if it isn't already (the exact size is rather hard to measure).
    – amara
    Aug 3 '13 at 19:44
  • @sparkleshy I don't see the direct connection between a cpu and the internet.
    – ott--
    Aug 3 '13 at 21:14
  • 1
    @StevenBurnap: some architectures have everything always be in address space, tho they aren't popular right now
    – amara
    Aug 3 '13 at 22:36
  • 1
    @StevenBurnap" "Stopgap" is putting it politely. Segmented memory, at least as Intel did it, was a hack grafted onto the 8085, which ran linear.
    – Blrfl
    Aug 4 '13 at 18:08

A flat memory model is generally easier for people to understand, because it is possible to construct a simple mapping between addresses and numbers. This makes it possible to mentally model the address space as a large array and addresses as indices into that array. In a segmented memory model, this mental image of the address space only works within a segment, but not between segments. So far, I have not found a mental model that can accurately describe a segmented memory model.

OTOH, a segmented memory model is far superior in preventing buffer overflows. The size of a segment is not fixed, but can be determined at runtime, so it is possible to allocate your buffers in dedicated segments that are sized exactly right for the buffer contained therein. Any attempt to go outside the buffer would immediately result in an error, because you are forming an illegal address. This is not possible with a flat memory model, because you might be addressing an unrelated variable that happens to be located adjacent to the buffer.

The reason that the flat memory model is used so much more probably comes from several factors:

  • The better understanding by programmers
  • On the x86 (including IA32) architecture, pointers within a segment are smaller and more efficient that pointers that can refer to different segments. This resulted in near and far pointers (which were a mess to work with) and a wish to keep as much as possible within one segment. In fact, IA32 has a segmented memory model, but in practice, only a single segment is ever used, giving it the appearance of a flat memory model.
  • Most processors with a segmented memory model (including the x86 architecture) did not support enough different segments to really take advantage of the fact that one segment per buffer is beneficial for security.

As a side note, it can be argued that the Java VM uses a segmented memory model, where each Java object occupies its own segment.


Segmented addresses allow a denser and more efficient use all CPU resources. All those meaningless zeros in a 64 bit address are "unnecessary" and consume resources - data paths must be wider, adders have to have more bits, and memories have to be bigger to hold all the redundant zeros.

Back in the stone age that was very important. The PDP-8 (my first real machine) packed everything into a 12-Bit "word", a 4K word address space, and a 128 word page size. Despite these extreme limitations, you could run a timesharing system on one.

These days CPU resources are not so precious, but not entirely irrelevant. You could probably pack a pdp-8 into a computer the size of a grain of sand. I'm sure the NSA has one on order.

  • 1
    For a long time there was a PDP-8 on a chip out there. Last time I looked no one was manufacturing them anymore, but there were still some in warehouses. I think I also heard a rumor of a PDP-8 specification for one of the FPGA languages. Aug 4 '13 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy