/* * Memory Leak Debug Magic */ /* * Returns ptr + ofs as an int * */ int * ::+( int *ptr1, int ofs ) { int *ptr2 = ptr1 ptr2+=ofs return ptr2 } /* * Returns value at *(ptr + ofs) as an int * */ int * ::@( int *ptr, int ofs ) { int ad = *(ptr + ofs) int *ptr2 = addr_( ad ) return ptr2 } /* * Returns value at *(ptr + ofs) as an int */ int ::%( int *ptr, int ofs ) { int ad = *(ptr + ofs) return ad } /* * Print functions */ void printHexNibble( int nibble ) { print charOf( nibble + (nibble < 10 ? intOf('0') : intOf('A') - 10 ) ) } void printHexByte( int byte ) { printHexNibble( ( byte & 0xF0 ) / 16 ) printHexNibble( byte & 0x0F ) } void printHexWord( int word ) { printHexByte( (word / 0x1000000 ) & 0xFF ) printHexByte( (word / 0x0010000 ) & 0xFF ) printHexByte( (word / 0x0000100 ) & 0xFF ) printHexByte( (word ) & 0xFF ) } void printHexAddress( int * ptr ) { printHexWord( (int addr_( ptr ) ) ) } void printMemHexWord( int * address, int size ) { int i for( i = 0; i < size; i++ ) { printHexWord( address % (i*4) ) print "\n" } } /* * Gets point to DXL Context from a temporay dialog box */ int * getContextPointer() { DB x = create( "" ) int *p = addr_( x ) int *r = p @ 48 destroy( x ) return r } /* * Gets allocation list pointer from context pointer */ int * listHead( int * contextPtr ) { int * rv = contextPtr @ 0x74 return rv } int *listNext( int * listElement ) { int * rv = listElement @ 8 return rv } int * contextPtr = getContextPointer() print "ContextPtr: " printHexWord( (int addr_(contextPtr) ) ) print "\n\n" void allocatedObjects() { int cnt = 0 print "Allocation List (cnt->list element address->object address):\n" // Get first element on allocation list int *listElement = listHead( contextPtr ) while(!null( listElement ) ) { print " LE->" print cnt "" print "->" printHexAddress( listElement ) print "->" printHexWord( listElement % 4 ) print "\n" //Get next element on allocation list listElement = listNext( listElement ) cnt++ } print "Allocated Objects: " print cnt "" print "\n" } void dumpAllocatedObjects( int size ) { int cnt = 0 print "Dump Allocated Objects\n" // Get first element on allocation list int *listElement = listHead( contextPtr ) while(!null( listElement ) ) { print " LE->" print cnt "" print "->" printHexAddress( listElement ) print "->" printHexWord( listElement % 4 ) print "\n" print " content:\n" printMemHexWord( listElement @ 4, size ) print "\n\n" //Get next element on allocation list listElement = listNext( listElement ) cnt++ } print "Allocated Objects: " print cnt "" print "\n" } print "Start\n" allocatedObjects() print "\n" DB boatBox = create( "Craft" ) print "DB created at: " printHexAddress( addr_( boatBox ) ) print "\n\n" allocatedObjects() print "\n" string boats[] = {"Dinghy", "Destroyer", "Carrier", "Mine sweeper"} void toBuild(DBE option) { int favorite = get( option ) ack(boatBox, "You are planning a new " boats[favorite] "?") } print "toBuild callback function address: " printHexWord(int addr_( toBuild ) ) print "\n\n" DBE boatCheck = radioBox(boatBox, "Select class:", boats, 3) print "boatCheck DBE created at: " printHexAddress( addr_( boatCheck ) ) print "\ncall back block address (base+48)->" printHexWord( addr_(boatCheck) % 48 ) print "\n\n" DBE boatCheck2 = radioBox(boatBox, "Select class:", boats, 3) print "boatCheck2 DBE created at: " printHexAddress( addr_( boatCheck2 ) ) print "\ncall back block address (base+48)->" printHexWord( addr_(boatCheck2) % 48 ) print "\n\n" print "pre-set DBE callback functions\n" allocatedObjects() print "\n\n" set( boatCheck, toBuild ) set( boatCheck2, toBuild ) print "post-set DBE callback functions\n" allocatedObjects() print "\n\n" print "boatCheck DBE after callback set: " printHexAddress( addr_( boatCheck ) ) print "\ncall back block address (base+48)->" printHexWord( addr_( boatCheck ) % 48 ) print "\n\n" print "boatCheck2 DBE after callback set: " printHexAddress( addr_( boatCheck2 ) ) print "\ncall back block address (base+48)->" printHexWord( addr_( boatCheck2 ) % 48 ) print "\n\n" print "pre-block\n" allocatedObjects() print "\n" block( boatBox ) print "Dialog Box Closed\n\n" allocatedObjects() print "\n\n" destroy( boatBox ) print "DB destroyed:\n" allocatedObjects() print "\n\n" dumpAllocatedObjects( 2 )