Smart Pointers in C++: unique_ptr, shared_ptr and weak_ptr Explained with Tested Code
How C++ smart pointers own memory, measured: what each one costs in bytes and allocations, why shared_ptr cycles leak, and which one to use where.
How C++ smart pointers own memory, measured: what each one costs in bytes and allocations, why shared_ptr cycles leak, and which one to use where.
The difference between malloc and calloc in C, with measured costs, realloc and free, four heap bugs caught by sanitizers, and C++ new and delete.
The same four members reordered went from 24 bytes to 16. A guide to struct syntax, what the compiler does with your layout, and why memcmp lies.
A double pointer in C stores the address of another pointer. See the memory diagram, the key use cases, and tested examples of int** and char**.
LRU and FIFO cache replacement in C, checked against Valgrind: a matrix walk that misses 100% of the time, and Belady’s anomaly.
Philips Guo at Stranford University has useful collection of C programming lessons which may be quite useful if you are
Unions in C explained with compiled examples: size and layout, type punning rules, tagged unions, and the C++ std::variant alternative.
int is not always 32 bits and long is not always 64. A measured reference to C types, their real sizes, and the conversions that catch people.
Eight memory errors that compile cleanly, which tools catch them, and the ownership habits that stop them: new and delete, RAII and smart pointers.
A unique_ptr is 8 bytes — exactly the same as a raw pointer. Pointers from declaration to ownership, with every claim compiled and measured.
A pointer is a variable that represents the location of a data item, such as a variable or an array element. Pointers are used frequently in C, as they have a number of useful applications. For example, pointers can be used to pass information back and forth between a function and its reference point. Pointers provide a way to return multiple data items from a function via function arguments to
be specified as arguments to a given function.
In this article, we’ll explore a curated set of programming tips to enhance your proficiency in C and C++. From optimizing performance to writing clean and maintainable code, these tips serve as guiding beacons for programmers. Let’s delve into the world of C and C++ and uncover the secrets that can transform your coding skills.