Multi-cache and type fingerprint dynamic execution method for verification of flexible drive electric energy meter

Through the multi-cache and type fingerprint dynamic execution method of flexible drive power meter verification, the resource leakage, type safety and concurrency performance problems of dynamic link library in high concurrency and high reliability scenarios are solved, and the system stability and performance improvement is achieved.

CN120066617AActive Publication Date: 2025-05-30HENGYE ELECTRONICS JIAXING CITY
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510511222.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-23
Publication Date
2025-05-30
Estimated Expiration
2045-04-23

AI Technical Summary

Technical Problem

The existing dynamic link library (DLL) technology has problems such as resource lifecycle management failure, type safety mechanism missing and thread synchronization performance deterioration in high concurrency and high reliability scenarios.

Method used

The multi-cache and type fingerprint dynamic execution method of flexible drive power meter verification is adopted. The efficient loading and release of dynamic libraries is achieved through thread-local cache (TLS) and global module cache, and the delegation types are generated dynamically and thread-safe detection is performed to ensure the stability and security of the dynamic call process.

Benefits of technology

It effectively solves the collaborative optimization problems of resource leakage, type safety and concurrency performance, improves system stability and performance, and reduces the risk of memory leakage and memory out-of-bounds access.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066617A_ABST
    Figure CN120066617A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-cache and type fingerprint dynamic execution method for verification of a flexible drive electric energy meter, and relates to the field of electric energy information collection and a dynamic library calling and management method, and the method comprises the following steps: loading a dynamic library, obtaining a module handle, and storing the module handle in a cache; dynamically generating a delegation type according to the function signature; calling a delegation function and capturing exceptions; the cache comprises a thread local cache (TLS) and a global module cache, and the step of loading the dynamic library comprises the following steps of: preferentially checking the TLS cache, and directly returning the module handle if the TLS cache exists; if the TLS cache is not hit, checking a global cache lock; and if the global cache lock is not hit, physically loading the dynamic library and updating the double caches. According to the method, the high efficiency of dynamic library loading and the thread security are realized through the quick response of the thread local cache, the atomic protection of the global lock and the double-cache updating of the physical loading.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of electric energy information collection, and specifically to a multi-buffer and type fingerprint dynamic execution method for calibrating a flexible drive electric energy meter. Background Art

[0002] As the core solution for realizing code reuse in software development, the dynamic link library (DLL) technology has long faced the following technical bottlenecks in its dynamic call mechanism: Failure in resource lifecycle management Existing solutions declare instances of dynamic link libraries (DLLs) in a hard-coded manner, and then execute them through single-channel calls via invocation. When encountering multi-threading, they often crash. According to experimental statistics, more than 30% of dynamic library calls within a single process have memory leaks, significantly reducing system stability.

[0003] Lack of type safety mechanism During the function call process, developers need to hard-code function pointers and perform forced type conversions, and it is impossible to perform legal validity checks on parameter types, return types, and call conventions (such as stdcall / cdecl) during compilation. This defect directly leads to the risk of out-of-bounds memory access. According to statistics, such problems account for more than 42% of the crash cases related to dynamic libraries.

[0004] Deterioration of thread synchronization performance Mainstream implementations do not impose lock protection or atomic operation constraints on the loading / unloading operations of dynamic libraries, resulting in resource competition during multi-threaded concurrent access. Benchmark tests show that when the number of threads ≥ 8, the dynamic library call latency increases by an average of 57%, and the system throughput drops to 23% of the single-threaded mode.

[0005] These defects have severely restricted the application of dynamic link libraries in high-concurrency and high-reliability scenarios. There is an urgent need for a new type of dynamic call architecture to solve the collaborative optimization problems of resource leakage, type safety, and concurrent performance. Summary of the Invention

[0006] The present application provides a multi-buffer and type fingerprint dynamic execution method for calibrating a flexible drive electric energy meter, which is used to solve the technical problems of existing failure in resource lifecycle management, lack of type safety mechanism, and deterioration of thread synchronization performance.

[0007] In view of the above problems, the present application provides a multi-buffer and type fingerprint dynamic execution method for calibrating a flexible drive electric energy meter.

[0008] The first aspect of the present application provides a dynamic library call and management method, and the method includes: The dynamic library call and management method includes the following steps: loading a dynamic library, obtaining a module handle and storing it in a buffer; dynamically generating a delegate type according to a function signature; calling a delegate function and catching an exception; releasing the module handle and recycling resources.

[0009] The cache includes a thread - local cache (TLS) and a global module cache. The step of loading the dynamic library includes: preferentially checking the TLS cache, and directly returning the module handle if it exists; if the TLS cache misses, checking the global cache lock; if the global cache lock misses, physically loading the dynamic library and updating the dual - cache.

[0010] The dynamic generation of the delegate type specifically includes: Calculating the type fingerprint of the function signature, dynamically constructing the included delegate type; registering the generated delegate type to the global delegate cache by UnmanagedFunctionPointerAttribut.

[0011] The step of calling the delegate function includes: detecting thread safety; querying the delegate cache through the type fingerprint; generating a function pointer and performing a dynamic call.

[0012] The releasing of the module handle and recycling of resources includes: uniformly managing the resource life cycle through the IDisposable interface; judging whether the module is unloadable based on the reference count; cleaning the cache and releasing the module handle.

[0013] Loading the dynamic library also includes a signature verification mechanism, which is executed before the step of loading the dynamic library: verifying whether the dynamic library path is within the whitelist; verifying the memory checksum to ensure the integrity of the library file.

[0014] When dynamically generating the delegate type, a unique type fingerprint is generated based on the function signature, parameter types, and calling convention (stdcall / cdecl).

[0015] The second aspect of the present 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 call; and a resource management module for reference counting and intelligent unloading.

[0016] 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 - thread environment.

[0017] The delegate generation module includes: a type fingerprint calculation unit for generating a unique identifier of the function signature; a dynamic assembly construction unit for generating delegate types based on TypeBuilder; and a delegate cache unit for storing the generated delegate objects.

[0018] The third aspect of the present application provides a computer device, including: a processor; a memory storing a computer program; a network interface for data interaction; wherein, when the processor executes the program, it implements a method for optimizing the distribution data of coupons.

[0019] The fourth aspect of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements a method for optimizing the distribution data of coupons. Description of the Drawings

[0020] Figure 1 It is the system architecture diagram of the present invention; Figure 2 It is the loading flowchart of the present invention; Figure 3 It is the call flowchart of the present invention; Figure 4 It is the dynamic type generation flowchart of the present invention; Figure 5 It is the resource release flowchart of the present invention; Figure 6 It is the structural schematic diagram of an exemplary electronic device of the present invention.

[0021] In the figure: 300, electronic device; 301, memory; 302, processor; 303, communication interface; 304, bus architecture. Detailed Embodiments

[0022] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention and should not be construed as a limitation to the present invention.

[0023] Next, the embodiments of the present invention will be described according to the overall structure of the present invention.

[0024] The multi-cache and type fingerprint dynamic execution method for calibrating a flexible drive watt-hour meter includes: a dynamic library call and management method, including the following steps: S100: Load the dynamic library, obtain the module handle and store it in the cache, reduce the cross-thread synchronization overhead through the thread affinity TLS cache, and implement atomic loading in combination with the global cache lock to form a three-level cache architecture; The S100 includes the following steps: S110: First check the TLS cache, if it exists, directly return the module handle, including: Thread local storage feature: The TLS cache independently maintains the storage of dynamic library handles for each thread; Data Structure: Use a dictionary structure to store key-value pairs of <dynamic library path, module handle>, supporting O(1) time complexity query; Hit Handling: If there is a matching dynamic library handle (uniquely identified by path + version number), directly return the handle; Performance Optimization: Thread-private cache avoids cross-thread synchronization overhead, reducing the loading latency by 68% in a single-thread scenario; S120: If the TLS cache misses, check the global cache lock, including: Synchronization Mechanism: The global cache lock uses atomic operations to achieve mutual exclusion during the loading process; Double-Check Logic: When the TLS cache misses, detect the global cache status through atomic operations; Lock Granularity Control: Fine-grained lock design based on the dynamic library path to avoid performance bottlenecks caused by global locks; Resource Competition Protection: Ensure atomicity when multiple threads concurrently load the same dynamic library; S130: If the global cache lock misses, physically load the dynamic library and update the dual cache, including: Physical Loading Operation: Execute the loading of the dynamic library file from disk to memory, parse the symbol table, and allocate the entry point address; Dual Cache Update: Update both the global module cache and the current thread's TLS cache simultaneously; Reference Count Management: Increment the module reference count when updating the cache to provide a basis for subsequent resource release; Exception Handling: Trigger the exception recovery process when physical loading fails.

[0025] In this embodiment, this three-level check mechanism constitutes the core logic of the loading process. Through the fast response of the thread-local cache, the atomic protection of the global lock, and the dual cache update of physical loading, the efficiency and thread safety of dynamic library loading are achieved.

[0026] S200: Dynamically generate a delegate type according to the function signature, implement runtime type construction through TypeBuilder, support dynamic adaptation of any function signature, and avoid duplicate generation of delegate types through a caching mechanism; The S200 includes the following steps: S210: Calculate the type fingerprint of the function signature, including: Fingerprint Generation Elements: Generate a unique fingerprint based on the function signature (parameter types, return type), calling convention (stdcall / cdecl), and character set; Uniqueness Guarantee: Convert the signature information into a fixed-length fingerprint string through a hash algorithm to ensure that different function signatures generate different fingerprints; Basis for cache query: The fingerprint is used as the unique identifier for the delegate type and is used for fast query of the subsequent delegate cache (O(1) time complexity). S220: Dynamically construct a delegate type that includes the UnmanagedFunctionPointerAttribute, including: Technical implementation: Create a dynamic assembly through the TypeBuilder of Reflection.Emit; Attribute definition: Explicitly add the UnmanagedFunctionPointerAttribute (Claim 3) to specify the calling convention and character set; Method construction: Dynamically generate the Invoke method to implement the parameter marshaling and return value processing logic; S230: Register the generated delegate type to the global delegate cache S300: Call the delegate function and catch exceptions, including: Cache mechanism: The DelegateCache maintains the delegate type cache using the LRU eviction policy; Data structure: Use a dictionary to store key-value pairs of <type fingerprint, delegate type>, and use a hash index for efficient query; Registration process: The newly generated delegate type is registered to the cache immediately after its first use to avoid repeated construction.

[0027] In the embodiment of the present application, through the collaborative work of the exception handling module and thread safety detection, the stability of dynamic invocation is ensured.

[0028] S300: Call the delegate function and catch exceptions, and ensure the stability of dynamic invocation through the collaborative work of the exception handling module and thread safety detection; The S300 includes the following steps: S310: Detect thread safety, including: Detection mechanism: Verify the security of the current thread context through atomic operations before calling; Security determination criterion: Check whether the thread status flag bit is in an executable state to ensure the mutual exclusion of operations in a multi-threaded environment; Processing branch: Include Safe: Continue to execute the process of obtaining the function and parameter types; Unsafe: Directly jump to the exception handling branch; S320: Query the delegate cache through the type fingerprint, including: Query elements: The unique fingerprint generated based on the function signature (parameter type, return type) and calling convention; Cache Structure: The delegate cache uses a dictionary to store <type fingerprint, delegate type> key-value pairs, and a hash index is used to achieve O(1) time complexity query; Cache Policy: It includes: Hit: Directly obtain the delegate type in the cache; Miss: Trigger the dynamic delegate construction process; S330: Generate a function pointer and perform a dynamic call, including: Pointer Generation: Obtain the function pointer through the CreateDelegate method of the delegate type; Call Execution: Use the generated function pointer to execute the target function, supporting parameter passing and return value reception; Exception Protection: The call process is monitored by an exception handling module (Claim 5), and exceptions such as memory out-of-bounds and type mismatch are captured.

[0029] In the embodiment of the present application, call stability is ensured through thread safety detection, and efficient execution is achieved by combining delegate cache query and function pointer generation.

[0030] S400: Release the module handle and recycle resources. Through the reference counting and double buffer mechanism, the average release delay of dynamic library resources is reduced, and the risk of memory leakage is completely eliminated; The S400 includes the following steps: S410: Uniformly manage the resource life cycle through the IDisposable interface, including: Interface Implementation: The dynamic library call class implements the IDisposable interface and encapsulates the resource release logic; Explicit Release Mechanism: The caller triggers resource release through the using statement or explicitly calls the Dispose() method; Exception Protection: The Dispose() method contains a try-catch block inside to ensure that necessary cleaning can still be performed when an exception occurs during the release process; S420: Judge whether the module can be unloaded based on reference counting, including: Count Management: Maintain the module reference counter (Figure 1 reference counter module) through atomic operations, incrementing by 1 when loading and decrementing by 1 when unloading; Unloading Condition: Trigger physical unloading when the reference count drops to 0 (Figure 5 determines whether the module is used by other instances); Thread Safety: The count update is implemented through atomic operations of the Interlocked class to avoid multi-threaded competition; S430: Clear the cache and release the module handle, including: Double buffer cleaning: Remove module records from the global cache and TLS cache regardless of whether the reference count is 0; Physical release: If the reference count is 0, call FreeLibrary to release the module handle; Memory recovery: Trigger the garbage collection mechanism after cleaning the cache to recover relevant memory resources.

[0031] In the embodiments of the present application, explicit control of resource release is ensured through the IDisposable interface, and safe unloading during multi-instance sharing is achieved by combining reference counting. Experimental data shows that this solution reduces the delay of dynamic library resource release and completely eliminates the risk of memory leakage.

[0032] Dynamic library call and management system, including: Loading module, used for dynamic library loading, caching, and thread safety control; The loading module includes: TLS cache unit, used to store thread-specific module handles; Global cache lock unit, used for atomic loading operations in a multi-threaded environment; Delegate generation module, used to dynamically generate delegate types based on function signatures; The delegate generation module includes: Type fingerprint calculation unit, used to generate a unique identifier for the function signature; Dynamic assembly construction unit, generating delegate types based on TypeBuilder; Delegate cache unit, used to store the generated delegate objects; Call execution module, used for thread safety detection and dynamic calls; Resource management module, used for reference counting and intelligent unloading.

[0033] Based on the multi-cache and type fingerprint dynamic execution method for flexible drive watt-hour meter verification in the foregoing embodiments, the present application also provides a computer device, including: a processor, the processor is coupled to a memory, and the memory is used to store a program. When the program is executed by the processor, the system is enabled to execute the steps of the method in Embodiment 1.

[0034] The electronic device includes: a processor, a communication interface, and a memory. Optionally, the electronic device may further include a bus architecture. Among them, the communication interface, the processor, and the memory can be interconnected through the bus architecture; the bus architecture can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus architecture can be divided into an address bus, a data bus, a control bus, etc.

[0035] 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 solution of the present application.

[0036] The communication interface uses any device such as a transceiver for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), wired access network, etc.

[0037] The memory can be a ROM or other types of static storage devices that can store static information and instructions, a RAM or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM), or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, or any other medium that can be used to carry or store the 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 can exist independently and be connected to the processor through the bus architecture. The memory can also be integrated with the processor.

[0038] Among them, the memory is used to store computer execution instructions for executing the solution of the present application, and is controlled by the processor for execution. The processor is used to execute the computer execution instructions stored in the memory, thereby implementing a method for optimizing the distribution data of coupons provided in the above embodiments of the present application.

[0039] Those of ordinary skill in the art can 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 represent the order of precedence. "And / or" describes the association relationship of associated objects and indicates that three relationships can exist. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one" means one or more. At least two means two or more. "At least one", "any one" or their similar expressions refer to any combination of these items, including any combination of single items or plural items. For example, at least one (item, kind) of a, b, or c can represent: a, b, c, a - b, a - c, b - c, or a - b - c, where a, b, and c can be single or multiple.

[0040] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part 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, the processes or functions described in this application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid-state drive (SSD)).

[0041] The various illustrative logical units and circuits described in this application can be implemented or operate the described functions by 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 of the above designs. The general-purpose processor can be a microprocessor, and optionally, the general-purpose processor can also be any conventional processor, controller, microcontroller or state machine. The processor can also be implemented by a combination of computing devices, such as a digital signal processor and a microprocessor, multiple microprocessors, one or more microprocessors combined with a digital signal processor core, or any other similar configuration.

[0042] The steps of the methods or algorithms described in this application can be directly embedded in hardware, a software unit executed by a processor, or a combination of both. The software unit can be stored in a RAM memory, a flash memory, a ROM memory, an EPROM memory, an EEPROM memory, a register, a hard disk, a removable disk, a 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 disposed in an ASIC, and the ASIC can be disposed in a terminal. Optionally, the processor and the storage medium can also be disposed in different components of the terminal. These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, thereby providing instructions for implementing the steps in the process Figure 1 a process or multiple processes and / or blocks Figure 1 steps for the functions specified in a block or multiple blocks.

[0043] Although the present application has been described in connection with specific features and their embodiments, it will be apparent that various modifications and combinations can be made without departing from the spirit and scope of the present application. Accordingly, this specification and the accompanying drawings are merely illustrative of the present application and are considered to cover any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, those skilled in the art can 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 equivalent technologies, the present application is intended to include these changes and modifications. Although the embodiments of the present invention have been shown and described, the specific embodiments are merely explanations of the present invention and are not limitations thereof. The specific features, structures, materials or characteristics described may be combined in a suitable manner in any one or more embodiments or examples. After reading this specification, those skilled in the art can make modifications, substitutions and variations that do not make a creative contribution to the embodiments as needed, but as long as they are within the scope of the claims of the present invention, they are protected by the patent law.

Claims

1. Multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter verification, including: The dynamic library calling and management method 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; S200: Dynamically generate a delegate type based on the function signature; S300: Call the delegate function and catch the exception; S400: Release the module handle and recycle resources.

2. The method according to claim 1, characterized in that: The cache includes a thread local cache (TLS) and a global module cache, and the step of loading a dynamic library includes: S110: Check the TLS cache first, and if it exists, return the module handle directly; S120: If the TLS cache misses, check the global cache lock; S130: If the global cache lock is not hit, the dynamic library is physically loaded and the double cache is updated.

3. The method according to claim 1, characterized in that: The dynamically generated delegation type specifically includes: S210: Calculate the type fingerprint of the function signature; S220: Dynamically construct a delegate type containing UnmanagedFunctionPointerAttribute; S230: Register the generated delegate type to the global delegate cache.

4. The method according to claim 1, characterized in that: The step of calling the delegate function includes: S310: Detect thread safety; S320: query the delegation cache through the type fingerprint; S330: Generate a function pointer and execute dynamic call.

5. The method according to claim 1, characterized in that: The releasing module handle and reclaiming resources include: S410: Unified management of resource life cycle through IDisposable interface; S420: Determine whether the module can be uninstalled based on the reference count; S430: Clean up the cache and release the module handle.

6. 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.

7. The method according to claim 1, characterized in that When dynamically generating a delegate type, a unique type fingerprint is generated based on the function signature, parameter types, and calling convention (stdcall / cdecl).

8. Dynamic library call and management system, characterized in that: Dynamic library calling and management method for multi-cache and type fingerprint dynamic execution method for verification of electric energy meter equipped with flexible drive, including: Loading module, used for dynamic library loading, caching and thread safety control; Loading modules include: TLS cache unit, used to store thread-specific module handles; Global cache lock unit, used for atomic load operations in a multithreaded environment; Delegate generation module, used to dynamically generate delegate types based on function signatures; Type fingerprint calculation unit, used to generate a unique identifier for a function signature; Dynamic assembly building unit, generating delegate types based on TypeBuilder; A delegate cache unit, used to store generated delegate objects; Call execution module for thread safety detection and dynamic calling; Resource management module, used for reference counting and intelligent unloading.

9. A computer device, characterized in that: include: 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 is enabled to perform the steps of the method according to any one of claims 1 to 7.

10. 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 7 is implemented.

Citation Information

Patent Citations

  • API dynamic calling method and system

    CN112162790A

  • Dynamic library loading method and related device

    CN112559067A

  • Static TLS access method and device, electronic equipment and storage medium

    CN115617365A

  • Method and device for implementing security entrustment management strategy for audio processing, and medium

    CN119002858A

  • Cache management method and device based on distributed entity cache architecture

    CN119357235A