Do not use global variables when writing the gstreamer plug-in!
Source: Internet
Author: User
Global variables cannot be used when writing gstreamer elements. Because the element may be created in a process, for example, multiple queue may exist in a pipeline. Put all these variables into the class of the element and use them as member variables. If a process uses multiple elements, multiple gobjects are created. Therefore, multiple member variables are generated. If it is written as a global variable, all objects will share one, and problems will occur. (In fact, it is better to regard gobject as a structure. Multiple gobjects have multiple structures in the memory, so the member variables will not conflict. And the global variable always has only one copy ).
I have also written code to study the global variables in the dynamic library. When a dynamic library is loaded by multiple programs, there is only one dynamic library in the memory. When multiple programs are used at the same time, will the global variables in the dynamic library be faulty? The answer is no, because each program (process) in the Data Segment of the dynamic library is independent, and the code segment may be shared. The global variables in the dynamic library are the copy-on-write mechanism. Once a write operation is performed, a new copy is created.
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