Forum Replies Created
-
AuthorPosts
-
::
I likely won’t make it to the Q&A today as I may not be in range of Wifi at that time. Good news is that we are working to get the video out today. If you all subscribe to CppNorth’s YouTube channel you’ll be first to know when the video is out: https://youtube.com/channel/UCGWAlXciy785Iog-X7247Hw
::I am using gcc 11.3.0, rev 1 built by MSYS2 project.
It is very odd because when I compile this code in compiler explorer with gcc 11.3 I get 6 allocations and 4 deallocations as expected: https://godbolt.org/z/bK5z8vqb7
But when I compile the same exact code locally I get the output:
Number of allocations: 4Number of deallocations: 0If I add a definition of new[] I get:
Number of allocations: 6Number of deallocations: 0::For instance when I execute overloadNewAndDelete incluing myNew.hpp (modified with the addition of the definition of operator new[]) I get the output:
Number of allocations: 6Number of deallocations: 0
So the operator delete defined on myNew.hpp is not called.
Similarly when I include each one of myNew2.hpp, myNew3.hpp, myNew4.hpp the operator delete defined on the header is not called.
It’s as if the usual operator delete is called instead.
::Update: The two calls to the overriding new that I am missing are the calls to new []. I added a definition for new [] in myNew.hpp and now I see those calls and the count is 6. The solution with the macro does override new and I get the output corresponding to 6 calls to the overriding new. With all the myNew header options the overriding delete is not called.
-
AuthorPosts