Re: [Dev-C++] Copy Constructors and Overloaded Assignment Operators
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Matthew H. <mhi...@sy...> - 2002-07-22 21:37:21
|
Hello, Abhijit Shylanath wrote: >>Now, speaking of class members, how would you persist state? >> >>In VB (the realm I come from... well, there was Pascal those many >>years ago 8-), I would use a Type (read struct) to hold my data. >>This allows for quick memory copies to restore defaults/back out >>changes... In C++ I can also see it making serialization a little >>easier (convert to a char array/string and dump to disk). >> >> > >This isn't always portable, since many compilers use memory alignment to >optimize access... Consider this: > > Yeah, I'd forgotten about that. I don't worry about portability that much (my primary language being proprietary). Time to change my thinking. But, is it safe to say that everything should be okay if this methodolgy is used for in-memory state maintenance? (Unless I start sharing memory across platforms, I suppose... which isn't extremely likely to happen...8-) >64-bit compiled program. A more portable way to persist is methods such as >saveToDisk() and loadFromDisk(), which read and write each member. This way >you can also change the read/write method to suit the platform... on >Windows, it can use the registry, on Linux the home dir, on DOS a config >file, etc. You could also interface to classes like FooWriter and FooReader, >to which you can pass the struct/class as an argument. > > Use conditional compilation? (#ifdef, etc.) How worried are people about bit problems (i.e. endian-ness cross platform, like Intel to PowerPC). I'd never really stopped to think about it until it came up ... I forget where now, but it was an interesting point. >Hope this helps. > > Yup. My favourite part of lists like this is to throw something out and see how the community at large responds. It usually points out weaknesses, and alternatives. It's always good! 8-) Thanks! |