home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18538 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  2.4 KB

  1. Path: sparky!uunet!pipex!bnr.co.uk!uknet!mcsun!sun4nl!ruuinf!prisma.cv.ruu.nl!koen
  2. From: koen@cv.ruu.nl (Koen Vincken)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Sizeof and Virtual functions
  5. Message-ID: <1992Dec30.142651.8454@cv.ruu.nl>
  6. Date: 30 Dec 92 14:26:51 GMT
  7. References: <1992Dec24.061254.9763@nuscc.nus.sg> <1992Dec29.211505.21322@taumet.com>
  8. Organization: University of Utrecht, 3D Computer Vision Research Group
  9. Lines: 44
  10.  
  11. In <1992Dec29.211505.21322@taumet.com> steve@taumet.com (Steve Clamage) writes:
  12.  
  13. >suresh@papaya.iss.nus.sg (Suresh Thennarangam - Research Scholar) writes:
  14. >
  15. >>One of the things that distinguishes virtual functions from other
  16. >>normal member functions of a class is that some compilers that I
  17. >>know of, store an extra pointer that is  probably used to index 
  18. >>a vector table...
  19. >
  20. >'sizeof' better tell the truth.  It must report the amount of storage
  21. >required by an object of that type.  If the object has extra data added
  22. >by the compiler, that is part of its size.  This is conceptually no
  23. >different from the padding a compiler might add to get suitable alignment
  24. >of individual members.  You are not allowed to assume the size of any
  25. >type other than "char" (which is always 1 by definition).  In C as well
  26. >as C++, struct types might have a size different from that calculated
  27. >by adding the size of each member.
  28. >
  29.  
  30. [...good points deleted...]
  31.  
  32. >C++ allows control of pure data types in exactly the same way as C.
  33. >You can, for example, create a C-style struct containing just the data
  34. >of interest, and derive a class from it which has all the functionality
  35. >you want.  You can still write and read back the data as you would in C.
  36. >-- 
  37. >
  38. >Steve Clamage, TauMetric Corp, steve@taumet.com
  39.  
  40. I agree with Steve. New C++ programmers often make the 'sizeof' mistake
  41. (just as I did). 
  42. Now I save my rather complicated classes with explicit member functions.
  43. Instead of using structs or using 'sizeof(object)' I have (for every class 
  44. of interest) a function 'Write()', which simply writes all member variables
  45. to a file. Also, this allows me to write only those variables that need to 
  46. be saved. This way, file sizes were reduced from about 50 Mbyte to 25 Mbyte!
  47.  
  48.     Koen Vincken
  49.  
  50.  
  51.     /   /                      Koen Vincken, AZU E 02.222, Heidelberglaan 100, 
  52.    /  /    _  /  ___/   \   / 3584 CX Utrecht, The Netherlands. 
  53.   /  \    /  /  _/    /  \ / e-mail: koen@cv.ruu.nl, or vincken@cs.unc.edu
  54. __/  _\ ____/ ____/ _/   _/ phone: +31-30-506710/506711
  55.