[Codepractice] Information using the data itself

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.