Click here to Skip to main content
14,360,852 members

C / C++ / MFC

 
GeneralRe: Dialog box margins Pin
leon de boer22-Feb-19 6:39
memberleon de boer22-Feb-19 6:39 
GeneralRe: Dialog box margins Pin
Maximilien23-Feb-19 2:49
memberMaximilien23-Feb-19 2:49 
GeneralRe: Dialog box margins Pin
leon de boer23-Feb-19 5:30
memberleon de boer23-Feb-19 5:30 
AnswerRe: Dialog box margins Pin
leon de boer22-Feb-19 6:37
memberleon de boer22-Feb-19 6:37 
GeneralRe: Dialog box margins Pin
Alexander Kindel22-Feb-19 10:04
memberAlexander Kindel22-Feb-19 10:04 
GeneralRe: Dialog box margins Pin
leon de boer22-Feb-19 11:00
memberleon de boer22-Feb-19 11:00 
SuggestionRe: Dialog box margins Pin
David Crow24-Feb-19 17:23
memberDavid Crow24-Feb-19 17:23 
QuestionTraceability of Dynamic Memory Allocation Faults Pin
HS_C_Student16-Feb-19 23:24
memberHS_C_Student16-Feb-19 23:24 
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:

StartScope(foobar)
CreateObj(data)
Do work;;;
FreeObj(data)
EndScope(foobar)

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?
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
leon de boer17-Feb-19 21:53
memberleon de boer17-Feb-19 21:53 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
Stefan_Lang18-Feb-19 1:15
memberStefan_Lang18-Feb-19 1:15 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
jschell23-Feb-19 11:41
memberjschell23-Feb-19 11:41 
QuestionCeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 1:23
memberMember 1271142615-Feb-19 1:23 
AnswerRe: CeratingNameePipe Server Application Using C++ Classes Pin
Victor Nijegorodov15-Feb-19 2:03
memberVictor Nijegorodov15-Feb-19 2:03 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 5:53
memberMember 1271142615-Feb-19 5:53 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Richard Andrew x6415-Feb-19 14:48
professionalRichard Andrew x6415-Feb-19 14:48 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Victor Nijegorodov15-Feb-19 14:53
memberVictor Nijegorodov15-Feb-19 14:53 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Richard Andrew x6415-Feb-19 15:11
professionalRichard Andrew x6415-Feb-19 15:11 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Victor Nijegorodov15-Feb-19 15:18
memberVictor Nijegorodov15-Feb-19 15:18 
AnswerRe: CeratingNameePipe Server Application Using C++ Classes Pin
Richard MacCutchan15-Feb-19 4:18
protectorRichard MacCutchan15-Feb-19 4:18 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 5:55
memberMember 1271142615-Feb-19 5:55 
QuestionWants guidance. Pin
Member 1415146015-Feb-19 0:46
memberMember 1415146015-Feb-19 0:46 
AnswerRe: Wants guidance. Pin
CPallini15-Feb-19 2:45
mveCPallini15-Feb-19 2:45 
QuestionSelected Row while updating in CListCtrl in MFC Pin
Anu_Bala13-Feb-19 23:29
memberAnu_Bala13-Feb-19 23:29 
AnswerRe: Selected Row while updating in CListCtrl in MFC Pin
Victor Nijegorodov14-Feb-19 2:24
memberVictor Nijegorodov14-Feb-19 2:24 
QuestionHow to resolve: error LNK2001: unresolved external symbol "public: static void * Pin
mlong3013-Feb-19 21:10
membermlong3013-Feb-19 21:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.