design - Volatile polymorphism (?) in gnu C++ -


i have raw binary dump of assembler split blocks (code, data, ignored, images etc). have walker increments position via virtual ++ operator. if it's in data block, moves 32 bytes, code number of bytes in instruction, ignored moves size of block etc. when reaches end of block, needs "transform" walker type of next block while keeping data, data pointer, block lookup etc.

there ways using switch statements, array of objects pointing same base etc wondering if there's better way? somehow transform derived object different object same physical base class?

can transform derived object different derived object same physical base class?

no, far less of issue you'd expect. if have derived1 first; on stack, makes no sense try change first derived2. however, there's no real polymorphism happening. polymorphism works magic when have base* second; points @ derived object. , 99% of time, that's going allocated on heap. can create new derived2 copies shared data *second, , make second point @ new derived2, , delete original pointee. obviously, use smart pointers.

so, apply this, "walker" class (which should iterator, think), contain std::unique_ptr<implementationbase> impl; points thing tells how advance.

however, virtual indirection comes @ performance penalty, , requires heap allocation unless confusing tricks. it's slower switch, takes more memory switch, takes more code switch, it's more confusing switch.... use switch.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -