System. getmem, system. freemem-apply for and release memory

Source: Internet
Author: User
If only one pointer is allocated memory, it is the same as new and dispose. The difference is that getmem can apply for multiple consecutive memory blocks.

Example:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formcreate (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} type tmyrec = record {definition structure} Name: String [8]; age: word; end; pmyrec = ^ tmyrec; {definition structure pointer} var PR: pmyrec; procedure tform1.formcreate (Sender: tobject); begin {three structures of memory are allocated at the same time; the three structures in the memory are sequential} getmem (PR, sizeof (tmyrec) * 3); {at this time, PR points to the first structure, with a value assigned to} PR. name: = 'zhang san'; PR. age: = 11; {point PR to the second structure, value assignment} Inc (PR); PR. name: = 'Li si'; PR. age: = 22; {point PR to the third structure, value assignment} Inc (PR); PR. name: = 'wang 5'; PR. age: = 33; {first return to the first structure, and then read} Dec (PR, 2) in sequence; showmessage (format ('% S % d', [pr. name, PR. age]); {Zhang San 11 years old} Inc (PR); showmessage (format ('% S % d', [pr. name, PR. age]); {Li Si 22 years old} Inc (PR); showmessage (format ('% S % d', [pr. name, PR. age]); {Wang Wu 33 years old} {clear the memory of the three structures from the first structure, so that the above three structures are deleted} Dec (PR, 2 ); freemem (PR, sizeof (PR ^) * 3); {sizeof (tmyrec) and sizeof (PR ^) are the same} end; end.
 
   
 

Public Function directory under System Unit

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.