Search

CN-121996443-A - Data access method, apparatus, computer device, readable storage medium, and program product

CN121996443ACN 121996443 ACN121996443 ACN 121996443ACN-121996443-A

Abstract

The present application relates to a data access method, apparatus, computer device, computer readable storage medium and computer program product. The method comprises the steps of responding to receiving an access request for real-time data in a shared memory, loading a pre-built interface library, wherein the real-time data in the shared memory is stored by a real-time operating system according to a target data structure, the interface library is built based on a programming language of a non-real-time operating system and an intermediate language between the programming language of the real-time operating system, an address mapping relation between the interface library and the shared memory is built based on a first application interface in the interface library, an address pointer of the shared memory is obtained, and the real-time data in the shared memory is accessed based on a second application interface in the interface library, the address mapping relation and the address pointer, wherein the non-real-time operating system is used for storing the accessed real-time data according to the target data structure. By adopting the method, cross-language data access can be realized, and real-time performance is ensured.

Inventors

  • SHEN JIANENG
  • YE JINYU
  • LU HONGXING

Assignees

  • 苏州纵苇科技有限公司

Dates

Publication Date
20260508
Application Date
20260129

Claims (10)

  1. 1. A method for accessing data, the method being applied to a non-real-time operating system, the method comprising: Loading a pre-built interface library in response to receiving an access request for real-time data in a shared memory, wherein the real-time data in the shared memory is stored by a real-time operating system according to a target data structure, and the interface library is built based on an intermediate language between a programming language of the non-real-time operating system and a programming language of the real-time operating system; establishing an address mapping relation between the interface library and the shared memory based on a first application interface in the interface library, and acquiring an address pointer of the shared memory; Accessing real-time data in the shared memory based on a second application interface in the interface library, the address mapping relation and the address pointer, wherein the non-real-time operating system is used for storing the accessed real-time data according to the target data structure.
  2. 2. The method of claim 1, wherein accessing real-time data in the shared memory based on the second application interface in the interface library, the address mapping relationship, and the address pointer, then comprises: and removing the address mapping relation between the interface library and the shared memory based on a third application interface in the interface library, and releasing resources occupied in the process of accessing the real-time data in the shared memory.
  3. 3. The method of claim 1, wherein the real-time operating system is configured to store real-time data to a shared memory based on a target data structure and delete stuff bytes automatically populated by a compiler between fields of the real-time data, wherein accessing the real-time data in the shared memory based on the second application interface in the interface library, the address mapping relationship, and the address pointer, then comprises: And storing the accessed real-time data based on a data structure consistent with the memory layout of the target data structure, and deleting the padding bytes automatically filled by a compiler among fields of the accessed real-time data.
  4. 4. A method according to claim 3, wherein the real-time operating system is further configured to define the target data structure to employ a fixed size data type and/or to prohibit employing non-serializable elements.
  5. 5. A method according to claim 3, wherein storing the accessed real-time data based on the data structure consistent with the memory layout of the target data structure and deleting the padding bytes automatically populated by the compiler between fields of the accessed real-time data comprises, before: Under the condition of compiling or running target language codes for accessing real-time data in a shared memory, determining a consistency result of a data structure for storing the accessed real-time data and a field memory offset, a byte size and/or a total byte length of a field data type of the target data structure; Storing the accessed real-time data based on a data structure consistent with the memory layout of the target data structure, and deleting the padding bytes automatically filled by a compiler among fields of the accessed real-time data comprises: And storing the accessed real-time data based on the data structure and deleting redundant bytes filled between fields of the accessed real-time data under the condition that the consistency result is consistent.
  6. 6. The method of claim 1, wherein the real-time operating system is configured to run at least one real-time task and the non-real-time operating system is configured to run at least one non-real-time task, the real-time task having a higher scheduling priority than the non-real-time task.
  7. 7. A data access device, the device comprising: The interface library loading module is used for loading a pre-constructed interface library in response to receiving an access request for real-time data in a shared memory, wherein the real-time data in the shared memory is stored by a real-time operating system according to a target data structure, and the interface library is constructed based on an intermediate language between a programming language of a non-real-time operating system and a programming language of the real-time operating system; The shared memory connection module is used for establishing an address mapping relation between the interface library and the shared memory based on a first application interface in the interface library, and acquiring an address pointer of the shared memory; The data access module is used for accessing the real-time data in the shared memory based on a second application interface, the address mapping relation and the address pointer in the interface library, wherein the non-real-time operating system is used for storing the accessed real-time data according to the target data structure.
  8. 8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 6 when the computer program is executed.
  9. 9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
  10. 10. A computer program product comprising a computer program, characterized in that the computer program, when executed by a processor, implements the steps of the method of any one of claims 1 to 6.

Description

Data access method, apparatus, computer device, readable storage medium, and program product Technical Field The present application relates to the field of cross-language data access technology, and in particular, to a data access method, apparatus, computer device, computer readable storage medium, and computer program product. Background In fields with high response timeliness requirements, such as industrial control, robots, automatic driving and the like, a system is generally designed by adopting a layered architecture, and is specifically divided into a real-time control layer and an upper application layer. The Real-time control layer is constructed based on a C/C++ language and a Real-time kernel (Real-TIME KERNEL), is required to realize microsecond-level deterministic response, ensures accurate execution of key tasks such as equipment control and data acquisition, and the like, and the upper application layer is developed based on a modern programming language such as Rust, python, go, java and the like, is used for realizing functions such as monitoring interface display, data analysis processing and business logic realization, and the normal operation of the Real-time control layer depends on efficient access to Real-time control layer data. In the prior art, in order to realize cross-language data sharing of an upper application layer and a real-time control layer, three types of schemes are mainly adopted, namely, a network communication scheme based on Socket or REST API, data interaction of the cross-layer data is completed through data serialization and network transmission, a middleware scheme based on a message queue, asynchronous data transmission is realized through a queue cache, and a scheme based on a common shared memory is adopted, and data direct reading and writing are realized through opening up a memory area shared among processes. However, the network communication scheme based on Socket or REST API has high delay of data transmission due to high serialization overhead and the middleware scheme based on message queue has additional overhead of data copy, so that microsecond response requirements of a real-time control layer are difficult to meet, and the common shared memory scheme has low delay, but lacks adaptation to real-time kernel characteristics, so that deterministic response of the real-time control layer cannot be ensured. Therefore, a data access method capable of realizing cross-language data access and ensuring real-time performance is needed. Disclosure of Invention In view of the foregoing, it is desirable to provide a data access method, apparatus, computer device, computer readable storage medium, and computer program product that enable cross-language data access and ensure real-time performance. In a first aspect, the present application provides a data access method, including: Loading a pre-built interface library in response to receiving an access request for real-time data in a shared memory, wherein the real-time data in the shared memory is stored by a real-time operating system according to a target data structure, and the interface library is built based on an intermediate language between a programming language of the non-real-time operating system and a programming language of the real-time operating system; establishing an address mapping relation between the interface library and the shared memory based on a first application interface in the interface library, and acquiring an address pointer of the shared memory; Accessing real-time data in the shared memory based on a second application interface in the interface library, the address mapping relation and the address pointer, wherein the non-real-time operating system is used for storing the accessed real-time data according to the target data structure. In one embodiment, accessing the real-time data in the shared memory based on the second application interface in the interface library, the address mapping relation and the address pointer, and then includes: and removing the address mapping relation between the interface library and the shared memory based on a third application interface in the interface library, and releasing resources occupied in the process of accessing the real-time data in the shared memory. In one embodiment, the real-time operating system is configured to store real-time data in a shared memory based on a target data structure, delete a stuff byte automatically filled by a compiler between fields of the real-time data, access the real-time data in the shared memory based on a second application interface in the interface library, the address mapping relationship, and the address pointer, and then include: And storing the accessed real-time data based on a data structure consistent with the memory layout of the target data structure, and deleting the padding bytes automatically filled by a compiler among fields of the accessed real-time data. In one embodiment, the re