From: lubaldo AT adinet DOT com DOT uy Message-Id: <3.0.1.32.19980616011946.006a2bcc@adinet.com.uy> Date: Tue, 16 Jun 1998 01:19:46 -0300 To: djgpp AT delorie DOT com Subject: Re: 64k demo In-Reply-To: References: <6lun9s$cie AT dfw-ixnews10 DOT ix DOT netcom DOT com> <35819A38 DOT C1BA3FCB AT hotmail DOT com> <358305BC DOT 61AB AT stud DOT warande DOT ruu DOT nl> <6lun9s$cie AT dfw-ixnews10 DOT ix DOT netcom DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Precedence: bulk Hello. At 11:53 PM 13/06/1998 GMT, Elliott Oti wrote: >On Sat, 13 Jun 1998, Matthew Conte wrote: >> Quick question: is access to a dynamically allocated array slower than a >> static global array, or are they the same? > >Depends. The speed of memory access depends on whether the accessed memory >is also in the cache, and whether that is more likely for static data in >your program code or globally allocated memory depends on your program >behaviour -- where it spends more time in, etc. All things being equal, it >should make no difference. > Warning: newbie giving opinions that can be very wrong! In my current project, we where using global static 2d arrays. Then changed to a dinamically allocated pointer and a dinamically allocated array of pointers to starts of lines of the pointer (similar thing as Allegro bitmaps). To my surprise and the surprise of my friends, this was slower! Then changed again and done a global static 1d array and a global static array of pointers to begining of lines of the 1d array. To our surprise, this was slower than the first method and faster than the dinamically allocated method (2nd method). I am not sure why is this, but maybe because GCC knows the sizes of the global static array and the offset in the data segment, and in a lot of cases it can directly access this array without doing arithmetic to find the address. In the 2nd method it cannot know the address of the array of pointers and the pointer so it has to find the pointer first (adding to the first pointer the value of the line we request) and then it has to add the value of this pointer to the column we say. In the 3rd method it knows where is the pointer array but not the 1d array, so it does not have to do the addition to find the pointer but the addition of the value of the pointer and the column we want. So, my question is if this is true and if it is not true, why is this? My recommendation: for multidimensional arrays try to use them static if you can. For 1d arrays I don't know, but it seems that 1d arrays also be faster if they are static since GCC know the address directly and don't have to add the pointer plus the number of the element we want. I have a 5x86 (like 486DX) so maybe this is the reason. In faster CPU's maybe this doesn't count and the only thing that counts is the speed of the memory, so it will be the same speed in any case. (right?) Ok, this is not off topic I think since we are talking of the DJGPP specific case and not the case of other compilers. Thanks for your patience and goodbye! Ivan Baldo: lubaldo AT adinet DOT com DOT uy - http://members.xoom.com/baldo - ICQ 10215364 Phone: (598) (2) 613 3223. Caldas 1781, Malvin, Montevideo, Uruguay, South America. (If you have problems with the previous addresses, try this ones: ibaldo AT usa DOT net, http://baldo.home.ml.org).