Write a Python program to get the current memory address and the length in elements of the buffer
used to hold an array’s contents and also find the size of the memory buffer in bytes.
array_num = array('i',[1,2,5,3,8,7,9,11,45,])
print('Current memory address :',str(array_num.buffer_info()))
print('Length in elements of the buffer :', str(array_num.buffer_info()[1]))
print('Size of the memory buffer in bytes :',str(array_num.itemsize))
Error Message “Name error:name ‘array’ is not defined”
You need to import array module. Just add the next line to your code:
from array import array
array_num = array('i',[1,2,5,3,8,7,9,11,45,])
print('Current memory address :',str(array_num.buffer_info()))
print('Length in elements of the buffer :', str(array_num.buffer_info()[1]))
print('Size of the memory buffer in bytes :',str(array_num.itemsize))
The output is:
Current memory address : (1613985309152, 9)
Length in elements of the buffer : 9
Size of the memory buffer in bytes : 4