Piles in VCLs and stacks

zhaozj2021-02-16  41

Stack (Stack) and Heap are common concepts in C | C , to learn C | C , we must also understand the differences and links between these two concepts. However, the VCL in BCB is written in Object Pascal. She has a lot of characteristics of Object Pascal. It is advisable to pay attention when using it, and I will write some views in this area for reference.

The stack is all the dynamic local variables and function calls and the returned information of the information. The stack of memory management strictly follows the advanced order, which is desirable to implement function calls. The allocation of memory is particularly high from the stack. The data object uses the memory in the stack (such as dynamic local variable) than the memory in use, makes the program faster.

Piles are a single memory for Malloc (), Calloc (), Realloc () and New. Get memory from the heap than much slower than from the stack, but the memory management of the stack is much flexible than the stack, you can get (or release) memory from the heap, we can do it in any order. The memory used to store recursive data structures is almost all from the heap. The memory used to store strings is usually acquired from the heap, especially for a long string that may appear when running.

The memory obtained from the heap is released with free (), delete, it is not automatically released.

Since all objects in Object Pascal can only be constructed in the heap, it cannot be the same as C , and the objects (objects created outside the function), the object outside the function), the stack (with new Waiting for functions to create a class of objects) Establish an object, so the object of the VCL class can only be created in the heap.

If you create a button object, we can create this:

TButton * btNmy = new TButton (null);

It can be written as the following: Class name * object name = new class name ();

() Inside can be the name of the object entity you have created, the name of the project, or null, or sometimes it is possible to still use the THIS pointer, this will be flexible in the application process.

But don't forget that BCB is the best support for C | C , in normal case, you can use the stacks and stacks.

转载请注明原文地址:https://www.9cbs.com/read-26028.html

New Post(0)