home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10835 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  2.6 KB

  1. Path: sparky!uunet!stanford.edu!rutgers!utcsri!csri.toronto.edu!ematias
  2. From: ematias@csri.toronto.edu (Ummm... me!)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Very puzzling struct problem!
  5. Message-ID: <1992Nov21.221745.23588@jarvis.csri.toronto.edu>
  6. Date: 22 Nov 92 03:17:45 GMT
  7. Organization: CSRI, University of Toronto
  8. Lines: 62
  9.  
  10.  
  11.  
  12.    While working on a little arcade-action game in Borland C v2.0, I've
  13. recently come across something very puzzling; perhaps someone can explain 
  14. to me exactly what is going on, since I'm not an expert programmer by any  
  15. stretch of the imagination.  The problem is explained below.
  16.  
  17.    I have declared a structure which holds all of the various characteristics
  18. of my sprites, and it looks something like this:
  19.  
  20. typedef struct {
  21.     int x, y;
  22.     int x2,y2;
  23.     int oldx[2], oldy[2];
  24.     int dx, dy;
  25.     int width, height;
  26.     int dead;
  27.     int frame;
  28.     int type;
  29.     int whatever[1];
  30. } Sprite;
  31.  
  32.    The different elements of the structure aren't important -- only the
  33. fact that there are 16 integer variables defined (i.e., 32 bytes).
  34.    A configuration like the one above works fine; however, I found that when
  35. I add or subtract an element from the struct (e.g., removing "int type", or
  36. changing the bottom one to "int whatever[2]"), two things would happen:
  37.  
  38. 1)  My program's .EXE size would increase by more than 1000 bytes,
  39. 2)  The number of frames per second would slow down drastically!
  40.     (i.e., the CPU was required to do much more work.)
  41.  
  42.    Upon fiddling around with the struct elements, I noticed that the two
  43. problems mentioned above would NOT occur when the number of elements was
  44. a multiple of 16 -- but only for some multiples.  For example:
  45.  
  46. - having 16 integer variables in the struct would work.
  47. - having 32 integer variables in the struct would work.
  48. - having 48 integer variables in the struct would NOT work.
  49. - having 64 integer variables in the struct would work.
  50. - having 80 integer variables in the struct would NOT work.
  51. - having 96 integer variables in the struct would NOT work.
  52. - having greater than 96 ints in the struct would NOT work.
  53.  
  54.    This is totally baffling me, since I can't comprehend why my program
  55. would be BIGGER and SLOWER just because the number of elements in a struct
  56. isn't a multiple of 16 -- and furthermore, why it works fine for only
  57. a select few multiples of 16.  Help!
  58.  
  59.    Any comments or suggestions would be most helpful, and if I'm naively
  60. overlooking something then a swift boot to the head would be in order. :-)
  61.  
  62.  
  63. Thanks,
  64.  
  65.      - Mark Rosteck -
  66. (ematias@csri.toronto.edu)
  67. (g1marker@cdf.toronto.edu)
  68.  
  69.  
  70. (By the way, I'm running this on a 33Mhz 386 and using the Compact memory
  71. model, if this helps to clarify the problem.)
  72.