Search This Blog

Monday, March 20, 2023

C++ custom debugger view for VisualCode

you can add custom view  for debugger.

https://www.cppstories.com/2021/natvis-tutorial/

https://devblogs.microsoft.com/cppblog/debug-visualizers-in-visual-c-2015/

create into your root folder  xxx.natvis

make sure in the launch.json  to add

            "visualizerFile": "${workspaceFolder}/xxx.natvis",
            "showDisplayString": true,

more sample:

 https://learn.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2019

note:

the Name of the class must be full qualified e.g. contain namespace name if exist.

even typedef name should be act as new Name in the natvis file.

ty  

enjoy

Yaniv 

sample template class:

template<typename T> class MyObject
{
public:
    MyObject() : myVal( 5 ) {}
    T myVal;
};


sample template  natvis file:

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">

<Type Name="MyObject&lt;*&gt;">
  <DisplayString>{{myVal = {myVal}}}</DisplayString>
  <Expand>
    <Item Name="[myVal]">myVal</Item>
  </Expand>
</Type> 
</AutoVisualizer>

Sunday, March 12, 2023

C++ struct alignment - can save you memory

 the orders of members in a struct affect sizeof of struct 


see this example https://www.joshcaratelli.com/blog/struct-packing


if no compiler directive - memory align to 8 bytes by default

struct top

{

    char* p; //8 bytes

    int i;  //4 bytes

    short s; // 2 bytes

    char c;  // 1 byte

                    // 1 padding 

    int t; // 4 bytes

                    // 4 padding 

};

struct buttom

{

    char c; // 1 bytes -- 7 padding

    char* p; //8 bytes

    short s;  //2 bytes

    int i;   //4 bytes

               // 2 padding

    int t;  // 4 bytes 

               // 4 padding

        

};

    int sizeTop = sizeof(top);   // =>24

    int sizeButtom = sizeof(buttom); // =>32

Saturday, January 28, 2023

C++ performance - hardware

++

 very impressive guide 





read about 

Profile-guided optimization (PGO)  and WPO  -- its free compiler option that can boost your program.






Wednesday, January 25, 2023