Remix.run Logo
inglor_cz 12 hours ago

Symbian's way of avoiding this was to use a class called CBase to derive from. CBase would memset the entire allocated memory for the object to binary zeros, thus zeroizing any member variable.

And by convention, all classes derived from CBase would start their name with C, so something like CHash or CRectangle.

jenadine 10 hours ago | parent [-]

I'm afraid that's still not defined behaviour in many case. For example, pointer and bool can be initialized with `=0`, but that doesn't mean the binary representation in memory has to be 0, and so initializing with memset would still be wrong. (Even if it works with all compilers I know of.)

Also, how does CBase knows the size of its allocated memory?

ksherlock 7 hours ago | parent [-]

The symbian source code is available. Looks like it uses a class-specific operator new() overload.

https://github.com/SymbianSource/oss.FCL.sf.os.kernelhwsrv/b...

2. Initialisation of the CBase derived object to binary zeroes through a specific CBase::operator new() - this means that members, whose initial value should be zero, do not have to be initialised in the constructor. This allows safe destruction of a partially-constructed object.