Re: performance question

From: Amey Samant (ameyas7_at_yahoo.com)
Date: 10/25/03


Date: 25 Oct 2003 02:37:41 -0700

Murat Tasan <tasan@eecs.cwru.edu> wrote in message news:<Pine.SOL.4.53.0310231524410.28593@homer>...

> let's say i have a program that uses an array.
> and many times in the program i need to do computation that rely on the
> array's length.
>
> so, how much speedup (if any at all) is there to storing the array length
> as an int and using that in the computations, compared with constantly
> using the arrayName.length method?
> murat

hi
in your example, your method has following disadvantages
1) you must update length variable as and when array is allocated new
elements
for eg
if in your prog you have something like arr=new int[5]; then you must
update length variable maintained by you.
2) its a duplicate variable ... i mean arr.length is a variable & not
a method, so why you want to maintain a copy of original variable
3) if you have 10 arrays , do you want to allocate 10 variables for
maintaining array size when its already taken care of ....
or would you go for havin an array of size 10 say lengths[10] ;) &
then maintain size of this array in seperate variable ;)

hope i made it clear
regards
amey



Relevant Pages

  • Re: check for the existence of an element in a vector
    ... The array A is already sorted. ... I think the "trivial" speedup of an ... early exit from the check loop is what i can get! ...
    (comp.lang.fortran)
  • Re: pros and cons of user-defined types
    ... Then i think it is good programming ... style to group related arguments into user-defined types. ... Or are there other possible disadvantages? ... like the data being plotted and a single array of parameters. ...
    (comp.lang.fortran)
  • poss soln
    ... this prog will print both the elements and similarly all the elements ... can be printed with the format *+ i). ... in the prog u had initalized Data to be a ptr to a 2D array with the ...
    (comp.lang.c)
  • Re: baffling arrays problem
    ... > 30 read a file whose index within the prog is file_number ... > column for each case was absent), and ukl work fine! ... > actual means an array boundary error), but I have no idea what, and why ... your compiler have an option to enable array bounds checking? ...
    (comp.lang.fortran)
  • Re: float (*Data)[4] vs float *Data[4]
    ... > array that it points to. ... this prog will print both the elements and similarly all the elements ... initalized Data to be a ptr to a 2D array with the no of columns ... the contents by *+ ),thats the format. ...
    (comp.lang.c)