什么是连续内存块?

时间:2020-12-23 02:40:11

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

就像在标题中一样,什么是连续内存块?

5 个解决方案

#1


41  

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".

一个没有任何空白的地址它占用。你可以把它想象成一个“block”,把中间有空隙的东西想象成“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):

这个术语出现在数组的定义中是“连续的”。这意味着元素是端到端的,它们之间没有不连续,也没有填充(每个元素内部可能有填充,但元素之间没有)。所以一个包含5个4字节的元素的数组看起来是这样的(每个字节1个下划线字符,|符号不代表内存):

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

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.

在所有情况下,“look like”都表示“对于C中可见的地址”。在虚拟地址空间中,某些东西可以是连续的,但在物理RAM中不能是连续的。因此,在物理RAM地址空间中某些东西可以是连续的,但在物理RAM中却不是相邻的。一半可能在这里的一个RAM芯片上,另一半在另一个RAM芯片上。但是C内存模型不能“看到”这些。

#2


48  

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

这是一个五个字节的连续内存块,从位置1到位置5:

什么是连续内存块?

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:

这是一个由5个字节组成的非连续集合:

什么是连续内存块?

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.

它被分割成三组字节(黄色),间隔字节在位置4和6。从位置1开始,有一个由三个字节组成的连续块,从位置1到3。在位置5和7分别有两个字节的块。

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.

位置0处的未使用块以及位置7之外的任何后续块通常都可以忽略,因为它们在从位置1到7的感兴趣字节之间进行交互。

#3


5  

A block of memory which isn't interrupted by other memory. Or to be more precise it requires an uninterrupted block of virtual address-space. The real RAM backing that address space doesn't need to be contiguous.

不被其他内存中断的内存块。或者更准确地说,它需要一个不间断的虚拟地址空间块。地址空间支持的真正RAM不需要是连续的。

This is important if you allocate a large memory block. The OS has to give it to you as a contiguous block, but if memory is so fragmented that only smaller pieces are free then this memory allocation cannot be satisfied even if the total free memory is larger than the requested space.

如果您分配一个大的内存块,这一点很重要。操作系统必须将它作为一个连续的块提供给您,但是如果内存碎片化到只有更小的块是空闲的,那么即使总的空闲内存大于请求的空间,也不能满足这个内存分配。

This isn't such a big problem on 64 bit apps since the address space is large there. But in 32 bit processes it can happen that the heap gets so fragmented(between freed blocks there are still unfreed blocks) that larger allocations fail.

在64位应用程序中,这不是一个大问题,因为地址空间很大。但是在32位进程中,堆变得如此分散(在被释放的块之间仍然有未释放的块),较大的分配失败。

#4


2  

Answering in the context of allocating memory, when you invoke the memory allocator and request 24 bytes of memory, it must be able to locate a single block of at least 24 bytes of unallocated memory.

在分配内存的上下文中进行应答,当您调用内存分配器并请求24字节的内存时,它必须能够定位至少24字节的未分配内存的单个块。

If it has 16 bytes of memory starting at one address x and another 8 bytes starting at an address y such that y > x + 16 or y < x - 8 (that would create a gap), then the allocator cannot satisfy your request for 24 bytes even though there is a total of 24 bytes free.

如果它有16个字节的内存从一个地址x和另一个8字节从一个地址y,y > x + 16或y < x - 8(这将创建一个空白),然后为24字节分配器不能满足你的要求即使有一个免费的24字节总数。

See also Fragmentation.

参见碎片。

#5


2  

A memory block is contiguous exactly when it is defined by a start and an end address from a single linear address space and has no holes.

当一个内存块由一个单一的线性地址空间的开始和结束地址定义时,它是连续的,并且没有任何洞。

#1


41  

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".

一个没有任何空白的地址它占用。你可以把它想象成一个“block”,把中间有空隙的东西想象成“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):

这个术语出现在数组的定义中是“连续的”。这意味着元素是端到端的,它们之间没有不连续,也没有填充(每个元素内部可能有填充,但元素之间没有)。所以一个包含5个4字节的元素的数组看起来是这样的(每个字节1个下划线字符,|符号不代表内存):

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

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.

在所有情况下,“look like”都表示“对于C中可见的地址”。在虚拟地址空间中,某些东西可以是连续的,但在物理RAM中不能是连续的。因此,在物理RAM地址空间中某些东西可以是连续的,但在物理RAM中却不是相邻的。一半可能在这里的一个RAM芯片上,另一半在另一个RAM芯片上。但是C内存模型不能“看到”这些。

#2


48  

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

这是一个五个字节的连续内存块,从位置1到位置5:

什么是连续内存块?

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:

这是一个由5个字节组成的非连续集合:

什么是连续内存块?

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.

它被分割成三组字节(黄色),间隔字节在位置4和6。从位置1开始,有一个由三个字节组成的连续块,从位置1到3。在位置5和7分别有两个字节的块。

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.

位置0处的未使用块以及位置7之外的任何后续块通常都可以忽略,因为它们在从位置1到7的感兴趣字节之间进行交互。

#3


5  

A block of memory which isn't interrupted by other memory. Or to be more precise it requires an uninterrupted block of virtual address-space. The real RAM backing that address space doesn't need to be contiguous.

不被其他内存中断的内存块。或者更准确地说,它需要一个不间断的虚拟地址空间块。地址空间支持的真正RAM不需要是连续的。

This is important if you allocate a large memory block. The OS has to give it to you as a contiguous block, but if memory is so fragmented that only smaller pieces are free then this memory allocation cannot be satisfied even if the total free memory is larger than the requested space.

如果您分配一个大的内存块,这一点很重要。操作系统必须将它作为一个连续的块提供给您,但是如果内存碎片化到只有更小的块是空闲的,那么即使总的空闲内存大于请求的空间,也不能满足这个内存分配。

This isn't such a big problem on 64 bit apps since the address space is large there. But in 32 bit processes it can happen that the heap gets so fragmented(between freed blocks there are still unfreed blocks) that larger allocations fail.

在64位应用程序中,这不是一个大问题,因为地址空间很大。但是在32位进程中,堆变得如此分散(在被释放的块之间仍然有未释放的块),较大的分配失败。

#4


2  

Answering in the context of allocating memory, when you invoke the memory allocator and request 24 bytes of memory, it must be able to locate a single block of at least 24 bytes of unallocated memory.

在分配内存的上下文中进行应答,当您调用内存分配器并请求24字节的内存时,它必须能够定位至少24字节的未分配内存的单个块。

If it has 16 bytes of memory starting at one address x and another 8 bytes starting at an address y such that y > x + 16 or y < x - 8 (that would create a gap), then the allocator cannot satisfy your request for 24 bytes even though there is a total of 24 bytes free.

如果它有16个字节的内存从一个地址x和另一个8字节从一个地址y,y > x + 16或y < x - 8(这将创建一个空白),然后为24字节分配器不能满足你的要求即使有一个免费的24字节总数。

See also Fragmentation.

参见碎片。

#5


2  

A memory block is contiguous exactly when it is defined by a start and an end address from a single linear address space and has no holes.

当一个内存块由一个单一的线性地址空间的开始和结束地址定义时,它是连续的,并且没有任何洞。