answersLogoWhite

0


Best Answer

Contiguous memory refers to a single block of consecutive memory addresses. All data types larger than a char require contiguous memory addresses.

For any given data type T, sizeof (T) tells us how many bytes of contiguous memory will be allocated to an object of that type:

std::cout << "sizeof (char) == " << sizeof (char) << std::endl;

std::cout << "sizeof (int) == " << sizeof (int) << std::endl;

std::cout << "sizeof (double) == " << sizeof (double) << std::endl;

struct X {/* ... */};

std::cout << "sizeof (X) == " << sizeof (X) << std::endl;

When we speak of contiguous memory, we don't usually refer to the number of bytes allocated to a given type; it can be taken as read that those bytes will be allocated contiguously such that the low-order byte refers to the whole object, regardless of its length.

Typically we use the term contiguous memory when referring to an array of objects. All objects in an array (the array elements) are exactly the same length (in bytes) and because they are allocated contiguously it is trivial to calculate the offset address of any one element relative to any other element in the same array. This is precisely how the array suffix operator works using only a zero-based index; the operator is nothing more than a convenient method of implementing pointer arithmetic. The upshot is that all arrays permit constant-time random access to any element in the array.

Arrays are dense data structures. That is, there is no additional memory required to maintain the structure. The only information we need to keep track of is the start address and the number of elements.

However, the downside of contiguous memory allocations is that whenever we wish to increase the amount of memory allocated we often have to move the entire allocation to new memory. The larger the allocation the more costly this becomes. Moreover, inserting new data means we must move elements to make room. This is why variable-length arrays typically reserve additional memory for moderate expansion while new elements are always pushed onto the end of the array rather than inserted in the middle.

Linked-lists are non-contiguous data structures which make use of additional memory to maintain links between the elements. As such, the elements need not move once allocated. If we want to change the element sequence or insert a new element into the sequence we simply update the affected links; the elements themselves remain wherever they were originally allocated.

Some data structures make use of both contiguous and non-contiguous allocations. A deque (a double-ended queue, pronounced deck) is a typical example because it is usually implemented as a linked-list of separate arrays. Each array is contiguous but the list of arrays is not necessarily contiguous.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is contiguous memory in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is meant by contiguous memory allocation in C?

Contiguous memory allocation in C programming refers to the assigning of consecutive memory blocks to a process. Contiguous memory allocation is one of the oldest and most popular memory allocation schemes in programming.


Difference between contiguous and non contiguous memory?

In contiguous allocation there is no overhead during execution of a program. In noncontiguous allocation address translation is performed during execution Contiguous memory allocates single area of memory Noncontigious memory allocates several memory areas - one memory are to each component of a process


Difference between contiguous and non contiguous memory allocation?

In a contiguous memory allocation there is no overhead during execution of a program. In a non contiguous memory allocation address translation is performed during execution.


What is the memory management operator in c plus plus?

There is no memory management operator in C++ -- it is an unmanaged language. You use the C++ new operator to allocate memory, and use the C++ delete operator to release previously allocated memory.


What is contiguous memory?

The largest chuck of available memory that is not fragmented.


Which operator is used for deallocating memory in c plus plus?

delete


What are new and delete operators in c plus plus?

New and Delete are the memory management operators in c++,like c language we use malloc() and calloc() functions to allocate memory and free() functiong to release the memory similarily we use new to allocate memory in C++ and Delete to release the allocated memory....


What is contiguous storage?

Contiguous means to share an edge or boundary, touching, adjacent, neighbouring and so on. Thus contiguous storage allocation is any allocation that consumes two or more contiguous storage elements. In the case of contiguous memory allocation, this means two or more contiguous memory addresses are allocated. A one-dimensional array is an example of a contiguous memory allocation, where one array element (a data type) is immediately followed by the next.


What is an address in C plus plus programming?

An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.


What is contiguous storage allocation?

Contiguous means to share an edge or boundary, touching, adjacent, neighbouring and so on. Thus contiguous storage allocation is any allocation that consumes two or more contiguous storage elements. In the case of contiguous memory allocation, this means two or more contiguous memory addresses are allocated. A one-dimensional array is an example of a contiguous memory allocation, where one array element (a data type) is immediately followed by the next.


How do you calculate the size of a class in memory in C plus plus?

Use sizeof( ).


Compare Contiguous memory allocation with internal fragmentation?

in early, computer system has contiguous memory allocation,each process is allocated in a single contiguous(together) memory!!(allocating into memory addresses one by one,)it has tackled memory fragmentation(both internal and external). not allocating for a fixed size memory block.so no internal fragmentation, allocating contiguously ,so no external fragmentation!!!