For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
My problem is that as I write larger and more complicated (C) programs, errors in manual memory management become much harder to find and more catastrophic, particularly if caused by memory corruption.
I'd like to detect any DMA related errors as quickly as possible perhaps only when a debug flag is #defined.
I pass a pointer to a pointer to the create and destroy object functions. Create will fail if a pointer to non NULL memory is passed which prevents doubly allocating.
I am thinking of storing pointers to all allocated objects in a balanced BST, which would enable me to tell if a pointer is valid before free()in it. After Free() I can write NULL to prevent it's use and to prepare it for allocation again.
Any function that wants to check if an object pointer is valid can then call a check of the BST inventory.
Further I was thinking of tagging each entry with a scope of some sort so that I can check for missed Free() as soon as the object is no longer used:
That way I can check at EndScope that all foobar scoped objects were freed.
This would enable me to make objects that were dynamically allocated have a stack based/automatic scope for example, if they are not going to be used after the function exits.
If using scopes for 'automatic' object allocation and nesting them in a stack, an error can be detected if a higher level scope is ended before a lower one.
These mechanisms are all intended to trigger errors as quickly as a problem can be detected and before it worsens. And furthermore to do so with the most minimal burden on the user.
I couldn't find a standard practice because garbage collection does not seem to be the same concept as detecting errors in memory management.
Is this good? Is there a better way of doing it / standard practice?
When you code reaches a certain complexity you have to stop and implement test benches on each unit file .. I take it you are not doing so.
At the moment you are treating the symptoms not the cause.
Put simply your
Should be known to work bug free because it passes your benchtest unit with clear use guideline API
One of the things writing the bench test unit does is makes you stop and think about possible errors because you try to bench test the errors.
Your bench test code should obviously include malloc failing and all memory writes should be checked for size in the benchtest. So put bluntly
your code is failing because you are failing to test properly.
For even larger projects especially if threaded it often becomes necessary to use a MOCK framework to actually cross test the units together.
Typical test frameworks are listed in the C section of List of unit testing frameworks - Wikipedia[^]
The more common ones are CMock, Ceedling and Unity.
Many memory problems come from inherent issue with pointers that lets you copy the reference to an allocated object without restriction, but then doesn't let these references track when someone deletes it. Neither indirection nor garbage collection can solve that. Instead, use smart pointers!
Smart pointers behave for the most part like normal pointers, but they also make sure that the allocated objects get released when they are no longer referenced. And not earlier!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
Hi, I'm new to Socket Programming, I don't know how to create a NamedPipe Server and Client Application, Here My requirement is below
1.) Create multithreaded pipe server and pipe Client inter-process sample application VC++/MFC.
2.) Transfer unsigned Char arr dummy bytes to and fro pipe client.
3.) Result display in printf both side.
By using VC++ or MFC Classes,
I have CListCtrl and updating this control with love data using OnTimer(). But i want to select some rows and do furthur actions. But when i select the row, the selected color appears,but moment it updating using OnTimer(), the selected row color become normal. How can i keep the selection row visible always?
(and so on...) in your test.cpp source file.
An altrernative, available only with C++ 17 compliant compilers is to declare such variables inline inside the header file (see, for instance INLINE VARIABLES[^]).