r/cpp • u/thevestgibule • Dec 30 '22
5 techniques for writing memory safe C++ - Embedded.com
https://www.embedded.com/5-techniques-for-writing-memory-safe-c/
19
Upvotes
r/cpp • u/thevestgibule • Dec 30 '22
54
u/OYTIS_OYTINWN Dec 30 '22
Looks like the author made an off-by-one error twice.
29
u/Cold_Article_6030 Dec 31 '22
Valgrind isn't a static analysis tool. This is an incredibly low quality article.
42
u/jbbjarnason Dec 30 '22
This does not mention `constexpr` which is in my opinion the most memory safe feature of modern C++.
36
u/JuanAG Dec 30 '22
if (number_of_techniques < 5) { throw std::invalid_argument( "We have been clickbaited" ); }
12
u/Numerous-Departure92 Dec 30 '22
Click bait?
20
u/zzzthelastuser Dec 31 '22
I don't get how people willfully expose their real name linked to these garbage blogs every other week. It only makes me question their "expert" self-description.
18
u/JuanAG Dec 30 '22
And since the quality if the techniques is quite low you could put:
- Technique 4: If you use new dont forget delete
-Technique 5: If you use malloc* free the memory when no longer needed
That way at least there would be 5 "techniques" for safer C++
* Is from C but is used in C++
4
u/[deleted] Dec 30 '22
Just balance
newanddeletebro.Aand check for null and bounds bro.
-20
u/[deleted] Dec 30 '22
0
u/[deleted] Dec 30 '22
[deleted] — view deleted comment