Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!att!cbnewsl!dog From: dog@cbnewsl.ATT.COM (edward.n.schiebel) Newsgroups: comp.lang.c++ Subject: Re: Objectifying contents read in from disk Message-ID: <1228@cbnewsl.ATT.COM> Date: 24 Jul 89 19:14:19 GMT References: <7316@athertn.Atherton.COM> Distribution: usa Organization: AT&T Bell Laboratories Lines: 32 From article <7316@athertn.Atherton.COM>, by thanh@athertn.Atherton.COM (Thanh Diec): .. stuff deleted > Writer: > > // write out an array of 1024 objects > > write(fd, &object_array[0], sizeof(class1) * 1024); > > > Reader: > > read(fd, buf, sizeof(class1) * 1024); > > class1 *p1 = (class1 *)buf; > > // buf is not ready to used as objects yet, must set runtime values > // such as _vptr's > In our project, each class that may need to have instances read and write themselves have read and write member functions which read and write the member data. On a read, the application creates an instance, then calls the read function to fill it up. There are a couple of small problems: - this is not as fast as a block read like your example, but then it doesn't need vptr fixing. - the object may have to output small headers ahead of some member data as a type field if the data is a pointer to a base class which may actually pont to a derived class object. If this is true, the object needs to know what type to create to call the proper reader. Ed Schiebel