replacement of MARK and RELEASE function in free pascal

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

replacement of MARK and RELEASE function in free pascal

mokashe.ram
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
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

Marco van de Voort
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

Дмитрий Померанцев
In reply to this post by mokashe.ram
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" <[hidden email]>:

> 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  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

mokashe.ram
In reply to this post by Marco van de Voort
Ok thanks,

   but using untyped pointer how to mention size in GETMEM()?
   
      GETMEM(markexam,'' ....");     

Thanks
Sudarshan
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

Marco van de Voort
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

Karoly Balogh (Charlie/SGR)
In reply to this post by mokashe.ram
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

mokashe.ram

Ok Thanks, Karoly
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

Sven Barth-2
In reply to this post by Karoly Balogh (Charlie/SGR)
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

JohannS-2
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

Karoly Balogh (Charlie/SGR)
Hi,

On Thu, 19 Jun 2014, [hidden email] 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: replacement of MARK and RELEASE function in free pascal

Sven Barth-2
In reply to this post by JohannS-2
On 19.06.2014 16:37, [hidden email] 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal