Sum
If a message is contained in the data, then even if the message is to be read thanks to two lines of code, it should be used directly instead of through memory to obtain and maintain consistency.
This is more concise and more scalable.
However, the memory mode will bring a qualitative change of mental burden and error probability after the amount of code reaches a certain level.
Details
One mistake that occurred yesterday was to make a mistake with the size of the render target.
The realization of itself is roughly like this:
//configRenderTargetSize size;xxxxSize size0;xxxxSize size1;//initRenderTarget* rt = CreateRenderTarget(size.x, size.y, format);//in another functionvector<u16> data;data.resize(size.x*size.y);//then read data
There is no problem from a simple example, but if the number of size is more than a certain amount, it can be very error-prone.
I was in the middle of it.
The result uses a different size that has a very similar meaning.
Finally, you need to debug for some time.
The real neat approach is to take the relevant size and format information directly from the RenderTarget, and to be more extensible in design.
This use of a similar convention, I know what the time of initialization, it will make code implementation error prone, maintenance costs are high.
Similar to the following:
std :: vector <char ; A; //this is error prone and the type itself is in a, memorize out is not good printf ( "size%d" , A.size () *sizeof (char )"); //it's much better to do it by type template <class t>u32 vectormemsize ( Span class= "Hljs-keyword" >const std :: vector <t> & V) {return sizeof (T) *v.size (); printf ( "size%d" , Vectormemsize (a));
So you should directly use the information directly contained in the data, rather than through memory and other means to ensure consistency.
Memory mode will bring a qualitative change of mental burden and error rate after the code reaches a certain level.
[Codepractice] Information using the data itself