Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a contiguous memory block?

Just like in the title, what is a contiguous memory block?

like image 963
565471741 Avatar asked Oct 30 '10 15:10

565471741


People also ask

What does contiguous mean in memory?

What Does Contiguous Memory Allocation Mean? Contiguous memory allocation is a classical memory allocation model. Here, a system assigns consecutive memory blocks (that is, memory blocks having consecutive addresses) to a process. Contiguous memory allocation is one of the oldest memory allocation methods.

What does contiguous mean in C++?

It means that memory is allocated as a single chunk. This is most often used when talking about containers. For instance, the vector and string classes use a contiguous chunk of memory.

What does contiguous mean in computer terms?

A file on disk that is not broken apart. All sectors are adjacent to each other. A contiguous file is faster to read and write than one that is fragmented across the disk.

What is contiguous memory locations in Java?

Contiguous memory allocation contains two memory allocations: single partition and multi-partition. It contains Paging and Segmentation. The memory space is partitioned into fixed-sized partitions in the contiguous memory allocation, and each partition is only assigned to one process.


2 Answers

This is a contiguous memory block of five bytes, spanning from location 1 to location 5:

alt text

It represents bytes (colored light blue) that are together in memory with no gap bytes (white) between them.

This is a non-contiguous set of five bytes of interest:

alt text

It is fragmented into three groups of bytes (colored yellow) with gap bytes at locations 4 and 6. Starting at location 1 there is a contiguous block of three bytes, spanning from locations 1 to 3. There are two more blocks of one byte each at locations 5 and 7, respectively.

The unused block at location 0 as well as any subsequent blocks beyond location 7 can usually be ignored since they do interpose between the bytes of interest spanning from locations 1 to 7.

like image 82
Michael Goldshteyn Avatar answered Sep 24 '22 19:09

Michael Goldshteyn


One without any gaps in the addresses it occupies. You can probably just think of this as a "block", and think of something with a gap in the middle as "two blocks".

The term comes up in the definition of an array as being "contiguous". That means the elements are laid out end-to-end, with no discontinuities and no padding between them (there may be padding inside each element, but not between elements). So an array of 5 4-byte elements looks like this (1 underscore character per byte, the | symbols don't represent memory):

 ____ ____ ____ ____ ____ |____|____|____|____|____| 

It doesn't look like this:

 ____ _ ____ _ ____ _ ____ _ ____ |____|_|____|_|____|_|____|_|____| 

And neither does it look like this:

 ____ ____ ____                                           ____ ____ |____|____|____| ... somewhere completely different ...  |____|____| 

In all cases, "looks like" means "as far as the addresses visible in C are concerned". Something could be contiguous in virtual address space, but not contiguous in physical RAM. For that matter, something could be contiguous in physical RAM address space, but not actually adjacent in physical RAM. Half of it could be on one RAM chip over here, and the other half on another RAM chip over there. But the C memory model can't "see" any of that.

like image 41
Steve Jessop Avatar answered Sep 23 '22 19:09

Steve Jessop