www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/11/26/16:54:19

Subject: Arrays vs. pointers
From: WU DAVID S <wudavid AT ecf DOT toronto DOT edu>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Sat, 26 Nov 1994 09:32:44 -0500

I was wondering what the exact differences betwen arrays and allocated pointers
are.

If you have: 
int array[big];

array[i] = 1;

or int * ptr
ptr = new int[big];
ptr[i] = 2;
delete ptr

they both do about the same thing, but the first case makes your exe bigger.
I would think that the first case can be alot faster however.  Is this correct?

Because if you are accessing an element, in the first case the compiler knows where
it is.  It doesn't need to use a register for ptr and it doesn't even have to 
dereference ptr. it can just add i to a constant number. to get the address.

Is this correct or have I completely lost it?

-- 
                                          |\___
                                          |O.o/
          David Wu                       =(___)=    Don't Drink
                                            U       and Derive

Disclaimer:  This message may not be politically correct.
The message may not be grammatically correct.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019