What are local arrays?

Hello everybody
I would like to know where are local arrays (I mean the arrays that are declared inside a function just to as intermediate variables) stored? in registers or in the memory?
The thing is, I want to calculate the arithmetic intensity of certain functions :
arithmetic intensity = number of arithmetic operations/number of memory accesses
and I don't know whether to regard an access to a local array as a memory access.
The local arrays Im talking about are created using malloc.

Replies

  • rahul69
    rahul69
    rukawa
    Hello everybody
    I would like to know where are local arrays (I mean the arrays that are declared inside a function just to as intermediate variables) stored? in registers or in the memory?
    The thing is, I want to calculate the arithmetic intensity of certain functions :
    arithmetic intensity = number of arithmetic operations/number of memory accesses
    and I don't know whether to regard an access to a local array as a memory access.
    The local arrays Im talking about are created using malloc.
    Variables can be stored on registers, when we specify them as register (remember storage class specifiers?๐Ÿ˜€)
    Local Variables declared inside a function are stored on the stack (in case of static allocation)
    However as u are dynamically allocating the memory to the array (using malloc) so this array will be stored on the heap.๐Ÿ˜
  • rukawa
    rukawa
    rahul69
    Variables can be stored on registers, when we specify them as register (remember storage class specifiers?๐Ÿ˜€)
    Local Variables declared inside a function are stored on the stack (in case of static allocation)
    However as u are dynamically allocating the memory to the array (using malloc) so this array will be stored on the heap.๐Ÿ˜
    Thanks rahul69 for your answer. Actually, the aim of the programming assignment I was doing is to show the impact of the cache memory on the exectution time of a program. The memory I'm talking about is the central memory (RAM). To my understanding, when the program needs data, it's loaded from the cache memory, if the wanted data is not there, then it is loaded from the central memory to the cache, and then used by the program. Of course, if data is available within the register, that's going to spare us the time to look for it elsewhere, which optimizes the execution time.
    I asked my teacher the following question : "If I use an array in my program, is it going to be stored in registers or in the central memory". He said that it was going to be stored in the central memory (which is logical given the fact that the array is bigger in size than a mere variable).
  • Anand Tamariya
    Anand Tamariya
    Registers are only relevant to the current instruction being executed - everything else is in cache, RAM or HD.

You are reading an archived discussion.

Related Posts

After 3 big announcement by Valve - SteamOS - Steambox - Steam Controller Latter one looked bit of disappointing announcement at first, but it's not. Checkout this video : โ€‹...
If you care about such a thing as - which satellite is looking at you right now, the SpyMeSat app is the right thing for you. Developed in the US...
Finding the right parking slot in big malls or parking places is a huge challenge to the entire mankind and Honda's engineers have vowed to solve that problem using a...
Innovation have made their way to the motorcycle safety gear with the Android powered Skully Helmets becoming Smart and more productive than ever before. Developed by Skully, a Silicon valley-based...
Current generation of storage media has one problem it's carried over for several decades, since the introduction of magnetic disk based storage system by IBM back in 1956: they can't...