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