[fpc-pascal]StrAlloc and StrDispose of pChars and the like
jonas at zeus.rug.ac.be
Wed Nov 14 19:05:13 CET 2001
On woensdag, november 14, 2001, at 05:28 , Cox, Stuart SRM:EX wrote:
> If one is to create pChars you really need to allocate an array of char
> like the example that Borland supplies with the introduction to pChars
> the BP7 manual. They don't mention any invisible allocation word as
> part of their implementation.
FPC doesn't use an invisible word specifically for pchar's either
(whether you allocate the memory with stralloc, getmem or whatever),
because every heap block itself already contains information about its
length. Further, the only thing stralloc does is call getmem with the
same argument it received.
strdispose(p) is simply a wrapper for
if assigned(p) then
p := nil;
The freemem call without a second parameter comes originally from Delphi
and lets the heap manager find out how much memory was allocated to that
pointer and release it.
To change the amount of memory allocated to a pointer (a pchar is a
pointer to a char, so it works for those just as well), you can use
reallocmem(p,new_size). And you can still use strdispose() later on...
More information about the fpc-pascal