On Mon, 5 Apr 2010, Jonas Maebe wrote:
On 05 Apr 2010, at 19:13, John L. Ries wrote:
The other day, I compiled a unit I wrote several years ago under FPC and got the following warning:
queues.p(101,37) Warning: use of NEW or DISPOSE for untyped pointers is meaningless
The same unit compiles under GPC (20070904) without warnings. My question is: does GPC properly deallocate memory in such a case, or is the DISPOSE request ignored?
Note that FPC also frees memory in this case. It's just that new() and dispose() a) are supposed to be used in pairs, but since new(pointer) does not really make sense (FPC translates it into getmem(p,0) in TP and Delphi modes) FPC also consider dispose(pointer) to be inadvisable b) have extended functionality besides freeing memory (such as calling constructors/destructors with TP-style objects, and initialising/finalising structured types that contain reference-counted elements). This extra functionality can however only be activated by the compiler if it knows what the pointer points to, which is not the case when you dispose an untyped pointer.
FPC therefore considers calling freemem(untyped pointer) preferable to calling dispose(untyped pointer).
Also useful to know... Thanks.
Since the unit in question is supposed to work with whatever data type is thrown at it (it is intended to be generic set of queuing routines), I have no immediate plans to change it to accomodate FPC, but I will keep this information in mind for future work. I'm just starting to work with FPC, but even though I'm a former Borland cultist, I think I like GPC better (though each compiler has its own strengths and weaknesses).
--------------------------| John L. Ries | Salford Systems | Phone: (619)543-8880 x107 | or (435)867-8885 | --------------------------|