Article View: comp.os.os2.programmer.misc
Article #178Re: /Tm option weirdness in Visual Age C++
From: wkovsky
Date: Tue, 28 Nov 1995 00:00
Date: Tue, 28 Nov 1995 00:00
55 lines
3230 bytes
3230 bytes
In <497r8m$kdi@cpcug.org>, kbennett@cpcug.org (Keith Bennett) writes: >Recently I issued a request for help for a program that was aborting >before even reaching main. I managed to make the problem go away, >but I don't know whether I've really addressed its cause or just >removed a symptom. > >I'm using Visual Age C++ with the most recent fixes. > >The executable used a home grown DLL. The DLL's object files were >compiled using /Tm, but the executable's were not. When I added the >/Tm option to their compile, the problem disappeared. > >Then we asked ourselves what would happen if the situation were >reversed, if the DLL was compiled without the /Tm, but the EXE was >compiled with it. We tried it, and the program aborted before >main().! > >I can't believe that this would be a general rule, as it is not >reasonable to expect that third party DLL's be compiled with /Tm. > >So, this problem must be masking another problem. That is, there's >probably some error in our code that's causing this to happen. > >Any thoughts on this? Thanks much. >- Keith > >-- >-------------------------------------------------------------------------- >Keith Bennett Bennett Business Solutions, Inc. >Silver Spring, MD USA OS/2 & DOS Software Development >kbennett@cpcug.org (301) 871-7696 Hello, Keith! When you use the /Tm option with VA C++, you are actually replacing some of the memory management modules. The new modules will add some data to the beginning and end of each block of memory you allocate, where they will store such information as the original size of the memory block, the address in your program from which it was allocated, and some additional information (such as checksums and data patterns to detect if you overwrite memory immediately before or immediately after this memory block's boundaries). The memory address returned to your own program is the address at which your data block actually starts; that is, the added header and trailer is "invisible" to your program. So, a program compiled with /Tm+ is fundamentally incompatible with a DLL compiled with /Tm- (and vice-versa). For example, if you call free() from a program compiled with /Tm+, the function will "back up" from the address you passed, to find the added header, and will add the length of that added header plus the trailer, and delete THAT block of memory. Obviously, if you are calling a DLL that allocated that block of memory via the "normal" memory management functions, there IS no header or footer for the memory block -- a recipe for trouble! Hope this helps!
Technical Details
Message-ID:
<49dk6r$ljt@shiva.usa.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<497r8m$kdi@cpcug.org>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11307a,a3ef8aae153403e1,start X-Google-Attributes: gid11307a,public X-Google-Thread: 10cd94,a3ef8aae153403e1,start X-Google-Attributes: gid10cd94,public From: wkovsky@colos2.com Subject: Re: /Tm option weirdness in Visual Age C++ Date: 1995/11/28 Message-ID: <49dk6r$ljt@shiva.usa.net> X-Deja-AN: 120209806 references: <497r8m$kdi@cpcug.org> organization: ColoradOS/2 reply-to: wkovsky@colos2.com newsgroups: comp.os.os2.programmer.misc,bit.listserv.os2-l