Multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter verification
Through the multi-cache and type fingerprint dynamic execution method of flexible drive power meter verification, the resource management, type safety and thread synchronization problems of dynamic link libraries in high concurrency scenarios are solved, and efficient and stable dynamic library calls are achieved.
Patent Information
- Application Number
- CN202510511222.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2045-04-23
AI Technical Summary
The existing dynamic link library (DLL) has problems such as resource lifecycle management failure, type safety mechanism missing and thread synchronization performance deterioration in high concurrency and high reliability scenarios, resulting in system stability and inefficiency.
The multi-cache and type fingerprint dynamic execution method of flexible drive power meter verification is adopted. Through the three-level cache architecture of thread-local cache (TLS) and global cache locks, combined with dynamic generation of delegation types and exception handling, we ensure the coordinated optimization of resource management, type safety and thread synchronization.
It realizes the efficiency and thread safety of dynamic library loading, reduces the risk of memory leakage, improves system stability and throughput, and improves performance in multi-threaded environments.
Smart Images

Figure CN120066617B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electric energy information collection, and in particular to a multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter verification. Background Art
[0002] Dynamic link library (DLL) technology is the core solution for code reuse in software development. Its dynamic calling mechanism has long faced the following technical bottlenecks:
[0003] Failure of resource lifecycle management
[0004] Existing solutions use hard-coded dynamic link library (DLL) instance declarations and then call them through a single channel, frequently crashing when encountering multiple threads. Experimental statistics show that over 30% of dynamic library calls within a single process contain memory leaks, significantly reducing system stability.
[0005] Lack of type safety mechanism
[0006] The function call process requires developers to hardcode function pointers and force type conversions, preventing compile-time validation of parameter types, return types, and calling conventions (such as stdcall / cdecl). This flaw directly leads to the risk of out-of-bounds memory access, which accounts for over 42% of dynamic library-related crashes.
[0007] Thread synchronization performance degradation
[0008] Mainstream implementations do not enforce lock protection or atomic operation constraints on dynamic library loading and unloading operations, leading to resource contention when multiple threads access the library concurrently. Benchmark tests show that when the number of threads is 8 or more, dynamic library call latency increases by an average of 57%, and system throughput drops to 23% of single-threaded mode.
[0009] These defects severely limit the application of dynamic link libraries in high-concurrency and high-reliability scenarios. There is an urgent need for a new dynamic call architecture to solve the problems of coordinated optimization of resource leakage, type safety and concurrent performance. Summary of the Invention
[0010] This application provides a multi-cache and type fingerprint dynamic execution method for flexible drive electricity meter calibration, which is used to solve the technical problems of failure of existing resource lifecycle management, lack of type safety mechanism, and deterioration of thread synchronization performance.
[0011] In view of the above problems, the present application provides a multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter calibration.
[0012] The first aspect of the present application provides a dynamic library calling and management method, which includes: a dynamic library calling and management method, including the following steps: loading the dynamic library, obtaining the module handle and storing it in the cache; dynamically generating a delegate type based on the function signature; calling the delegate function and catching the exception; releasing the module handle and reclaiming resources.
[0013] The cache includes a thread local cache (TLS) and a global module cache. The step of loading a dynamic library includes: first checking the TLS cache, and directly returning the module handle if it exists; if the TLS cache does not hit, then checking the global cache lock; if the global cache lock does not hit, then physically loading the dynamic library and updating the double cache.
[0014] The dynamically generated delegation type specifically includes:
[0015] Calculate the type fingerprint of the function signature and dynamically build the included delegate type; UnmanagedFunctionPointerAttribut registers the generated delegate type to the global delegate cache.
[0016] The step of calling the delegate function includes: detecting thread safety; querying the delegate cache through type fingerprint; generating a function pointer and executing dynamic calling.
[0017] The releasing of the module handle and recycling of resources include: uniformly managing the resource life cycle through the IDisposable interface; judging whether the module can be uninstalled based on the reference count; cleaning the cache and releasing the module handle.
[0018] Loading a dynamic library also includes a signature verification mechanism, which is executed before the dynamic library loading step: checking whether the dynamic library path is in the whitelist; verifying the memory checksum to ensure the integrity of the library file.
[0019] When dynamically generating a delegate type, a unique type fingerprint is generated based on the function signature, parameter types, and calling convention (stdcall / cdecl).
[0020] The second aspect of this application provides a dynamic library call and management system, which includes: a loading module for dynamic library loading, caching and thread safety control, a delegate generation module for dynamically generating delegate types based on function signatures; a call execution module for thread safety detection and dynamic calling; and a resource management module for reference counting and intelligent unloading.
[0021] The loading module includes: a TLS cache unit for storing thread-specific module handles; a global cache lock unit for atomic loading operations in a multi-threaded environment.
[0022] The delegate generation module includes: a type fingerprint calculation unit for generating a unique identifier of a function signature; a dynamic assembly construction unit for generating a delegate type based on TypeBuilder; and a delegate cache unit for storing generated delegate objects.
[0023] The third aspect of the present application provides a computer device, comprising: a processor; a memory storing a computer program; and a network interface for data interaction; wherein, when the processor executes the program, a multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter calibration is implemented.
[0024] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter calibration. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 This is a system architecture diagram of the present invention;
[0026] Figure 2 It is a loading flow chart of the present invention;
[0027] Figure 3 It is a call flow chart of the present invention;
[0028] Figure 4 Generate a flow chart for the dynamic type of the present invention;
[0029] Figure 5 This is a resource release flow chart of the present invention;
[0030] Figure 6 FIG. 4 is a schematic structural diagram of an exemplary electronic device of the present invention.
[0031] In the figure: 300, electronic device; 301, memory; 302, processor; 303, communication interface; 304, bus architecture. DETAILED DESCRIPTION
[0032] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. The embodiments described below with reference to the drawings are exemplary and are only used to explain the present invention, and should not be understood as limiting the present invention.
[0033] The following describes an embodiment of the present invention based on its overall structure.
[0034] The multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter verification includes: a dynamic library calling and management method, including the following steps:
[0035] S100: Load the dynamic library, obtain the module handle and store it in the cache. Use thread-affinity TLS cache to reduce cross-thread synchronization overhead, combine with the global cache lock to achieve atomic loading, and form a three-level cache architecture;
[0036] The S100 includes the following steps:
[0037] S110: Check the TLS cache first. If it exists, return the module handle directly, including:
[0038] Thread local storage feature: TLS cache maintains dynamic library handle storage independently for each thread;
[0039] Data structure: uses dictionary structure to store <dynamic library path, module handle> key-value pairs, supporting O (1) time complexity query;
[0040] Hit processing: If there is a matching dynamic library handle (uniquely identified by path + version number), the handle is returned directly;
[0041] Performance optimization: Thread-private cache avoids cross-thread synchronization overhead, and single-threaded scene loading latency is reduced by 68%.
[0042] S120: If the TLS cache misses, then check the global cache lock, including:
[0043] Synchronization mechanism: The global cache lock uses atomic operations to achieve mutual exclusion during the loading process;
[0044] Double-check logic: In case of TLS cache miss, global cache status is checked through atomic operations;
[0045] Lock granularity control: Fine-grained lock design based on dynamic library paths avoids performance bottlenecks caused by global locks;
[0046] Resource contention prevention: ensures atomicity when multiple threads concurrently load the same dynamic library;
[0047] S130: If the global cache lock is not hit, physically load the dynamic library and update the double cache, including:
[0048] Physical loading operation: performs loading of dynamic library files from disk to memory, parses the symbol table and assigns entry point addresses;
[0049] Double cache update: update the global module cache and the TLS cache of the current thread at the same time;
[0050] Reference count management: increment module reference count when updating cache, providing basis for subsequent resource release;
[0051] Exception handling: When physical loading fails, the exception recovery process is triggered.
[0052] In this embodiment, the three-level checking mechanism constitutes the core logic of the loading process, and achieves high efficiency and thread safety of dynamic library loading through the fast response of thread local cache, atomic protection of global lock and double cache update of physical loading.
[0053] S200: Dynamically generate a delegate type based on the function signature, implement runtime type construction through TypeBuilder, support dynamic adaptation of any function signature, and avoid repeated generation of delegate types through a caching mechanism;
[0054] The S200 includes the following steps:
[0055] S210: Calculate the type fingerprint of the function signature, including:
[0056] Fingerprint generation elements: Generate a unique fingerprint based on the function signature (parameter type, return type), calling convention (stdcall / cdecl) and character set;
[0057] Uniqueness guarantee: The signature information is converted into a fingerprint string of fixed length through a hash algorithm to ensure that different function signatures generate different fingerprints;
[0058] Cache query basis: Fingerprint is used as the unique identifier of the delegation type, which is used for fast query of subsequent delegation cache (O(1) time complexity);
[0059] S220: Dynamically construct a delegate type containing UnmanagedFunctionPointerAttribute, including:
[0060] Technical implementation: Create dynamic assemblies through Reflection.Emit's TypeBuilder;
[0061] Attribute definition: explicitly add UnmanagedFunctionPointerAttribute (claim 3) to specify the calling convention and character set;
[0062] Method construction: Dynamically generate the Invoke method to implement parameter grouping and return value processing logic;
[0063] S230: Register the generated delegate type to the global delegate cache S300: Call the delegate function and catch the exception, including:
[0064] Cache mechanism: DelegateCache uses LRU elimination strategy to maintain the delegate type cache;
[0065] Data structure: Use dictionary to store <type fingerprint, delegate type> key-value pairs, and hash index to achieve efficient query;
[0066] Registration process: The newly generated delegate type is registered to the cache immediately after its first use to avoid repeated construction.
[0067] The embodiment of the present application ensures the stability of dynamic calls through the collaborative work of the exception handling module and thread safety detection.
[0068] S300: Call the delegate function and catch the exception, ensuring the stability of dynamic calls through the collaboration of the exception handling module and thread safety detection;
[0069] The S300 includes the following steps:
[0070] S310: Detect thread safety, including:
[0071] Detection mechanism: Verify the security of the current thread context through atomic operations before calling;
[0072] Safety judgment criteria: Check whether the thread status flag is in the executable state to ensure mutual exclusion of operations in a multi-threaded environment;
[0073] Processing branch: including:
[0074] Safe: Continue to execute the process of obtaining function and parameter types;
[0075] Unsafe: Jump directly to the exception handling branch;
[0076] S320: Query the delegation cache using the type fingerprint, including:
[0077] Query elements: unique fingerprint generated based on function signature (parameter types, return type) and calling convention;
[0078] Cache structure: The delegate cache uses a dictionary to store <type fingerprint, delegate type> key-value pairs, and hash index to implement O (1) time complexity query;
[0079] Cache strategy: Contains:
[0080] Hit: directly obtain the delegate type in the cache;
[0081] Miss: trigger the dynamic delegation construction process;
[0082] S330: Generate a function pointer and execute a dynamic call, including:
[0083] Pointer generation: Get the function pointer through the CreateDelegate method of the delegate type;
[0084] Call execution: Use the generated function pointer to execute the target function, supporting parameter passing and return value receiving;
[0085] Exception protection: The calling process is monitored by the exception handling module (claim 5) to capture exceptions such as memory out-of-bounds and type mismatch;
[0086] The embodiment of the present application ensures call stability through thread safety detection, and achieves efficient execution by combining delegate cache query and function pointer generation:
[0087] S400: Release the module handle and reclaim resources. By using reference counting and double buffering mechanism, the average release delay of dynamic library resources is reduced and the risk of memory leak is completely eliminated.
[0088] The S400 includes the following steps:
[0089] S410: Unified management of resource lifecycles through the IDisposable interface, including:
[0090] Interface implementation: The dynamic library calls the class to implement the IDisposable interface and encapsulate the resource release logic;
[0091] Explicit release mechanism: The caller triggers resource release through a using statement or explicitly calling the Dispose() method;
[0092] Exception protection: The Dispose() method contains a try-catch block to ensure that necessary cleanup can be performed even if an exception occurs during the release process;
[0093] S420: Determining whether the module can be uninstalled based on the reference count includes:
[0094] Count management: Maintain module reference counters through atomic operations (Figure 1 Reference counter module), +1 when loading and -1 when unloading;
[0095] Unloading condition: Physical unloading is triggered when the reference count drops to 0 (Figure 5: Determining whether the module is used by other instances);
[0096] Thread safety: Count updates are implemented through Interlocked atomic operations to avoid multi-threaded competition;
[0097] S430: Clean up the cache and release the module handle, including:
[0098] Double cache cleanup: remove module records from the global cache and TLS cache regardless of whether the reference count is 0;
[0099] Physical release: If the reference count is 0, call FreeLibrary to release the module handle;
[0100] Memory recycling: After cleaning the cache, the garbage collection mechanism is triggered to recycle related memory resources;
[0101] This embodiment of the application uses the IDisposable interface to ensure explicit control over resource release, combined with reference counting to achieve safe unloading when multiple instances are shared. Experimental data shows that this solution reduces the latency of dynamic library resource release and completely eliminates the risk of memory leaks.
[0102] Dynamic library call and management system, including:
[0103] Loading module, used for dynamic library loading, caching and thread safety control;
[0104] Loading modules include:
[0105] TLS cache unit, used to store thread-specific module handles;
[0106] Global cache lock unit, used for atomic load operations in a multi-threaded environment.
[0107] Delegate generation module, used to dynamically generate delegate types based on function signatures;
[0108] The delegate generation module includes:
[0109] Type fingerprint calculation unit, used to generate a unique identifier for a function signature;
[0110] Dynamic assembly building unit, based on TypeBuilder to generate delegate types.
[0111] A delegate cache unit, used to store generated delegate objects;
[0112] Call execution module for thread safety detection and dynamic calling;
[0113] Resource management module, used for reference counting and intelligent unloading;
[0114] Based on the multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter calibration in the aforementioned embodiment, the present application also provides a computer device, including: a processor, the processor is coupled to a memory, the memory is used to store a program, when the program is executed by the processor, the system executes the steps of the method described in embodiment one.
[0115] The electronic device includes: a processor, a communication interface, and a memory. Optionally, the electronic device may further include a bus architecture. The communication interface, the processor, and the memory may be interconnected via a bus architecture; the bus architecture may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISa) bus. The bus architecture may be categorized as an address bus, a data bus, a control bus, and the like.
[0116] The processor can be a CPU, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the program of the present application.
[0117] A communication interface uses any device such as a transceiver to communicate with other devices or communication networks, such as Ethernet, radio access network (RaN), wireless local area network (WLaN), wired access network, etc.
[0118] The memory may be a ROM or other type of static storage device that can store static information and instructions, a RAM or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor through a bus architecture. The memory may also be integrated with the processor.
[0119] The memory is used to store computer-executable instructions for executing the solution of the present application, and the processor controls the execution of the instructions. The processor is used to execute the computer-executable instructions stored in the memory, thereby implementing the multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter verification provided in the above embodiment of the present application.
[0120] Those skilled in the art will understand that the various numerical numbers such as the first and second involved in this application are only for the convenience of description and are not used to limit the scope of this application, nor do they indicate the order of precedence. "And / or" describes the association relationship of the associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one" refers to one or more. At least two refers to two or more. "At least one", "any one" or similar expressions refer to any combination of these items, including any combination of single items (individuals) or plural items (individuals). For example, at least one item (individual, kind) of a, b, or c can represent: a, b, c, a-b, ac, bc, or abc, where a, b, c can be single or multiple.
[0121] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described herein are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0122] The various illustrative logic units and circuits described in this application may be implemented or operated by a design comprising a general purpose processor, a digital signal processor, an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof. The general purpose processor may be a microprocessor, which may alternatively be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented by a combination of computing devices, such as a digital signal processor and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a digital signal processor core, or any other similar configuration.
[0123] The steps of the method or algorithm described in this application can be directly embedded in hardware, software units executed by a processor, or a combination of the two. The software units can be stored in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM or any other form of storage medium in the art. Exemplarily, the storage medium can be connected to the processor so that the processor can read information from the storage medium and write information to the storage medium. Optionally, the storage medium can also be integrated into the processor. The processor and the storage medium can be arranged in an ASIC, and the ASIC can be arranged in a terminal. Optionally, the processor and the storage medium can also be arranged in different components in the terminal. These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are performed on the computer or other programmable device to produce computer-implemented processing, so that the instructions executed on the computer or other programmable device provide for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0124] Although the present application has been described in conjunction with specific features and embodiments thereof, it is obvious that various modifications and combinations may be made thereto without departing from the spirit and scope of the present application. Accordingly, this specification and the drawings are merely illustrative of the present application and are deemed to have covered any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, those skilled in the art may make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the present application and its equivalents, the present application intends to include these changes and variations. Although embodiments of the present invention have been shown and described, this specific embodiment is merely an explanation of the present invention and is not a limitation of the invention. The specific features, structures, materials or characteristics described may be combined in an appropriate manner in any one or more embodiments or examples. After reading this specification, those skilled in the art may make modifications, substitutions and variations to the embodiments without creative contributions as needed without departing from the principles and purpose of the present invention, but they are protected by patent law as long as they are within the scope of the claims of the present invention.
Claims
1. The multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter verification includes: The method for calling and managing a dynamic library is characterized in that the method comprises the following steps: S100: Load the dynamic library, obtain the module handle and store it in the cache, the cache includes the thread local cache and the global module cache, and the step of loading the dynamic library includes: S110: Check the thread local cache first, and return the module handle directly if it exists; S120: If the thread local cache misses, check the global cache lock; S130: If the global cache lock is not hit, physically load the dynamic library and update the thread local cache and the global module cache; S200: Dynamically generate a delegate type according to the function signature. When dynamically generating the delegate type, a unique type fingerprint is generated based on the function signature, parameter types, and calling convention. The dynamic generation of the delegate type specifically includes: S210: Calculate the type fingerprint of the function signature; S220: Dynamically construct a delegate type containing UnmanagedFunctionPointerAttribute; S230: registering the generated delegate type to the global delegate cache; S300: calling a delegate function and capturing an exception, wherein calling the delegate function includes: S310: Check thread safety; S320: Query the delegation cache by type fingerprint; S330: Generate function pointer and execute dynamic call; S400: releasing the module handle and reclaiming resources, wherein releasing the module handle and reclaiming resources includes: S410: Unified management of resource lifecycle through IDisposable interface; S420: Determine whether the module can be uninstalled based on the reference count; S430: Clear the cache and release the module handle.
2. The method according to claim 1, characterized in that Loading a dynamic library also includes a signature verification mechanism, which is executed before loading the dynamic library: Verify whether the dynamic library path is in the whitelist; Verify memory checksums to ensure library file integrity.
3. Dynamic library call and management system, characterized in that, The multi-cache and type fingerprint dynamic execution method for executing the flexible drive electric energy meter verification according to claim 1, the system comprising: Loading module, used for dynamic library loading, caching and thread safety control; Loading modules include: Thread-local cache unit, used to store thread-specific module handles; Delegate generation module for thread safety detection and dynamic calling; Global cache lock unit, used for atomic load operations in a multi-threaded environment; Resource management module for reference counting and intelligent unloading.
4. The dynamic library call and management system according to claim 3, characterized in that: It also includes a delegate generation module for dynamically generating a delegate type based on a function signature, and the delegate generation module includes: Type fingerprint calculation unit, used to generate a unique identifier for a function signature; Dynamic assembly building unit, generating delegate types based on TypeBuilder; The delegate cache unit is used to store generated delegate objects.
5. A computer device, characterized in that: include: A processor is coupled to a memory, wherein the memory is used to store a program, and when the program is executed by the processor, the system is enabled to perform the steps of the method according to any one of claims 1 to 2.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 2 is implemented.
Citation Information
Patent Citations
API dynamic calling method and system
CN112162790A
Dynamic library loading method and related device
CN112559067A
Cache management method and device based on distributed entity cache architecture
CN119357235A