CN112631815B - Inter-process communication method and system based on COM cross-process calling and shared memory - Google Patents

Inter-process communication method and system based on COM cross-process calling and shared memory Download PDF

Info

Publication number
CN112631815B
CN112631815B CN202110257312.0A CN202110257312A CN112631815B CN 112631815 B CN112631815 B CN 112631815B CN 202110257312 A CN202110257312 A CN 202110257312A CN 112631815 B CN112631815 B CN 112631815B
Authority
CN
China
Prior art keywords
memory
shared memory
com
calling
shared
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110257312.0A
Other languages
Chinese (zh)
Other versions
CN112631815A (en
Inventor
沈阳丽
李志强
刘曙元
程睿君
薛尚君
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guoneng Xinkong Internet Technology Co Ltd
Original Assignee
Guoneng Xinkong Internet Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guoneng Xinkong Internet Technology Co Ltd filed Critical Guoneng Xinkong Internet Technology Co Ltd
Priority to CN202110257312.0A priority Critical patent/CN112631815B/en
Publication of CN112631815A publication Critical patent/CN112631815A/en
Application granted granted Critical
Publication of CN112631815B publication Critical patent/CN112631815B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Abstract

The method and the system for interprocess communication based on COM cross-process calling and shared memory combine the COM cross-process calling technology and the shared memory technology, firstly, a calling end process dynamically allocates a continuous memory space in the shared memory, puts data into the memory space according to a specific format, and then transmits the initial offset of the memory as a parameter to a corresponding COM interface; and the COM informs the called process, the called process acquires the offset and accesses a corresponding position in the shared memory, data is acquired according to the same format, a result is still put into the shared memory after certain logic is executed, the control right is returned to the COM, and the calling end acquires an output result from the shared memory again. The invention realizes the function of cross-process communication for efficiently transmitting a large amount of data.

Description

Inter-process communication method and system based on COM cross-process calling and shared memory
Technical Field
The invention belongs to the technical field of interprocess communication and message transmission, and relates to an interprocess communication method and system based on COM (component object model) cross-process calling and shared memory.
Background
The inter-process communication is to transmit or exchange information among different processes, and is not only applied to the fields of operating systems, application software and the like, but also applied to the fields of industrial internet of things, real-time databases and the like.
The existing interprocess communication method comprises the following steps: pipes, message queues, etc.; however, the anonymous pipeline only supports one-way communication and can only be on a local machine, and the named pipeline cannot realize multi-process communication; when the message queue copies the message, it needs to consume extra time of the CPU, which is not suitable for the situation with large amount of information or frequent operation.
Disclosure of Invention
In order to solve the problems in the prior art, the invention aims to provide a method and a system for interprocess communication based on COM cross-process calling and shared memory, which not only solve the cross-network cross-process calling, but also solve the problem of mass data transmission among processes.
The invention adopts the following technical scheme:
the inter-process communication method based on COM cross-process calling and shared memory comprises the following steps:
step 1, a calling end dynamically allocates a continuous memory space in a shared memory, preset data to be transmitted among processes is put into the memory space according to a set format, and then the initial offset of the memory space is used as a parameter to be transmitted to a corresponding COM interface;
step 2, the called end obtains the initial position of the shared memory through the parameters of the COM interface, after finding the corresponding position, the memory space is explained according to the same format to obtain the data in the memory space, then the calling is carried out, the output parameters are still placed in the shared memory after the calling is finished and returned to the calling end,
the shared memory is a memory space in the same block accessed by a preset number of processes, and is also an inter-process communication mode;
step 3, after the calling end finishes calling, a return value is obtained from the COM interface, and an output parameter is obtained in the shared memory;
wherein, COM is a serial communication port.
In step 1, a shared memory is used to reduce the performance overhead of data replication during COM transfer.
In step 1, the calling end includes a memory offset unit, and the memory offset unit is configured to calibrate different initial offsets of the shared memory when the shared memory is loaded in each process.
In step 1, the COM interface adopts a macro mechanism to uniformly process formats in the shared memory, specifically:
automatically calculating the total space occupied by the format memory through the class constructor and dynamically allocating the shared memory;
automatically calculating the offset according to the length of the field, and automatically moving the position of the pointer according to the offset;
when exiting the scope, the allocated shared memory is automatically released through the destructor of the class.
The macro definition in the macro mechanism depends on the number of preset data fields, and the number of macro definitions is several due to the different number of the data fields; the same macro can be reused for the same number of data fields.
Because the output parameter is located in the shared memory, the recovery and release of the shared memory are performed after the call end sends the reply message.
In step 1, the set format is that the data are sequentially and continuously arranged in sequence.
In step 2, the called end adopts the corresponding macro definition for explaining the memory.
In step 3, the output parameter is located in the shared memory, and the recovery and release of the shared memory are performed after the reply message is sent.
The interprocess communication system of the interprocess communication method based on COM cross-process calling and shared memory comprises a dynamic allocation module, a format interpretation module and an output parameter module,
a calling end in the dynamic allocation module dynamically allocates a continuous memory space in a shared memory, puts data to be transmitted between processes into the memory space according to a set format, and then transmits the initial offset of the memory as a parameter to a corresponding COM interface;
the called end in the format interpretation module obtains the initial position of the shared memory through the parameters of the COM interface, after finding the corresponding position, the called end interprets the memory according to the same format to obtain data, then calls the memory, and after calling is finished, the output parameters are still placed in the shared memory and returned to the calling end;
and after the calling end in the output parameter module finishes calling, a return value is obtained from the COM interface, and an output parameter is obtained in the shared memory.
Compared with the prior art, the invention has the beneficial effects that:
the COM technology adopted by the invention realizes cross-process communication; the adopted shared memory technology realizes the function of transmitting a large amount of data required or returned during COM calling, and reduces the performance overhead of data copying in the COM transmission process. The invention provides a method for efficient interprocess communication and large-amount data transmission.
Drawings
FIG. 1 is a schematic flow diagram of an interprocess communication method based on COM cross-process calling and shared memory according to the present invention;
FIG. 2 is a schematic flow chart of an embodiment of inter-process communication based on COM cross-process invocation and shared memory according to the present invention;
fig. 3 is a schematic diagram of a specific structure of the inter-process communication system based on COM cross-process invocation and shared memory according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. The embodiments described herein are only some embodiments of the invention, and not all embodiments. All other embodiments obtained by a person skilled in the art without making any inventive step on the basis of the spirit of the present invention are within the scope of protection of the present invention.
The present invention will be described in further detail with reference to the accompanying drawings and specific embodiments.
As shown in fig. 1, a method for inter-process communication based on COM cross-process invocation and shared memory combines COM cross-process invocation technology and shared memory technology.
Step 1, a calling end dynamically allocates a continuous memory space in a shared memory, puts data to be transmitted between processes into the memory space according to a set format, and then transmits the initial offset of the memory as a parameter to a corresponding COM interface;
step 2, the called end obtains the initial position of the shared memory through the parameter of the COM interface, after finding the corresponding position, explain this block of memory according to the same format, obtain the data stated in step 1, then call, place the output parameter in this shared memory still after the call is finished, return to the calling end;
step 3, after the calling end finishes calling, a return value is obtained from the COM interface, and an output parameter is obtained in the shared memory;
wherein, COM is a serial communication port; the shared memory is a same internal memory space that can be accessed by a plurality of processes, and is also a communication mode among the processes.
The COM interface adopts a macro mechanism to uniformly process formats in the shared memory, and the macro needs to realize the following three functions:
firstly, automatically calculating the total space occupied by the format memory and dynamically allocating the shared memory, wherein the function can be completed through a class constructor;
secondly, automatically calculating the offset according to the length of the field, and automatically moving the position of the pointer according to the offset;
third, when exiting the scope, the allocated shared memory is automatically released, which can be accomplished through a class destructor.
And the COM informs the called process, the called process acquires the offset and accesses a corresponding position in the shared memory, data is acquired according to the same format, a result is still put into the shared memory after certain logic is executed, the control right is returned to the COM, and the calling end acquires an output result from the shared memory again and returns the output result to the client.
As shown in fig. 2, taking a snapshot-on-write call process of a real-time database as an example (putsanpshots), first, a network service process (server) dynamically allocates a continuous memory space (offset is position) in a shared memory, puts data into the memory space according to a specific format (for example, values of count, ids, dates, ms, values, states, qualities, and errors are sequentially and continuously put into the memory space), and then calls a COM interface with the offset position as a parameter; after being notified, the snapshot service process (snapshot) obtains the offset, accesses a corresponding position in the shared memory, obtains data in the same format, executes the snapshot writing logic, then puts the result (ecode, count, errors) into the shared memory, and returns the control right to the calling thread, and the network service process (server) obtains the output result from the shared memory again, wherein the sequence numbers in fig. 2 illustrate the sequence of various calls.
The application also discloses an interprocess communication system based on the COM cross-process calling and shared memory interprocess communication method, the specific structure is shown in figure 3, which comprises a dynamic allocation module, a format interpretation module and an output parameter module,
a calling end in a dynamic allocation module dynamically allocates a continuous memory space in a shared memory, data to be transmitted between processes is put into the memory space according to a set format, and then initial offset of the memory is taken as a parameter to be transmitted to a corresponding COM interface;
the called end in the format interpretation module obtains the initial position of the shared memory through the parameters of the COM interface, after finding the corresponding position, the called end interprets the memory according to the same format to obtain data, then calls the memory, and after calling is finished, the output parameters are still placed in the shared memory and returned to the calling end;
and after the calling end in the output parameter module finishes calling, a return value is obtained from the COM interface, and an output parameter is obtained in the shared memory.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting the same, and although the present invention is described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that: modifications and equivalents may be made to the embodiments of the invention without departing from the spirit and scope of the invention, which is to be covered by the claims.

Claims (8)

1. An interprocess communication method based on COM cross-process calling and shared memory is characterized by comprising the following steps:
step 1, a calling end dynamically allocates a continuous memory space in a shared memory, preset data to be transmitted among processes is put into the memory space according to a set format, and then the initial offset of the memory space is used as a parameter to be transmitted to a corresponding COM interface; in step 1, the COM interface adopts a macro mechanism to uniformly process formats in the shared memory, automatically calculates the total occupied space of the format memory through a class constructor and dynamically allocates the shared memory; automatically calculating the offset according to the length of the field, and automatically moving the position of the pointer according to the offset; when exiting the scope, automatically releasing the allocated shared memory through the destructor of the class; the calling end comprises a memory offset unit, and the memory offset unit is used for calibrating different initial offsets of the shared memory when the shared memory is loaded in each process;
step 2, the called end obtains the initial position of the shared memory through the parameters of the COM interface, after finding the corresponding position, the memory space is explained according to the same format to obtain the data in the memory space, then the calling is carried out, the output parameters are still placed in the shared memory after the calling is finished and returned to the calling end,
the shared memory is a memory space in the same block accessed by a preset number of processes, and is also an inter-process communication mode;
step 3, after the calling end finishes calling, a return value is obtained from the COM interface, and an output parameter is obtained in the shared memory;
wherein, COM is a serial communication port.
2. The COM-based cross-process call and shared-memory interprocess communication method according to claim 1,
in step 1, the shared memory is used to reduce the performance overhead of data replication in the COM transmission process.
3. The COM-based cross-process call and shared-memory interprocess communication method according to claim 1,
the macro definition in the macro mechanism depends on the number of preset data fields, and when the number of the data fields is different, the number of the macro definitions is multiple; when the number of data fields is the same, the same macro may be reused.
4. The COM-based cross-process call and shared-memory interprocess communication method according to claim 1,
because the output parameter is located in the shared memory, the recovery and release of the shared memory are performed after the call end sends the reply message.
5. The COM-based cross-process call and shared-memory interprocess communication method according to claim 1,
in step 1, the set format is that the data are sequentially and continuously arranged in sequence.
6. The COM-based cross-process call and shared-memory interprocess communication method according to claim 1,
in step 2, the called end adopts the corresponding macro definition for explaining the memory.
7. The COM-based cross-process call and shared-memory interprocess communication method according to claim 1,
in step 3, the output parameter is located in the shared memory, and the recovery and release of the shared memory are performed after the reply message is sent.
8. An interprocess communication system using the COM cross-process call and shared memory based interprocess communication method of any claim 1-7, the system includes a dynamic allocation module, a format interpretation module and an output parameter module, characterized in that:
a calling end in the dynamic allocation module dynamically allocates a continuous memory space in a shared memory, puts data to be transmitted between processes into the memory space according to a set format, and then transmits the initial offset of the memory as a parameter to a corresponding COM interface;
the called end in the format interpretation module obtains the initial position of the shared memory through the parameters of the COM interface, after finding the corresponding position, the called end interprets the memory according to the same format to obtain data, then calls the memory, and after calling is finished, the output parameters are still placed in the shared memory and returned to the calling end;
and after the calling end in the output parameter module finishes calling, a return value is obtained from the COM interface, and an output parameter is obtained in the shared memory.
CN202110257312.0A 2021-03-10 2021-03-10 Inter-process communication method and system based on COM cross-process calling and shared memory Active CN112631815B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110257312.0A CN112631815B (en) 2021-03-10 2021-03-10 Inter-process communication method and system based on COM cross-process calling and shared memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110257312.0A CN112631815B (en) 2021-03-10 2021-03-10 Inter-process communication method and system based on COM cross-process calling and shared memory

Publications (2)

Publication Number Publication Date
CN112631815A CN112631815A (en) 2021-04-09
CN112631815B true CN112631815B (en) 2021-08-17

Family

ID=75297777

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110257312.0A Active CN112631815B (en) 2021-03-10 2021-03-10 Inter-process communication method and system based on COM cross-process calling and shared memory

Country Status (1)

Country Link
CN (1) CN112631815B (en)

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100252084B1 (en) * 1997-11-05 2000-04-15 윤종용 Method for writing/reading data and data access apparatus in multi-process system
CN1257455C (en) * 2002-07-25 2006-05-24 梁肇新 Inter-process calling gate technique
CN101321387A (en) * 2008-07-10 2008-12-10 中国移动通信集团广东有限公司 Voiceprint recognition method and system based on communication system
CN102547575A (en) * 2012-03-12 2012-07-04 成都林海电子有限责任公司 Method and system for determining radio frequency transmitting power by acquiring geographic information
CN107391285B (en) * 2017-08-23 2020-06-30 美的智慧家居科技有限公司 Memory sharing method and system
CN112416625B (en) * 2020-11-30 2024-04-09 深信服科技股份有限公司 Copy-free interprocess communication system and method

Also Published As

Publication number Publication date
CN112631815A (en) 2021-04-09

Similar Documents

Publication Publication Date Title
US8270299B2 (en) Communicator-based token/buffer management for eager protocol support in collective communication operations
EP2919116B1 (en) Global memory sharing method and device and communication system
US10331595B2 (en) Collaborative hardware interaction by multiple entities using a shared queue
CN102630315B (en) Method and system for processing data for preventing deadlock
CN101150487A (en) A transmission method for zero copy network packet
CN101150488A (en) A receiving method for zero copy network packet
CN101178666A (en) Coordinating and scheduling method between heterogeneous multi-core
CN113127139B (en) Memory allocation method and device based on DPDK of data plane development kit
CN113032166A (en) Inter-core communication method, processor, inter-core communication system, and computer-readable storage medium
CN112631815B (en) Inter-process communication method and system based on COM cross-process calling and shared memory
CN114201416A (en) Communication scheduling method for control core MCU and calculation core MPU
CN111913784B (en) Task scheduling method and device, network element and storage medium
EP1891525A2 (en) Techniques for handling lock-related inconsistencies
CN101141417A (en) Inter-task message communicating method in equipment
CN112311695B (en) On-chip bandwidth dynamic allocation method and system
CN115480904A (en) Concurrent calling method for system service in microkernel
CN111817890B (en) Data synchronization processing method and device, computer equipment and storage medium
Ward et al. EDS hardware architecture
CN113434441A (en) DMA transmission method, device, controller and readable storage medium
CN112783675A (en) IPC communication method
CN112235411A (en) AI-based RPA process control end server communication method, device, equipment and medium
CN111049761B (en) Data processing method of wireless water controller communication module
Lin et al. Zero-buffer inter-core process communication protocol for heterogeneous multi-core platforms
CN109522004A (en) A kind of method that ETL process is run in distributed structure/architecture
CN110096374B (en) System and method for controlling communication middleware between internal multi-class computing units

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant