home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!unipalm!uknet!mcsun!sunic!hagbard!loglule!jbn
- From: jbn@lulea.trab.se (Johan Bengtsson)
- Newsgroups: comp.lang.c++
- Subject: Re: zero-length datatype
- Message-ID: <4947@holden.lulea.trab.se>
- Date: 9 Sep 92 19:58:05 GMT
- References: <TMB.92Sep8141523@arolla.idiap.ch>
- Distribution: comp
- Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
- Lines: 45
- X-Newsreader: Tin 1.1 PL4
-
- tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
- : In article <MCGRANT.92Sep7142456@rascals.stanford.edu> mcgrant@rascals.stanford.edu (Michael C. Grant) writes:
- :
- : I don't understand why those 4 bytes are causing you such a stink. Perhaps
- : you could enlighten us as to why a truly zero length data type is even
- : necessary?
- :
- : Under the current rules,
- :
- : struct nothing {};
- : HashTable<int,nothing> table(1000000);
- :
- : table takes up 8Mbytes (on most machines). If you could write
- :
- : HashTable<int,void> table(1000000);
- :
- : table takes up 4Mbytes.
-
- Note also that the "minimum 4 bytes" effect multiplies, if
- a class has more than one "void" data member:
-
- // This is not legal C++ code, "void" means "zero-size type"
- class C {
- long i;
- void a,b,c,d,e;
- };
-
- On common implementations, 1 million such objects take up
- 24 MB (since a-e take up 4 bytes each), whereas Thomas's
- proposed 'void' type means only 4 MB would be needed.
- Quite a difference!
-
- Side note: As everybody knows, a similar size blowup occurs
- when small-size classes are given virtual methods, and those
- classes are used as data members in other classes. This is a
- good reason why not every class should have virtual methods.
-
- Of course, a zero-size data type is not "necessary" (only wins
- you some memory), but it might be useful, IMHO.
-
- --
- --------------------------------------------------------------------------
- | Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden |
- | Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490 |
- --------------------------------------------------------------------------
-