Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
Forget it. Mark and Release are very DOS, real mode functions. Use New/Dispose or GetMem/FreeMem instead and make proper control of dynamically allocated blocks. Dmitriy Pomerantsev. 19.06.2014, 14:50, mokashe.ram mokashe@gmail.com: Hi, Can any one help me on raplacement of MARK and RELEASE function in free pascal... var markexam: pointer; // untyped pointer begin ... * mark(markexam); . Release(markexam);* end; Thanks, Sud -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/replacement-of-MARK-and-RELEASE-function-in-free-pascal-tp5719624.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
In our previous episode, mokashe.ram said: Can any one help me on raplacement of MARK and RELEASE function in free pascal... var markexam: pointer; // untyped pointer begin ... * mark(markexam); . Release(markexam);* end; This eighties style of memory management has no 1:1 substitutions. Reengineer your memory management on top of getmem and freemem. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
Ok thanks, but using untyped pointer how to mention size in GETMEM()? * GETMEM(markexam,'' );* Thanks Sudarshan -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/replacement-of-MARK-and-RELEASE-function-in-free-pascal-tp5719624p5719626.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
In our previous episode, mokashe.ram said: Ok thanks, but using untyped pointer how to mention size in GETMEM()? * GETMEM(markexam,'' );* You misunderstood. You don't substitute getmem/freemem (or new/dispose) of just the markexam pointer, but for ALL pointers allocated between mark and release statements. So basically you must delete the mark, release and markexam declaration lines, and make sure that every allocated pointer is freed (-gh can help with that). Mark/release save/restore the stack top which allowed a release to release all dynamically allocated memory since the last mark on that pointer. This option (even the principle) is not available anymore in modern memory managers. Mark and release were already declared legacy in Turbo Pascal versions from the early nineties. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
Hi, On Thu, 19 Jun 2014, mokashe.ram wrote: Ok thanks, but using untyped pointer how to mention size in GETMEM()? * GETMEM(markexam,'' );* It's detailed in the documentation, it's detailed there along with the rest of the memory management functions, please refer to that: http://www.freepascal.org/docs-html/rtl/system/getmem.html So either you use mypointer:=GetMem(size); or GetMem(mypointer, size); both are valid. If you need to allocate heap space for a record, use New/Dispose, or GetMem(myptr, sizeof(Tmyrecord)); This changed little since the times of Turbo Pascal, works the same way. Charlie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
Ok Thanks, Karoly -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/replacement-of-MARK-and-RELEASE-function-in-free-pascal-tp5719624p5719629.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
On 19.06.2014 13:29, Karoly Balogh (Charlie/SGR) wrote: So either you use mypointer:=GetMem(size); or GetMem(mypointer, size); both are valid. If you need to allocate heap space for a record, use New/Dispose, or GetMem(myptr, sizeof(Tmyrecord)); I wouldn't use GetMem() in case of record pointers just in case a managed type happens to be in there. Unlike GetMem() New() does initialize those fields correctly. Alternatively one should use Initialize(myptr^) after the call to GetMem(). Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
On Thu, Jun 19, 2014 at 03:28:42PM +0200, Sven Barth wrote: On 19.06.2014 13:29, Karoly Balogh (Charlie/SGR) wrote: So either you use mypointer:=GetMem(size); or GetMem(mypointer, size); both are valid. If you need to allocate heap space for a record, use New/Dispose, or GetMem(myptr, sizeof(Tmyrecord)); I wouldn't use GetMem() in case of record pointers just in case a managed type happens to be in there. Unlike GetMem() New() does initialize those fields correctly. Alternatively one should use Initialize(myptr^) after the call to GetMem(). I seem to remember being warned in the old days of Turbo Pascal not mix use of getmem()/freemem() and new()/dispose() within a program, due to differences in the memory allocation strategies. Are there still any compatibility or efficiency/performance issues with alternating between these two families, or can the most simple or appropriate call be used interchangeably? In other words, now that objects are so much more prevalent in Pascal code, should getmem() and freemem() be avoided? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
Hi, On Thu, 19 Jun 2014, joha...@nacs.net wrote: I seem to remember being warned in the old days of Turbo Pascal not mix use of getmem()/freemem() and new()/dispose() within a program, due to differences in the memory allocation strategies. Are there still any compatibility or efficiency/performance issues with alternating between these two families, or can the most simple or appropriate call be used interchangeably? In other words, now that objects are so much more prevalent in Pascal code, should getmem() and freemem() be avoided? Not in Free Pascal at least. In FPC New/Dispose are inline functions generated by the compiler (because they need to do other things aside the memory allocation), but the memory handling part internally just wraps to GetMem and FreeMem. (See pinline.pas, new_dispose_statement() in the compiler sources for all the dirty details.) However, while mixing New/Dispose with GetMem/FreeMem in the same code shouldn't have any ill. effects, you still should *not* mix New/Dispose on the *same* pointer I think. (Eg. allocate with New, but free with FreeMem, and so on.) Charlie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] replacement of MARK and RELEASE function in free pascal
On 19.06.2014 16:37, joha...@nacs.net wrote: On Thu, Jun 19, 2014 at 03:28:42PM +0200, Sven Barth wrote: On 19.06.2014 13:29, Karoly Balogh (Charlie/SGR) wrote: So either you use mypointer:=GetMem(size); or GetMem(mypointer, size); both are valid. If you need to allocate heap space for a record, use New/Dispose, or GetMem(myptr, sizeof(Tmyrecord)); I wouldn't use GetMem() in case of record pointers just in case a managed type happens to be in there. Unlike GetMem() New() does initialize those fields correctly. Alternatively one should use Initialize(myptr^) after the call to GetMem(). I seem to remember being warned in the old days of Turbo Pascal not mix use of getmem()/freemem() and new()/dispose() within a program, due to differences in the memory allocation strategies. Are there still any compatibility or efficiency/performance issues with alternating between these two families, or can the most simple or appropriate call be used interchangeably? In other words, now that objects are so much more prevalent in Pascal code, should getmem() and freemem() be avoided? I think even back then it was meant that you shouldn't freemem() memory allocated with new() and vise versa. Nevertheless in FPC you are free to use whatever you deem suitable (and afterall there are situations when you *can't* use a new(), namely on untyped pointers) the only thing you should keep in mind is that you should dispose() memory allocated by new() and freemem() memory allocated getmem(), but no mixing on the same pointer. It *might* work (and indeed if the type pointed to doesn't contain managed types it will in fact be the same), but we do not guarantee anywhere that it will stay that way. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal