Author: martin fierz
Date: 09:21:24 11/16/00
Go up one level in this thread
On November 16, 2000 at 10:33:48, Robert Hyatt wrote: >On November 16, 2000 at 05:38:02, martin fierz wrote: > >>hi, >> >>i recently moved from borland C 5.5 to visual C 6.0 professional which resulted >>in a 10% speed increase in my checkers program - this helps answer a question i >>asked recently about 'best compilers'. >> >>i have another question about speed: i'm using large arrays for different >>things, hash-xoring, bit-counting, some arrays in the evaluation etc. i noticed >>that the final speed of my program depends on how i declare them - but the >>behavior seems rather erratic. does anybody know if there should be a difference >>between declaring globals like this: >> >>int large_array[BIG_NUMBER]; >> >>or >> >>int *large_array; >> >>followed by a malloc in the initialization? > >They are equivalent, actually, since C doesn't really have an "array" data >type. One of the things that students have trouble with is that if you use >the pointer declaration form above, you can do this: > >*(large_array+i)=0; >large_array[i]=0; > >even though the large_array declaration is not an array... because arrays >are implemented in C via pointers. i know that the two methods are equivalent in principle, but it's a fact that the execution speed of my program changes (not much, i admit) if i change this statement. there is the difference pointed out by james: >I _think_ the only difference there is where it's stored in memory. >The first case (with the array) would be allocated down with >the rest of your globals, and the malloc would go on the heap, of course. and somehow this seems to affect the execution speed, but in a rather random way - i was just wondering if there was some general idea around, like 'always use pointers' or 'always use arrays' because that might tend to get data closer together in the memory and could somehow affect the way the cache is working. it's the only explanation i have and it does not give me any clue on what do do :-( -martin
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.