0% found this document useful (0 votes)
95 views7 pages

Memory Array Organizations

A memory array refers to a linear data structure that stores a collection of similar data types in contiguous memory locations. Memory arrays can be one-dimensional, containing elements accessed via a single index, or multi-dimensional, containing elements accessed via multiple indices. Memory is allocated for arrays in either row-major or column-major order, with elements stored sequentially in memory based on the chosen storage order. The total memory used by an array is calculated by multiplying the number of elements by the size of each element.

Uploaded by

Sutanu MUKHERJEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views7 pages

Memory Array Organizations

A memory array refers to a linear data structure that stores a collection of similar data types in contiguous memory locations. Memory arrays can be one-dimensional, containing elements accessed via a single index, or multi-dimensional, containing elements accessed via multiple indices. Memory is allocated for arrays in either row-major or column-major order, with elements stored sequentially in memory based on the chosen storage order. The total memory used by an array is calculated by multiplying the number of elements by the size of each element.

Uploaded by

Sutanu MUKHERJEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Memory Array Organizations

A memory array is a linear data structure that stores a collection of similar data types at
contiguous locations in a computer's memory. Memory arrays are categorized as one-
dimensional arrays and multiple-dimensional arrays. Arrays are among the oldest data
structures and are used in almost every computer program.

What is a Memory Array?


A memory array refers to a linear data structure that stores a collection of similar data types at
contiguous locations in a computer's memory. A linear data structure comprises data
components arranged in sequential order, and each member element is related to the
preceding element. Each memory array is built as a series of bit cells, with each cell holding to
one bit of data. An array index specifies the position of an element within the array. The item
stored in the array is referred to as an array element, and it may be retrieved using its index.
Memory arrays are generally categorized into one-dimensional arrays and multi-dimensional
arrays.

Types of Memory Arrays

One-dimensional Arrays
A one-dimensional array, also known as a single dimension array, is a linear data structure array
that requires only one subscript specification to indicate a single array element. It is a collection
of variables related to one another and have similar data types. A one-dimensional array
enables random access, and all the elements can be retrieved with the support of their index.
These types of arrays are popular in programming.

Multiple-dimensional Arrays
A multiple-dimensional array is a linear data structure array with two subscripts. Like a one-
dimensional array, it also allows random access, and all the elements can be retrieved with the
support of their index. A multiple-dimensional array can be seen as a collection of 1D arrays
known as a matrix. The dimensions of multiple-dimensional arrays can be increased from 2 to 3
and so forth. The simplest form of multiple-dimensional array is a two-dimensional array,
usually denoted as 2D. 

Uses and Applications


Arrays are used to implement matrices, mathematical vectors, and other rectangular tables.
Many databases are made up of, or include, one-dimensional arrays with records as their
elements. Memory arrays can also implement various data structures such as heaps, hash
tables, queues, stacks, etc. One or more huge arrays are sometimes employed to simulate in-
program dynamic memory allocation, particularly memory pool allocation. Arrays allow random
access and are cache-friendly.

Array Memory Diagrams


Here is an array declaration and code to initialize it.
int a[5]; // Allocates memory for 5 ints.
. . .
a[0] = 1;
for (int i=1; i<5; i++) {
a[i] = a[i-1] * 2;
}

Arrays are often represented with diagrams that represent their memory use. The
diagram below is one typical way to represent the memory used by an array.
Each box represents the amount of memory needed to hold one array element. For
ints this is usually 4 bytes. We can write the value of an element inside the box.
Pointers hold the memory address of other data and are represented by a black
disk with an arrow pointing to the data it references.
The actual array variable, a in this example, is a pointer to the memory for all of its
elements. A common shortcut is to omit writing the array variable, and write only
the elements that hold the data because these are usually the focus of attention.
Sometimes the cells are written horizontally, especially when showing C-strings
(arrays of chararcters).

or simply
or just

Array Memory Allocation in C


Programming
We have already discussed that whenever an array is declared in the
program, contiguous memory to it elements are allocated. Initial address of
the array – address of the first element of the array is called base address of
the array. Each element will occupy the memory space required to
accommodate the values for its type, i.e.; depending on elements datatype, 1,
4 or 8 bytes of memory is allocated for each elements. Next
successive memory address is allocated to the next element in the array. This
process of allocating memory goes on till the number of element in the array
gets over.
Table of Contents
 One Dimensional Array
 Multidimensional Array
 Row Major Order
 Column Major Order
One Dimensional Array
Below diagram shows how memory is allocated to an integer array of N
elements. Its base address – address of its first element is 10000. Since it is
an integer array, each of its element will occupy 4 bytes of space. Hence first
element occupies memory from 10000 to 10003. Second element of the array
occupies immediate next memory address in the memory, i.e.; 10004 which
requires another 4 bytes of space. Hence it occupies from 10004 to 10007. In
this way all the N elements of the array occupies the memory space.

If the array is a character array,


then its elements will occupy 1 byte of memory each. If it is a float array then
its elements will occupy 8 bytes of memory each. But this is not the total size
or memory allocated for the array. They are the sizes of individual elements in
the array. If we need to know the total size of the array, then we need to
multiply the number of elements with the size of individual element.

i.e.; Total memory allocated to an Array = Number of elements * size of


one element
Total memory allocated to an Integer Array of N elements = Number of
elements * size of one element
= N * 4 bytes
= 10 * 4 bytes = 40 Bytes, where N = 10
= 500 * 4 bytes = 2000 Bytes, where N = 500
Total memory allocated to an character Array of N elements= Number of
elements * size of one element
= N * 1 Byte
= 10 * 1 Byte = 10 Bytes, where N = 10
= 500 * 1 Byte = 500 Bytes, where N=500
This is how memory is allocated for the single dimensional array.
Multidimensional Array
In the case of multidimensional array, we have elements in the form of rows
and columns. Here also memories allocated to the array are contiguous. But
the elements assigned to the memory location depend on the two different
methods:

Row Major Order


Let us consider a two dimensional array to explain how row major order way
of storing elements works. In the case of 2D array, its elements are
considered as rows and columns of a table. When we represent an array as
intArr[i][j], the first index of it represents the row elements and the next index
represents the column elements of each row. When we store the array
elements in row major order, first we will store the elements of first row
followed by second row and so on.  Hence in the memory we can find the
elements of first row followed by second row and so on. In memory there will
not be any separation between the rows. We have to code in such a way that
we have to count the number of elements in each row depending on its
column index. But in memory all the rows and their columns will be
contiguous. Below diagram will illustrate the same for a 2D array of size 3X3
i.e.; 3 rows and 3 columns.

Array indexes always start from 0. Hence the first element of the 2D array is at
intArr[0][0]. This is the first row-first column element. Since it is an integer
array, it occupies 4 bytes of space. Next memory space is occupied by the
second element of the first row, i.e.; intArr [0][1] – first row-second column
element. This continues till all the first row elements are occupied in the
memory. Next it picks the second row elements and is placed in the same way
as first row. This goes on till all the elements of the array are occupies the
memory like below. This is how it is placed in the memory. But seeing the
memory address or the value stored in the memory we cannot predict which is
the first row or second row or so.
Total size/ memory
occupied by 2D array is calculated as

Total memory allocated to 2D Array = Number of elements * size of one


element
                = Number of Rows * Number of Columns * Size of one element
Total memory allocated to an Integer Array of size MXN = Number of
elements * size of one element
=M Rows* N Columns * 4 Bytes
= 10*10 * 4 bytes = 400 Bytes, where M =N = 10
= 500*5 *4 bytes= 10000 Bytes, where M=500 and N= 5
Total memory allocated to an character Array of N elements= Number of
elements * size of one element
= M Rows* N Columns * 1 Byte
= 10*10 * 1 Byte = 100 Bytes, where N = 10
= 500*5 * 1 Byte = 2500 Bytes, where M=500 and N= 5
Column Major Order
This is the opposite method of row major order of storing the elements in the
memory. In this method all the first column elements are stored first, followed
by second column elements and so on.
Total size/ memory
occupied by 2D array is calculated as in the same way as above.

Total memory allocated to 2D Array = Number of elements * size of one


element
                                        = Number of Rows * Number of Columns * Size of
one element
Total memory allocated to an Integer Array of size MXN = Number of
elements * size of one element
=M Rows* N Columns * 4 Bytes
= 10*10 * 4 bytes = 400 Bytes, where M =N = 10
= 500*5 *4 bytes= 10000 Bytes, where M=500 and N= 5
Total memory allocated to an character Array of N elements= Number of
elements * size of one element
= M Rows* N Columns * 1 Byte
= 10*10 * 1 Byte = 100 Bytes, where N = 10
= 500*5 * 1 Byte = 2500 Bytes, where M=500 and N= 5
If an array is 3D or multidimensional array, then the method of allocating
memory is either row major or column major order. Whichever is the method,
memory allocated for the whole array is contiguous and its elements will
occupy them in the order we choose – row major or column major. The total
size of the array is the total number of elements * size of one element.

You might also like