A data processing method and apparatus

By setting the memory block status of the circular buffer to be writing data and pointing to the next writable block in remote asynchronous communication, multi-user parallel operation is achieved, which solves the problems of system overhead and low utilization caused by frequent buffer memory allocation, and improves data processing efficiency and system stability.

CN112882831BActive Publication Date: 2025-11-21ZHEJIANG DAHUA TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202110155702.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-04
Publication Date
2025-11-21
Estimated Expiration
2041-02-04

AI Technical Summary

Technical Problem

In remote asynchronous communication, the frequent memory allocation and release operations of the circular buffer in multi-threaded or multi-process scenarios lead to increased memory fragmentation, increased system overhead, and affect the long-term stable operation of the system. Furthermore, under the mutual exclusion access mechanism, the utilization rate of the buffer by users is low.

Method used

Upon receiving a memory block request, its status is immediately set to "writing data" and pointed to the next writable memory block, allowing other users to operate in parallel, reducing waiting time, and enabling multiple users to read and write to the buffer in parallel.

Benefits of technology

It improves the efficiency of using the circular buffer in multi-threaded or multi-process scenarios, reduces the time spent on data writing and reading, and enhances the stability and efficiency of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112882831B_ABST
    Figure CN112882831B_ABST
Patent Text Reader

Abstract

The application discloses a data processing method and device, which can realize parallel reading and writing of a buffer in a multi-process or multi-thread scene, and improves the data processing efficiency. The method specifically comprises the following steps: receiving a first request, wherein the first request is used for requesting a first memory block in a buffer; setting a state of the first memory block as a first state, wherein the first state is used for representing that the first memory block is being written with data or has been written with data; pointing a write pointer to a second memory block in the buffer, wherein the write pointer is used for pointing to a memory block in the buffer which can currently be written with data; receiving to-be-written data, and writing the to-be-written data into the first memory block.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, and in particular to a data processing method and device. BACKGROUND

[0002] Remote asynchronous communication (including service communication between multiple threads, message communication between processes, data transceiving communication across a network, and caching, etc.) usually adopts a form of request reply, message queue, or cached data. This form of communication involves many memory allocation and release operations, and frequent memory application, allocation, and release not only increase system overhead, but also cause memory fragmentation to continuously increase, which is very detrimental to long-term stable operation of the system. In order to solve this problem, a user can choose to repeatedly use a fixed-size memory space, such as a ring buffer. In addition, remote asynchronous communication also involves scenarios of shared memory between multiple threads or multiple processes, in which multiple users access the same ring buffer mutually exclusively. Therefore, improving the use efficiency of the ring buffer in the scenario of multiple threads or multiple processes is crucial to improving the quality of remote asynchronous communication. SUMMARY

[0003] Embodiments of the present application provide a data processing method and device, which can realize parallel reading and writing of a buffer in a scenario of multiple threads or multiple processes, and improve the efficiency of data processing.

[0004] In a first aspect, an embodiment of the present application provides a data processing method, comprising:

[0005] receiving a first request, the first request being used to request application of a first memory block in a buffer;

[0006] setting a state of the first memory block as a first state, the first state being used to represent that the first memory block is being written with data or has been written with data;

[0007] pointing a write pointer to a second memory block in the buffer, the write pointer being used to point to a memory block in the buffer that is currently writable;

[0008] receiving data to be written, and writing the data to be written into the first memory block.

[0009] Optionally, the method further comprises:

[0010] before a first time, receiving a second request, the second request being used to request application of the second memory block in the buffer; the first time being a time when the data to be written corresponding to the first memory block is completely written into the first memory block;

[0011] setting a state of the second memory block as the first state;

[0012] pointing the write pointer to a third memory block in the buffer.

[0013] Optionally, the method further comprises:

[0014] receiving a data read request;

[0015] determining that the to-be-written data corresponding to the first memory block is completely written to the first memory block at a first time, and that the to-be-written data corresponding to the second memory block is completely written to the second memory block at a second time;

[0016] when the second time is earlier than the first time, pointing a read pointer to the second memory block, so that a data reading device reads data from the second memory block based on the read pointer.

[0017] Optionally, the method further comprises:

[0018] setting a state of the second memory block as a second state, the second state being used to represent that the second memory block is being read data;

[0019] before a third time, pointing the read pointer to the first memory block, so that the data reading device reads data from the first memory block based on the read pointer, wherein the third time is a completion time of reading data in the second memory block.

[0020] Optionally, the method further comprises receiving a data read request;

[0021] pointing a read pointer to the first memory block, so that a data reading device reads data from the first memory block based on the read pointer.

[0022] setting a state of the first memory block as a second state, the second state being used to represent that the first memory block is being read data;

[0023] before a fourth time, pointing the read pointer to the second memory block, so that the data reading device reads data from the second memory block based on the read pointer, wherein the fourth time is a completion time of reading data in the first memory block.

[0024] In a second aspect, an embodiment of the present application provides a data processing device, comprising:

[0025] a receiving unit configured to receive a first request, the first request being used to request a first memory block in a buffer;

[0026] a processing unit configured to set a state of the first memory block as a first state, the first state being used to represent that the first memory block is being written data or has been written data;

[0027] The processing unit is further configured to point the write pointer to a second memory block in the buffer, the write pointer being used to point to a memory block in the buffer that is currently writable;

[0028] The receiving unit is further configured to receive data to be written, and the processing unit is further configured to write the data to be written into the first memory block.

[0029] Optionally, the receiving unit is further configured to receive a second request before a first time, the second request being used to request the second memory block in the buffer, the first time being a time when the data to be written corresponding to the first memory block is completely written into the first memory block;

[0030] The processing unit is further configured to set a state of the second memory block as the first state.

[0031] The processing unit is further configured to point the write pointer to a third memory block in the buffer.

[0032] Optionally, the receiving unit is further configured to receive a data reading request.

[0033] The processing unit is further configured to determine that the data to be written corresponding to the first memory block is completely written into the first memory block at a first time, and the data to be written corresponding to the second memory block is completely written into the second memory block at a second time.

[0034] The processing unit is further configured to, when the second time is earlier than the first time, point a read pointer to the second memory block, so that a data reading device reads data from the second memory block based on the read pointer.

[0035] In a third aspect, an embodiment of the present application provides a data processing device, comprising:

[0036] a memory configured to store computer instructions;

[0037] a processor connected with the memory, configured to execute the computer instructions in the memory, so as to execute the method provided in the first aspect when the computer instructions are executed.

[0038] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, the computer readable storage medium storing computer instructions, when the computer instructions are executed on a computer, causing the computer to execute the method provided in the first aspect.

[0039] In a fifth aspect, an embodiment of the present application provides a computer program product, when the computer program product is executed on a computer, causing the computer to execute the method provided in the first aspect.

[0040] The embodiment of the present application provides a data processing method, after receiving a first request for a first memory block in an application buffer, setting a state of the first memory block as a first state, and pointing a read pointer to a second memory block, so that other users can operate (such as writing data in the second memory block) the second memory block. Generally, after applying for the first memory block, it takes a certain time to write data in the first memory block, and the present application does not need to wait for the data in the first memory block to be completely written before moving the read pointer to the second memory block, but immediately moves the read pointer to the second memory block after applying for the first memory block (that is, setting the state of the first memory block as the first state). When the read pointer is moved to the second memory block, the data in the first memory block has not been written, at this time, the data in the second memory block can also be written, that is, the first memory block and the second memory block can be written in parallel, so that multiple users can read and write multiple memory blocks in the ring buffer in a multi-thread or multi-process scenario, and the efficiency of data processing is improved. BRIEF DESCRIPTION OF DRAWINGS

[0041] Figure 1 A scene schematic diagram corresponding to the data processing method provided by the embodiment of the present application is provided.

[0042] Figure 2 A method schematic diagram for writing data into a ring buffer in the prior art is provided.

[0043] Figure 3 A flow schematic diagram of the data processing method provided by the embodiment of the present application is provided.

[0044] Figure 4 A method schematic diagram for writing data into a ring buffer provided by the embodiment of the present application is provided.

[0045] Figure 5 A specific flow schematic diagram of the data processing method provided by the embodiment of the present application is provided.

[0046] Figure 6 A method schematic diagram for reading data from a ring buffer provided by the embodiment of the present application is provided.

[0047] Figure 7 A method schematic diagram for reading data from a ring buffer provided by the embodiment of the present application is provided.

[0048] Figure 8 A structure schematic diagram of a data processing device provided by the embodiment of the present application is provided.

[0049] Figure 9 A structure schematic diagram of another data processing device provided by the embodiment of the present application is provided. DETAILED DESCRIPTION

[0050] In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the technical solutions of the present application, rather than all the embodiments. Based on the embodiments described in the present application document, all other embodiments obtained by a person of ordinary skill in the art without creative labor fall within the scope of protection of the technical solutions of the present application.

[0051] Generally, the cache area has various forms, such as a ring-shaped cache area, a strip-shaped cache area, and the like. Taking the ring-shaped buffer area as an example, its storage space is logically connected at the head and tail, and is a one-dimensional fixed-length continuous linear structure in physical storage. The ring-shaped buffer area usually has a read pointer and a write pointer, the read pointer points to the readable data in the ring-shaped buffer area, and the write pointer points to the writable buffer area in the ring-shaped buffer area. By moving the read pointer and the write pointer, the reading and writing of the buffer area data can be realized. In a general case, the read user of the ring-shaped buffer area only affects the read pointer, and the write user only affects the write pointer. If there is only one read user and one write user, a mutual exclusion protection mechanism does not need to be added to ensure the correctness of the data. If there are multiple read users or write users accessing the ring-shaped buffer area, a mutual exclusion protection mechanism needs to be added to ensure that multiple users access the ring-shaped buffer area mutually exclusively.

[0052] Under the mutual exclusion access mechanism, when one of the multiple users is accessing the ring-shaped buffer area, the ring-shaped buffer area is in a locked state for other users, indicating that the ring-shaped buffer area is currently used to process a user request to write data or read data. If other users request to write data or read data at this time, the reading and writing requests of the other users need to be processed after the current user's request is processed. Generally, the reading and writing process of the user takes relatively large time, and therefore the utilization rate of the ring-shaped buffer area by the user is low under the mutual exclusion access mechanism.

[0053] In view of this, the embodiments of the present application provide a data processing method, which can realize parallel reading and writing of multiple users on the ring-shaped buffer area. Compared with the above mutual exclusion access mechanism, the reading and writing requests of other users can be processed without processing the request of the current user, thereby greatly reducing the time consumption of the user reading and writing data and improving the use efficiency of the ring-shaped buffer area in the case that multiple read users or write users access the ring-shaped buffer area.

[0054] The technical solutions provided by the embodiments of the present application will be described below with reference to the drawings in the specification.

[0055] Reference Figure 1 The scene schematic diagram corresponding to the data processing method provided by the embodiments of the present application.

[0056] Figure 1 The scenario in the embodiment includes one ring buffer in a terminal device and five users which perform read and write operations on the ring buffer. Among them, user 1, user 2 and user 3 apply to write data into the ring buffer, and user 4 and user 5 apply to read data from the ring buffer. Figure 1 The ring buffer is taken as an example in the embodiment, and the scheme in the embodiment can also be applied to other types of buffers with mutual exclusion protection mechanism in the specific implementation process. In addition, Figure 1 The ring buffer in the embodiment can also be a storage space of any size specified in the memory space of any terminal device, and the terminal device can be a desktop computer, a notebook computer, a palm computer, a smart tablet, a mobile terminal, a cloud server and other computing devices, and the embodiment of the present application does not make any limitation in this regard. Figure 1 The ring buffer is taken as an example in the embodiment, and the scheme in the embodiment can also be applied to other types of buffers with mutual exclusion protection mechanism in the specific implementation process. In addition,

[0057] It should be noted that the scenarios mentioned above are only shown for the purpose of facilitating the understanding of the spirit and principles of the present application, and the embodiments of the present application are not limited in this regard. On the contrary, the embodiments of the present application can be applied to any applicable scenario.

[0058] In order to better illustrate the technical scheme provided by the present application, the embodiments in the following are all based on the scenario described in the above Figure 1 The scenario described in the embodiment is as follows. First, Figure 2 is a schematic diagram of a method for writing data into a ring buffer in the prior art.

[0059] As Figure 2As shown, in step one, the write pointer 204 initially points to memory block 201. When users 1, 2, and 3 sequentially request to write data to the circular buffer, under the mutual exclusion mechanism, user 1 requests to write data to the circular buffer first. Therefore, the right to use memory block 201 pointed to by write pointer 204 is allocated to user 1, allowing user 1 to write data to memory block 201. As shown in step two, after user 1 finishes writing data (memory block 201 in step two turns black to indicate that the data writing is complete), the write pointer points to memory block 202. Then, in step three, the terminal device responds to user 2's request to write data and allocates memory block 202 pointed to by write pointer 201 to user 2. In step four, after user 2 finishes writing data to memory block 202, the write pointer points to memory block 203, and then user 3 can request memory block 203 and write data to it. Using this existing data writing method, if it takes 2 minutes for user 1 to write the corresponding data to memory block 201, 1 minute for user 2 to write the corresponding data to memory block 202, and 3 minutes for user 3 to write the corresponding data to memory block 203, then the total time for these three users to write data is at least 2 + 1 + 3 = 6 minutes. Therefore, the time spent writing or reading data results in low efficiency of the circular buffer.

[0060] To address the shortcomings of existing technologies, embodiments of the present invention provide a data processing method, the specific process of which is as follows: Figure 3 As shown, it includes the following steps:

[0061] Step 301: Receive the first request. The first request is used to request the first memory block in the buffer.

[0062] If a user wants to write data to the circular buffer, the user first needs to request a fixed-size memory block in the circular buffer. The capacity of this memory block must be greater than or equal to the size of the data to be written. After the user requests the first memory block from the terminal device, the terminal device responds to the user's request and grants the user the right to use the first memory block, allowing the user to perform arbitrary read and write operations on the first memory block.

[0063] For example Figure 4 As shown in step 1, after receiving the first request from user 1, the terminal device allocates the right to use memory block 401 in the circular buffer to user 1, so that user 1 can perform arbitrary read and write operations on memory block 401.

[0064] Step 302: Set the state of the first memory block to a first state, which is used to indicate that the first memory block is being written to or has been written to.

[0065] The terminal device sets the state of the first memory block to the first state after the first memory block is assigned to the user. The first state can be used to represent that the first memory block is being written data, or the first state can also be used to represent that the first memory block has been written data.

[0066] Step 303: Pointing the write pointer to the second memory block in the buffer. The write pointer is used to point to the memory block in the buffer that can be written data currently.

[0067] Step 304: Receiving the data to be written and writing the data to be written into the first memory block.

[0068] Optionally, if a second request is received before the first time, the second request is used to request the second memory block in the buffer, the state of the second memory block is set to the first state, wherein the first time is the time when the data to be written corresponding to the first memory block is completely written into the first memory block. Finally, the write pointer is pointed to the third memory block in the buffer.

[0069] For example Figure 4 As shown, the terminal device is provided with a write pointer 404, a head pointer 405 and a tail pointer 406 in the ring buffer, wherein the write pointer is used to point to the memory block in the ring buffer that can be written data, the head pointer is used to point to the first memory block that is applied to write data, and the tail pointer is used to point to the last memory block that is applied to write data. When no data is written, the head pointer 405, the tail pointer 406 and the write pointer 404 point to the same position in the ring buffer. As shown in step 1, when the use right of the memory block 401 is assigned to the user 1 (the memory block 401 moves away from the original position in step 1, which means that the use right is assigned or occupied), the state of the memory block 401 is set to the first state, in which state, no other user except the user 1 can apply for the memory block 1, and no data writing or reading operation can be performed on the memory block 401, and at the same time, the first state also represents that the memory block 401 is being written data. After the terminal device sets the state of the memory block 401 to the first state, the pointer 404 points to the next memory block of the memory block 401 that can be written data, the head pointer 405 points to the first applied memory block (i.e. the memory block 401), and the tail pointer points to the last memory unit of the memory block 401.

[0070] If the terminal device receives a second request of user 2 to write data before the data corresponding to user 1 is completely written into the memory block 401, user 2 can apply for the memory block 402 pointed by the write pointer after the terminal device sets the state of the memory block 401 to the first state, as shown in step 2, the terminal device sets the state of the memory block 402 to the first state to indicate that the memory block 402 is occupied by user 2 and used to write data. After the terminal device sets the memory block 402 to the first state, the terminal device continues to point the write pointer 404 to the next memory block that can be written data in the memory block 402, the head pointer 405 points to the memory block 401, and the tail pointer points to the last memory cell of the memory block 402, as shown in step 2. Figure 4

[0071] Similarly, before the data corresponding to user 2 is completely written into the memory block 402, user 3 can apply for and write data in the next memory block that can be written data pointed by the write pointer 404. As shown in step 3, the terminal device sets the state of the memory block 403 to the first state to indicate that the memory block 403 is being written data by user 3, at this time, the write pointer 404 points to the next memory block that can be written data in the memory block 403, the head pointer 405 points to the memory block 401, and the tail pointer points to the last memory cell of the memory block 403.

[0072] The terminal device sets the state of the memory block quickly, which can be ignored. If the time interval of user 1, user 2 and user 3 applying for the memory block is small, and it takes 2 minutes for user 1 to completely write data into the memory block 401, it takes 1 minute for user 2 to completely write data into the memory block 402, and it takes 3 minutes for user 3 to completely write data into the memory block 403, as shown in steps 4-6, in the first minute after the terminal device receives the request of user 1 to write data, the memory block 402 is completely written data and is released (the memory block 402 becomes dark in step 4 to indicate that it is completely written data, and the memory block returns to the original position to indicate that it is released), in the second minute, the memory block 401 is completely written data and is released, and in the third minute, the memory block 403 is completely written data and is released. The total time for the three users to write data blocks into the corresponding memory blocks is 3 minutes. Compared with the time required for data processing (6 minutes) by using the prior art, the parallel writing of data in the ring buffer by using the method provided in the embodiment of the application greatly saves the time required for data writing and improves the efficiency of data processing. Figure 2

[0073] ​​It has been described above how to use the data processing method provided in the embodiments of the present application to write the data blocks corresponding to multiple users into the ring buffer in parallel. In the actual implementation process, there are cases where multiple users apply to write data into the ring buffer and multiple users apply to read data from the ring buffer at the same time. The following takes the case of Figure 5 as an example to specifically describe the data processing method provided in the embodiments of the present application, which specifically includes the following steps:

[0074] Step 501: initialization of the ring buffer.

[0075] The terminal device needs to perform initialization processing on the obtained ring buffer. Specifically, the terminal device can place a head node at the head of the ring buffer to record the information of the ring buffer, which includes buffer size information, state records of writing data or reading data, etc. In the initialization process, the terminal device can also place a head pointer, a tail pointer, a write pointer and a read pointer in the ring buffer.

[0076] In the initialization process, the terminal device can also set whether the ring buffer supports / does not support overwrite. If the terminal device sets the ring buffer to support overwrite, when the memory space in the ring buffer is full, the newly written data can overwrite the first written data. On the contrary, if the terminal device sets the ring buffer to not support overwrite, when the memory space in the ring buffer is full, no new data can be written.

[0077] After the initialization is completed, the terminal device waits for the reading or writing request of the ring buffer from other users.

[0078] When a user applies to write data into the ring buffer, step 5010 is performed: receiving the data writing request.

[0079] Step 5011: judging whether there is free memory between the head pointer and the tail pointer. If not, step 5012 is performed, otherwise step 5013 is performed.

[0080] Step 5012: allocating the tail memory block.

[0081] Step 5013: allocating the gap memory block.

[0082] When a user applies to write data into the ring buffer, the data can be written according to the method described in the above Figure 3 . Here, no further description is given. It should be noted that when the user A applies to write data, it can be first judged whether there is a free memory block between the head pointer and the tail pointer, which is not written with data and not occupied by other users, wherein the head pointer is used to point to the first memory block applied to write data, and the tail pointer is used to point to the last memory block applied to write data.

[0083] by Figure 6 For example, in the circular buffer corresponding to step a in the figure, memory blocks 601, 602 and 603 between the head pointer 604 and the tail pointer 605 have all been written with data. It can be seen that there is no free memory between the head pointer and the tail pointer at this time. Therefore, when a user requests to write data, the tail memory block, that is, the memory block after memory block 603, needs to be allocated.

[0084] Correspondingly, when the memory block between the head pointer 604 and the tail pointer 605 in the circular buffer is freed (e.g.) Figure 6 In the circular buffer corresponding to step d, memory block 602 has been released and becomes a free memory block. At this time, when a user requests to write data, the free memory 602 in the middle can be allocated.

[0085] Another possibility is that there is a free memory block between the head and tail pointers in the circular buffer, but the size of this free memory block is insufficient to write new data. Therefore, alternatively, the size of the data to be written can be compared with the size of the free memory block between the head and tail pointers. When the size of the data to be written is smaller than the size of the free memory block between the head and tail pointers, the data to be written can be written into the free memory block between the head and tail pointers; when the size of the data to be written is larger than the size of the free memory block between the head and tail pointers, the data to be written can be written into the free memory block after the tail pointer.

[0086] For example Figure 6 In step d, there is a free memory block 602. When the size of the data to be written is less than the capacity of memory block 602, the data to be written can be written into memory block 602, or as shown in step e, the data to be written can be written into the newly allocated memory block 607. When the size of the data block to be written is greater than the free memory block between the head and tail pointers, the tail memory block 608 can be allocated to the corresponding user for writing the data to be written, as shown in step f.

[0087] Step 5014: Write the pointer to the next memory block.

[0088] After the terminal device allocates a memory block to the user, it sets the write pointer to the next memory block that can be written to, so that other users can continue to write data.

[0089] Step 5015: Write data. After the terminal device allocates the corresponding memory block to the user, the user can write data. During this period, other users can continue to request and write data to other memory blocks in the circular buffer.

[0090] Step 5016: Confirm that the data writing is complete.

[0091] Step 5017: updating the memory block state to data written.

[0092] When the user writes the data completely into the corresponding memory block, the terminal device can determine that the corresponding data has been written according to the corresponding state flag bit of the memory block, then update the state of the memory block to data written, and release the occupation of the memory block by the user, so that other users can read the memory block.

[0093] Corresponding to the above step 5010, when the user applies to read data from the buffer, step 5020 is performed: receiving the data read request.

[0094] In one case, when the terminal device receives the data read request of the user, the data in the memory block can be read in the order of writing first and reading first. Specifically, after receiving the data read request, the terminal device determines that the to-be-written data corresponding to the first memory block is completely written into the first memory block at the first time, and the to-be-written data corresponding to the second memory block is completely written into the second memory block at the second time; when the second time is earlier than the first time, the terminal device points the read pointer to the second memory block, so that the data reading device reads data from the second memory block based on the read pointer.

[0095] If the terminal device receives data read requests of multiple users, similar to the method of writing data into the memory block in parallel as described in the above Figure 3 , the terminal device can also adopt the parallel reading mode: the terminal device sets the state of the above-mentioned second memory block to a second state, the second state is used to represent that the second memory block is being read data, and points the read pointer to the first memory block before the third time, so that the data reading device reads data from the first memory block based on the read pointer, wherein the third time is the completion time of reading the data in the second memory block.

[0096] For example, as shown in Figure 6 , the terminal device can read the data in the memory block in the order of writing first and reading first. Figure 6As shown in step a, there are three memory blocks 601, 602 and 603 in the circular buffer, which have been written with data. The memory blocks 601, 602 and 603 start to write data at nearly the same time, the memory block 602 takes 1 minute to write data, the memory block 601 takes 2 minutes to write data, and the memory block 603 takes 3 minutes to write data. Therefore, the data to be written in the memory block 602 is completely written into the memory block 602 at the earliest time, and the data to be written in the memory block 603 is completely written into the memory block 603 at the latest time. There is a head pointer 604 pointing to the memory block 601 which is applied first in the circular buffer, there is a tail pointer 605 pointing to the memory block 603 which is applied last, and there is a read pointer 606 pointing to the memory block 602 which is completely written with data first.

[0097] If there are user 4 and user 5 who apply to read data in the memory blocks in the circular buffer successively, the terminal device allocates the use right of the memory block 602 to the user 4 based on the data reading request of the user 4, and sets the state of the memory block 602 as the second state. In the second state, no other user except the user 4 can operate the memory block 602, and the second state represents that the memory block 602 is occupied by the user 4 and the data reading is performed. After the terminal device sets the memory block 602 as the second state, the read pointer can be pointed to the second memory block 601 which is completely written with data before the user 4 completely reads the data in the memory block 602, and then the use right of the memory block 601 is allocated to the user 5 based on the data reading request of the user 5, so that the user 5 can read the data in the memory block in parallel with the user 4, and the efficiency of reading the data in the memory block by multiple users is improved.

[0098] In another case, when the terminal device receives the data reading request of the user A, the data in the memory block can be read in the order of first application first reading. Specifically, since the first memory block is the memory block which is applied first, after receiving the data reading request, the terminal device points the read pointer to the first memory block, so that the data reading device reads data from the first memory block based on the read pointer.

[0099] If the terminal device receives the data reading request of multiple users, and the data reading request of the user A is received first, the terminal device can read the data in the memory block in the order of first application first reading. Figure 3 Similar to the method of writing data in the memory block in parallel as described in the above, the method of reading data in parallel can also be adopted. The terminal device sets the state of the first memory block as the second state, and the second state is used to represent that the first memory block is being read, and points the read pointer to the second memory block before the fourth time, so that the data reading device reads data from the second memory block based on the read pointer, and the fourth time is the completion time of reading the data in the first memory block.

[0100] For example, as shown in step A of Figure 7 Figure 7 In the circular buffer, there are three memory blocks 701, 702 and 703 in which data has been written, wherein the memory block 701 is the first to be applied to write data, the memory block 702 is the second, and the memory block 703 is the last. In the circular buffer, there is a head pointer 704 pointing to the first applied memory block 701, a tail pointer 705 pointing to the latest applied memory block 703, and a read pointer 706 pointing to the first applied memory block 701.

[0101] If user 4 and user 5 successively apply to read data in the memory block of the circular buffer, the terminal device allocates the use right of the memory block 701 to user 4 based on the data reading request of user 4, and then sets the state of the memory block 701 to the second state, in which state other users except user 4 cannot operate the memory block 701, and the second state indicates that the memory block 701 is being occupied by user 4 for data reading. After the terminal device sets the memory block 701 to the second state, the read pointer can be pointed to the second memory block 702 applied to write data before user 4 completely reads the data in the memory block 701, and then the use right of the memory block 702 is allocated to user 5 based on the data reading request of user 5, so that user 5 can read data in the memory block in parallel with user 4, improving the efficiency of multiple users reading data in the memory block.

[0102] After the above method is executed to step 5020, step 5021 is continued: the read pointer is pointed to the next memory block.

[0103] After the terminal device allocates the memory block to user A, the read pointer is pointed to the next memory block in which data can be read, so that other users can continue to read data.

[0104] Step 5022: reading data. After the terminal device allocates the memory block to user A, user A can read data, during which other users can continue to apply for memory blocks for data reading.

[0105] Step 5023: determining that data reading is complete.

[0106] Step 5024: updating the state of the memory block to the idle state.

[0107] When user A completely reads the data in the corresponding memory block, the occupation of the memory block by user A is released, the data in the memory block is emptied, and the state of the memory block is updated to the idle state, so that other users can reapply for data writing in the memory block.

[0108] ​Based on the same inventive concept, the embodiments of the present application provide a data processing apparatus capable of realizing the functions corresponding to the data processing method described above. The data processing apparatus can be a hardware structure, a software module, or a hardware structure plus a software module. The data processing apparatus can be realized by a chip system, which can be composed of a chip or can include a chip and other discrete devices. Please refer to Figure 8 The apparatus comprises:

[0109] The receiving unit 801 is configured to receive a first request for applying for a first memory block in a buffer area;

[0110] The processing unit 802 is configured to set the state of the first memory block to a first state, wherein the first state represents that the first memory block is being written with data or has been written with data;

[0111] The processing unit 802 is further configured to point the write pointer to a second memory block in the buffer area, wherein the write pointer is used to point to a memory block in the buffer area that can currently be written with data;

[0112] The receiving unit 801 is further configured to receive data to be written, and the processing unit 802 is further configured to write the data to be written into the first memory block.

[0113] Optionally, the receiving unit 801 is further configured to receive a second request for applying for the second memory block in the buffer area before a first time, wherein the first time is the time when the data to be written corresponding to the first memory block is completely written into the first memory block;

[0114] The processing unit 802 is further configured to set the state of the second memory block to the first state;

[0115] The processing unit 802 is further configured to point the write pointer to a third memory block in the buffer area.

[0116] Optionally, the receiving unit 801 is further configured to receive a data reading request;

[0117] The processing unit 802 is further configured to determine that the data to be written corresponding to the first memory block is completely written into the first memory block at a first time, and the data to be written corresponding to the second memory block is completely written into the second memory block at a second time;

[0118] The processing unit 802 is further configured to point a read pointer to the second memory block when the second time is earlier than the first time, so that a data reading apparatus reads data from the second memory block based on the read pointer.

[0119] All the related contents of the steps involved in the foregoing embodiment of the data processing method can be cited to the function description of the function modules corresponding to the data processing device in the embodiments of the present application, and will not be repeated here.

[0120] The division of the modules in the embodiments of the present application is illustrative, and is only a logical function division. In actual implementation, there can be another division manner. In addition, each function module in each embodiment of the present application can be integrated in one processor, or can be a separate physical existence, or two or more modules can be integrated in one module. The integrated module can be realized in the form of hardware or in the form of a software function module.

[0121] Please refer to Figure 9 , based on the same inventive concept, the embodiments of the present application provide a data processing device, which comprises at least one processor 901, and the processor 901 is used to execute the computer program stored in the memory, and realize the steps of the data processing method as shown in Figure 3 .

[0122] Optionally, the processor 901 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, which can realize or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the data processing method disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or be executed by a combination of hardware and software modules in the processor.

[0123] Optionally, the data processing device can further comprise a memory 902 connected with the at least one processor 901, and the memory 902 stores instructions executable by the at least one processor 901. The at least one processor 901 can execute the steps included in the foregoing data processing method by executing the instructions stored in the memory 902.

[0124] The specific connection medium between the processor 901 and the memory 902 is not limited in the embodiments of the present application. The memory 902 can include at least one type of storage medium, for example, can include flash memory, a hard disk, a multimedia card, a card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), a magnetic memory, a magnetic disk, an optical disk, and the like. The memory 902 is any other medium capable of carrying or storing desired program codes in the form of instructions or data structures and capable of being accessed by a computer, but is not limited thereto. The memory 902 in the embodiments of the present application can also be a circuit or any other device capable of achieving a storage function, for storing program instructions and / or data.

[0125] The processor 901 can be designed and programmed to solidify the codes corresponding to the data processing method introduced in the foregoing embodiments into a chip, so that the chip can execute the steps of the foregoing data processing method at runtime. How to design and program the processor 901 is a technology known to those skilled in the art, and thus will not be described here. The entity devices corresponding to the receiving unit 801 and the processing unit 802 can all be the processor 901. The data processing apparatus can be used to execute the method provided by the embodiments shown in the foregoing embodiments. Therefore, as to the functions that can be achieved by each functional module in the apparatus, reference can be made to the corresponding descriptions in the foregoing embodiments, and thus will not be described here. Figure 3 The processor 901 can be designed and programmed to solidify the codes corresponding to the data processing method introduced in the foregoing embodiments into a chip, so that the chip can execute the steps of the foregoing data processing method at runtime. How to design and program the processor 901 is a technology known to those skilled in the art, and thus will not be described here. The entity devices corresponding to the receiving unit 801 and the processing unit 802 can all be the processor 901. The data processing apparatus can be used to execute the method provided by the embodiments shown in the foregoing embodiments. Therefore, as to the functions that can be achieved by each functional module in the apparatus, reference can be made to the corresponding descriptions in the foregoing embodiments, and thus will not be described here. Figure 3 The processor 901 can be designed and programmed to solidify the codes corresponding to the data processing method introduced in the foregoing embodiments into a chip, so that the chip can execute the steps of the foregoing data processing method at runtime. How to design and program the processor 901 is a technology known to those skilled in the art, and thus will not be described here. The entity devices corresponding to the receiving unit 801 and the processing unit 802 can all be the processor 901. The data processing apparatus can be used to execute the method provided by the embodiments shown in the foregoing embodiments. Therefore, as to the functions that can be achieved by each functional module in the apparatus, reference can be made to the corresponding descriptions in the foregoing embodiments, and thus will not be described here.

[0126] Based on the same inventive concept, the embodiments of the present application further provide a computer readable storage medium storing computer instructions, which, when executed on a computer, cause the computer to perform the steps of the data processing method as described above.

[0127] In some possible implementation, the various aspects of the data processing method provided by the present application can also be implemented in the form of a program product, which includes program codes for causing the detection device to perform the steps of the data processing method according to various exemplary embodiments of the present application described above in the specification when the program product is run on an electronic device. Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) having computer-usable program codes contained therein.

[0128] The present application is described with reference to the flowcharts and / or block diagrams of the method, device (system), and computer program product according to the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as a combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate a means for implementing the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 an apparatus for performing the functions specified in the flowcharts and / or block diagrams.

[0129] These computer program instructions can also be stored in a computer-readable memory that can direct the computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a product including instruction apparatus, which implements the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 an apparatus for performing the functions specified in the flowcharts and / or block diagrams.

[0130] 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 performed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide a means for implementing the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 an apparatus for performing the functions specified in the flowcharts and / or block diagrams.

[0131] Obviously, many modifications and variations of the present application are possible in light of the above teachings. It is, therefore, to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.

Claims

1. A data processing method, characterized by, The method comprises: receiving a first request for requesting a first memory block in a buffer area; setting a state of the first memory block as a first state, the first state being used to represent that the first memory block is being written with data or has been written with data; pointing a write pointer to a second memory block in the buffer area, the write pointer being used to point to a memory block in the buffer area that is currently writable; receiving data to be written, and writing the data to be written into the first memory block; receiving a data reading request; determining that the data to be written corresponding to the first memory block is completely written into the first memory block at a first time, and that the data to be written corresponding to the second memory block is completely written into the second memory block at a second time; when the second time is earlier than the first time, pointing a read pointer to the second memory block, so that a data reading device reads data from the second memory block based on the read pointer; setting a state of the second memory block as a second state, the second state being used to represent that the second memory block is being read; before a third time, pointing the read pointer to the first memory block, so that the data reading device reads data from the first memory block based on the read pointer, wherein the third time is a completion time of reading data in the second memory block; before a first time, receiving a second request for requesting the second memory block in the buffer area; the first time is a time when the data to be written corresponding to the first memory block is completely written into the first memory block; setting the state of the second memory block as the first state; pointing the write pointer to a third memory block in the buffer area.

2. The method of claim 1, wherein, The method further comprises: receiving a data reading request; pointing a read pointer to the first memory block, so that a data reading device reads data from the first memory block based on the read pointer; setting a state of the first memory block as a second state, the second state being used to represent that the first memory block is being read; before a fourth time, pointing the read pointer to the second memory block, so that the data reading device reads data from the second memory block based on the read pointer, the fourth time being a completion time of reading data in the first memory block.

3. A data processing apparatus, characterized by, The method comprises: a receiving unit, configured to receive a first request for requesting a first memory block in a buffer area; a processing unit, configured to set a state of the first memory block as a first state, the first state being used to represent that the first memory block is being written with data or has been written with data; the processing unit is further configured to point a write pointer to a second memory block in the buffer area, the write pointer being used to point to a memory block in the buffer area that is currently writable; the receiving unit is further configured to receive data to be written, and the processing unit is further configured to write the data to be written into the first memory block; the receiving unit is further configured to receive a data reading request; the processing unit is further configured to set a state of the first memory block as a second state, the second state being used to represent that the first memory block is being read; The processing unit is further configured to determine that the to-be-written data corresponding to the first memory block is completely written into the first memory block at a first time, and that the to-be-written data corresponding to the second memory block is completely written into the second memory block at a second time; The processing unit is further configured to, when the second time is earlier than the first time, point the read pointer to the second memory block, so that the data reading device reads data from the second memory block based on the read pointer; The processing unit is further configured to set the state of the second memory block to a second state, the second state being used to represent that the second memory block is being read data; Before a third time, the read pointer is pointed to the first memory block, so that the data reading device reads data from the first memory block based on the read pointer, the third time being a completion time of reading data in the second memory block; The receiving unit is further configured to receive a second request before a first time, the second request being used to request to apply for the second memory block in the buffer area, the first time being a time when the to-be-written data corresponding to the first memory block is completely written into the first memory block; The processing unit is further configured to set the state of the second memory block to the first state; The processing unit is further configured to point the write pointer to a third memory block in the buffer area.

4. A data processing apparatus, characterized by, Comprising: a memory, configured to store computer instructions; a processor, connected with the memory, configured to execute the computer instructions in the memory, and execute the method in claim 1 or 2 when executing the computer instructions.

5. A computer readable storage medium, characterized in that, The computer readable storage medium stores computer instructions, when the computer instructions run on the computer, make the computer execute the method in claim 1 or 2.

Citation Information

Patent Citations

  • Method for simultaneously reading and writing memory and data acquisition unit

    CN101493755A

  • Method and device for transmitting data among multiple data sources

    CN105320673A

  • Multi-core processor inter-core communication method and device

    CN106095604A

  • Data reading and writing method and device based on asynchronous annular buffer area

    CN110704335A