Debugger check for PBHeap

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Debugger check for PBHeap

Post by Deeem2031 »

pcfreak just showed me this nice code from fr34k to validate the PBHeap:

Code: Select all

Procedure ValidatePBHeap(LineNumber) 
  Protected StringHeap, MemoryHeap, InternalHeap 
  
  !extrn _PB_Memory_Heap 
  !extrn _PB_StringHeap 
  
  !mov eax, dword [_PB_MemoryBase] 
  !mov [p.v_InternalHeap], eax 
  !mov eax, dword [_PB_StringHeap] 
  !mov [p.v_StringHeap], eax 
  !mov eax, dword [_PB_Memory_Heap] 
  !mov [p.v_MemoryHeap], eax    
  
  If HeapValidate_(StringHeap, 0, 0) = 0 
    MessageRequester("Error", "String Heap invalid at Line: "+Str(LineNumber)) 
  EndIf    
  If HeapValidate_(MemoryHeap, 0, 0) = 0 
    MessageRequester("Error", "Memory Heap invalid at Line: "+Str(LineNumber)) 
  EndIf    
  If HeapValidate_(InternalHeap, 0, 0) = 0 
    MessageRequester("Error", "Internal Memory Heap invalid at Line: "+Str(LineNumber)) 
  EndIf 
EndProcedure 
 
Macro _validate 
  ValidatePBHeap(#PB_Compiler_Line) 
EndMacro
Now it would be even better to have the debugger check this. Maybe this will slow down the program too much if all heaps are checked every line but with a switch to enable/disable this feature all would be fine I guess.
irc://irc.freenode.org/#purebasic
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Yes, it would be dead slow with the check at every line, but there is also this:
msdn wrote:Validating a heap may degrade performance, especially on symmetric multiprocessing (SMP) computers. The side effects may last until the process ends.
http://msdn.microsoft.com/en-us/library ... S.85).aspx

Also, heap corruption errors don't happen that often, which is why i have been hesitating to add this as a debugger option.
quidquid Latine dictum sit altum videtur
Post Reply