Date: Mon, 28 Nov 1994 09:09:33 +0100 From: Thomas Eifert Subject: Re: Arrays vs. pointers To: djgpp AT sun DOT soe DOT clarkson DOT edu Reply-To: eifert AT rz DOT rwth-aachen DOT de Organization: Rechenzentrum RWTH Aachen > 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? > The difference is the "dynamics": The 2nd version does the same *after* the "new"-command, so the allocation is done at run time, whereas in the 1st case the allocation is done at compile time* ! +------------------------------------------------------------------+ | Thomas Eifert | | | | Aachen University of Technology RWTH Aachen | | Computing Center Rechenzentrum | | Seffenter Weg 23 | | D-52074 Aachen | | | | E-Mail: eifert AT rz DOT RWTH-Aachen DOT de Tel.: (0241) 80-4890 | | Fax.: (0241) 8888-134 | +------------------------------------------------------------------+