Delphi memory allocation Stralloc New

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.