CrazyEngineers
  • rukawa
    rukawa

    MemberOct 21, 2013

    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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • rahul69

    MemberOct 23, 2013

    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.😁
    Are you sure? This action cannot be undone.
    Cancel
  • rukawa

    MemberNov 2, 2013

    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).
    Are you sure? This action cannot be undone.
    Cancel
  • Anand Tamariya

    MemberNov 3, 2013

    Registers are only relevant to the current instruction being executed - everything else is in cache, RAM or HD.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register