Source: Delphi Memory allocation Stralloc New
Citation: http://anony3721.blog.163.com/blog/static/5119742010824934164/assigns memory to character pointers (PChar, Pwidechar, Pansichar), and the best choice is: Stralloc.
Stralloc, although eventually called Getmem, Stralloc will add 4 management bytes (record length) required by Delphi in front of the pointer.
Stralloc allocated memory, released with Strdispose, with Strbufsize to get the size.
Can you release it with Freemem? This frees up 4 bytes less.
This type of pointer is typically used for parameters of API functions, such as getting the window caption:
Var
Begin
P: = Stralloc (256);
GetWindowText (Handle, P, Strbufsize (p));
{Form1}
Strdispose (P);
End
There are also a couple of very important related functions: Globalallocptr, globalfreeptr; Their function is above these are irreplaceable!
Try to use GetMemory instead of Getmem.
3, the New corresponding Dispose can also be replaced with Freemem or freememory.
Try to use Freememory to release memory allocated by Getmem, GetMemory, AllocMem, Reallocmem, Reallocmemory.
Reallocmem, Reallocmemory is allocated memory on the basis of the reallocation of memory, it is almost reallocmemory more than reallocmem a nil judgment, try to use Reallocmemory bar.
Delphi memory allocation Stralloc New (GO)