Differences between BPL and DLL files [translation]

Source: Internet
Author: User

[Original]

That is correct. a BPL is a DLL. (but not all DLLs are bpls .)

> But I still found some different, such as that I can create
> Object from the host EXE and that pass to a BPL and modify it safely,
> If I do same to a DLL, I can not modify any referenced property of the object.

When you use packages, There is only ever one copy of any unit in
Memory. One copy of forms, one copy of sysutils, one copy of System
(Well, most of it), one copy of stdctrls, etc.

All class-related operations, such as the "is" and "as" operators, rely
On class references. Class references are actually just addresses. They
Point to definitions for the layouts of the classes 'internals. (They
Point to what's called the virtual-method table, the VMT.) Two Classes
Are the same if they point to the same VMT -- if the addresses are equal.

When you have a class defined in the EXE's copy of stdctrls and the same
Class defined in a DLL's copy of stdctrls, those classes will really
Have different addresses. The "is" and "as" operators won't work
Cross-module clases. But when you use packages, there is only one copy
Of the class, kept in vcl70.bpl, so all modules that reference that
Package will share a single class definition.

Another factor is the memory manager in system. All string allocations
Ultimately call getmem and freemem. If the EXE allocates a string, it
Uses its own getmem. It then passes the string to a DLL, And the DLL
Might try to free it. The dll will call its own copy of freemem, which
Won't have access to the EXE's memory-manager structures, and you'll get
Errors. With packages, everything will use the same memory manager from
Rtl70.bpl. (This can also be solved by using a Shared Memory Manager
Between the EXE and the DLL; sharemem is one example. That won't solve
The class-comparison problem, though .)

Above, I said the major difference between bpls and DLLs is the number
Of exported functions. With a DLL, the only things exported are what
Appear in the "exports" clause that you write yourself. With a BPL,
Everything from all the units '"interface" sections gets exported,
Including global variables and class definitions. Also exported are
Addresses of the "initialization" and "finalization" sections. And,
Internally, that is indeed the major difference. a bpl exports
Functions necessary for the RTL to recognize the file as being a BPL and
Not just a generic DLL. If you call loadpackage, I will call loadlibrary
To load it like a normal DLL, and then it will call all the package's
Units 'initialization sections and do a Fe other housekeeping
Operations. Calling a package's functions generates the same kind
Extends er code as is generated when you call a DLL function.

[Translation]

Yes, BPL is a DLL, but not all of them are BPL.

> But I still found some differences, such,
> I can create an object in the main application, pass it to BPL, and then
> I can modify it safely. But if I use DLL, I cannot modify
> Reference the attributes of this object.

When packages is used, each unit, every form, every sysutils, and every system have only one copy in the memory,

All operators acting on classes, such as is and as, depend on class references. Class references are actually a (restricted) pointer, point to class definition (virtual function table VMT) If two references point to the same VMT, they are references of the same class.

If you use the same class defined in stdctrls in EXE and DLL, the VMT of these two classes has different addresses. The is and as operators cannot work correctly in different modules. However, if you use a package, there is only one copy of the class in the memory, which is saved in vcl70.bpl. All modules that reference the package will share the definition of the same class.
Another factor is the memory manager in the system unit. Getmem and freemem are called at the end of all string distribution. If the EXE is assigned a string, it uses its own getmem function copy. If it passes the string to the DLL, it is free in the DLL. The dll will call the copy of its own freemem function, and the freemem function cannot access the memory manager in the EXE, which produces an error. If you use packages, they all use the Memory Manager in rtl70.bpl. (This problem can also be solved by sharing a memory manager between the EXE and DLL. The shared memory is just an example. But it still cannot solve the problem between classes .)

In conclusion, I think the main difference between bpls and DLLs is the number of output functions. The only thing output with DLL is those specified with the exports keyword. In BPL, all the definitions in interfaces are output, including global variables and class definitions, and the addresses in initialization and finalization are also output. In addition, the DLL and BPL are indeed quite different. BPL outputs all functions that are required to identify a file as BPL rather than a DLL file. If you call loadpackage, I can also call loadlibrary to load it as a normal DLL, and then it will call the initializatin part of all units in packages and do some other housekeeping? . The assembly code generated when the function in the package is called is the same as the assembly code generated when the function in the DLL is called.

For the first time, the translation of articles is poor in many places.
I think this article is very good. I hope some experts who have time can translate it again. Thank you.

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.