Changeset 21454


Ignore:
Timestamp:
2010-01-14T18:46:45+13:00 (12 years ago)
Author:
ak19
Message:

Dr Bainbridge added the useful new method check_system_heap() for Windows which calls _heapchk. It's helpful in detecting memory related errors when these have weird and inexplicable effects and which the debugger cannot help in unravelling.

Location:
main/trunk/greenstone2/common-src/src/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/src/lib/gsdltools.cpp

    r18880 r21454  
    279279  return (i == 0);
    280280}
     281
     282
     283#if defined(__WIN32__)
     284// A very useful function to call to debug mysterious heap memory errors when
     285// their cause isn't clear in the Vis Studio debugger. Call it from various
     286// places of the code and narrow down the point at which the heap memory becomes
     287// corrupted. The title param can be the method this function is called from.
     288void check_system_heap(char* title)
     289{
     290  int heapstatus = _heapchk();
     291
     292  char message[1024];
     293
     294  switch (heapstatus) {
     295  case _HEAPOK:
     296    sprintf(message,"%s","OK - heap is fine");
     297    break;
     298  case _HEAPEMPTY:
     299    sprintf(message,"%s","OK - heap is empty");
     300    break;
     301  case _HEAPBADBEGIN:
     302    sprintf(message,"%s","ERROR - bad start of heap");
     303    break;
     304  case _HEAPBADNODE:
     305    sprintf(message,"%s","Error - bad node in heap");
     306    break;
     307  default:
     308    sprintf(message,"%s: %d","Unrecognized heap status",heapstatus);
     309  }
     310
     311  MessageBox (NULL, message, title, MB_OK);
     312}
     313
     314#endif
  • main/trunk/greenstone2/common-src/src/lib/gsdltools.h

    r17545 r21454  
    7373bool perl_ok (ostream &logout);
    7474
     75#if defined(__WIN32__)
     76void check_system_heap(char* title);
     77#endif
     78
    7579#endif
    7680
Note: See TracChangeset for help on using the changeset viewer.