home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10870 < prev    next >
Encoding:
Text File  |  1992-11-23  |  1.3 KB  |  30 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!rei2!fox
  3. From: fox@rei.com (Fuzzy Fox)
  4. Subject: Re: Very puzzling struct problem!
  5. Message-ID: <1992Nov23.195509.8376@rei.com>
  6. Date: Mon, 23 Nov 1992 19:55:09 GMT
  7. References: <1992Nov21.221745.23588@jarvis.csri.toronto.edu>
  8. Organization: Recognition Equipment, Inc.
  9. Lines: 19
  10.  
  11. ematias@csri.toronto.edu (Ummm... me!) writes:
  12.  
  13. >   This is totally baffling me, since I can't comprehend why my program
  14. >would be BIGGER and SLOWER just because the number of elements in a struct
  15. >isn't a multiple of 16 -- and furthermore, why it works fine for only
  16. >a select few multiples of 16.  Help!
  17.  
  18. It is because pointer arithmetic is more efficient with powers of two.
  19. If the size of your struct is a power of two, then pointer manipulations
  20. (and array offset calculations) can be performed with simple shift
  21. instructions, whereas non-power-of-two-sized elements require slow
  22. multiply and division operations, which both increase the size of your
  23. code and slow down the program.  Exactly what you observed.
  24.  
  25. -- 
  26. #ifdef TRUE        | Fuzzy Fox (a.k.a. David DeSimone)       fuzzy@netcom.com
  27. #define  TRUE   0  |
  28. #define  FALSE  1  |  "You have been recruited by the Star League to defend
  29. #endif             |     the Frontier against Xur and the Kodan Armada."
  30.