CN-121681180-B - Shared memory management method and device, electronic equipment and storage medium
Abstract
The embodiment of the invention provides a shared memory management method, a shared memory management device, electronic equipment and a storage medium, and relates to the technical field of mobile application development. Under the condition that the capacity expansion of the shared memory can be carried out, determining an actual capacity expansion memory according to the size relation between the target memory and the maximum preset memory, and expanding the shared memory according to the actual capacity expansion memory. The target memory is the memory size obtained by expanding the shared memory according to a preset rule. And taking the actual capacity-expanded memory as the expanded shared memory, and informing monitors on the mobile webpage and the native application to update the memory usage statistics. The invention can reduce or even avoid the spending of character string serialization and reverse serialization. And under the condition that the capacity of the shared memory can be expanded, the capacity of the shared memory is expanded, and the stability of data transmission between the native application and the mobile webpage is ensured. The CPU utilization rate is reduced, and the CPU running speed and the data processing efficiency are improved.
Inventors
- CHEN HUIJUN
- ZHANG SHUTING
- WANG TAO
Assignees
- 深圳凡泰极客科技有限责任公司
Dates
- Publication Date
- 20260505
- Application Date
- 20260210
Claims (8)
- 1. The method is characterized in that the method is used for communication between a native application and a mobile webpage, the native application is provided with a shared memory, the shared memory comprises a data storage area, the mobile webpage and the native application read/write data on the shared memory in the form of binary data, and the method comprises the following steps: obtaining the memory utilization rate of the shared memory according to a first pointer, a second pointer and the size of the shared memory based on a preset memory utilization rate calculation formula, wherein the first pointer points to the current writable data position in the data storage area, and the second pointer points to the current readable data position in the data storage area; Under the condition that the capacity expansion of the shared memory can be carried out, determining an actual capacity expansion memory according to the size relation between a target memory and a maximum preset memory, and expanding the shared memory according to the actual capacity expansion memory, wherein the target memory is the memory size after the capacity expansion of the shared memory according to a preset rule; taking the actual capacity-expanded memory as a shared memory after capacity expansion, and informing a monitor on the mobile webpage and the native application to update memory usage statistics; If the shared memory expansion is not possible, generating an error signal, recording the continuous error times, and re-judging whether the shared memory expansion can be performed after a first interval time, if the shared memory expansion can not be performed, generating an error signal, recording the continuous error times, and re-judging whether the shared memory expansion can be performed after the first interval time until the shared memory expansion can be performed is judged, clearing the continuous error times, if the continuous error times exceeds a preset continuous error threshold, re-judging whether the shared memory expansion can be performed after a second interval time which is longer than the first interval time, and increasing the re-judging interval time when the shared memory expansion can not be performed until the shared memory expansion can be performed is judged, and clearing the continuous error times.
- 2. The method of shared memory management as recited in claim 1, wherein the method further comprises: Receiving a writing request, determining a writing data memory required by the writing request, and acquiring the residual memory of a data storage area in the shared memory; If the writing data memory is larger than the residual memory, determining the target memory, and judging whether the capacity expansion of the shared memory can be performed or not based on the maximum preset memory, the shared memory and the target memory; If the capacity expansion of the shared memory can be carried out, the capacity expansion of the shared memory is carried out according to the actual capacity expansion memory, and after the capacity expansion is completed, data are written into the data storage area of the shared memory after the capacity expansion in sequence according to the time sequence.
- 3. The method of claim 1, wherein determining an actual capacity expansion memory according to a size relationship between a target memory and a maximum preset memory, and expanding the shared memory according to the actual capacity expansion memory comprises: if the target memory is smaller than or equal to the maximum preset memory, determining that the target memory is the actual capacity expansion memory; if the target memory is larger than the maximum preset memory, determining that the maximum preset memory is the actual capacity expansion memory; suspending writing data into the shared memory, and creating the actual capacity-expansion memory; migrating the data in the shared memory to the actual capacity-expanding memory; And releasing the shared memory, updating the first pointer and the second pointer, and completing the capacity expansion of the shared memory.
- 4. The method of claim 3, wherein the shared memory and the data storage area of the actual flash memory are both ring buffers, and the transferring the data in the shared memory to the actual flash memory comprises: Determining the current data size of a data storage area in the shared memory, and judging the relative position of the first pointer and the second pointer; If the second pointer is smaller than the first pointer, directly transferring the data in the data storage area in the shared memory to the data storage area in the actual capacity expansion memory; If the second pointer is larger than or equal to the first pointer, determining first partial data according to the current data size and the second pointer, wherein the first partial data is data from the second pointer to the tail of a data storage area in the shared memory; according to the second pointer, the first part of data is migrated to the starting position of the data storage area in the actual capacity expansion memory; and after the second part of data is migrated to the first part of data according to the first pointer, completing data migration, wherein the second part of data is data except the first part of data in a data storage area of the shared memory.
- 5. The method of shared memory management as recited in claim 1, wherein the method further comprises: After the mobile webpage reads data from the shared memory, garbage cleaning is carried out on the shared memory; Calculating the memory utilization rate based on the preset memory utilization rate calculation formula; if the memory utilization rate is always lower than a preset memory utilization rate lower limit value within a preset duration, or a system memory alarm signal of the native application is received, performing memory reduction on the shared memory to obtain an actual reduced memory; and taking the actual reduced memory as the reduced shared memory.
- 6. The shared memory management device is used for communication between a native application and a mobile webpage, wherein the native application is provided with a shared memory, the shared memory comprises a data storage area, the mobile webpage and the native application read/write data on the shared memory in the form of binary data, and the shared memory management device comprises: The memory capacity expansion unit is used for determining an actual capacity expansion memory according to the size relation between the target memory and the maximum preset memory under the condition that the shared memory capacity expansion can be carried out, and expanding the shared memory according to the actual capacity expansion memory; the method comprises the steps of obtaining a target memory, determining whether the target memory can be expanded according to a preset memory utilization rate calculation formula, obtaining the memory utilization rate of the shared memory according to a first pointer, a second pointer and the size of the shared memory, wherein the first pointer is a pointer pointing to the current writable data position in the data storage area, the second pointer is a pointer pointing to the current readable data position in the data storage area, determining whether the target memory can be expanded or not according to a preset memory utilization rate threshold value if the memory utilization rate is larger than the preset utilization rate threshold value, judging whether the shared memory can be expanded or not according to the largest preset memory, the shared memory and the target memory, if the shared memory cannot be expanded, generating an error signal, recording the continuous error times, and re-judging whether the shared memory can be expanded or not after a first interval period, if the shared memory cannot be expanded, generating the error signal, recording the continuous error times, re-judging whether the shared memory can be expanded or not until the continuous error times are increased after the first interval, and if the continuous error times can be expanded, and the continuous error times can be increased after the preset error times are increased when the continuous error times are compared with the preset time, resetting the continuous error times; And the updating notification unit is used for taking the actual capacity-expanded memory as the shared memory after capacity expansion and notifying the mobile webpage and the monitor on the native application to update the memory usage statistics.
- 7. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method according to any one of claims 1 to 5 when the program is executed.
- 8. A computer readable storage medium, characterized in that the computer readable storage medium comprises a computer program, which when run controls a server where the computer readable storage medium is located to implement the steps of the method according to any one of claims 1-5.
Description
Shared memory management method and device, electronic equipment and storage medium Technical Field The present invention relates to the field of mobile application development technologies, and in particular, to a method and apparatus for managing a shared memory, an electronic device, and a storage medium. Background JSBridge (JavaScript Bridge, JS bridge) is a bridge for connecting different technical platforms and languages, which allows JavaScript code to interact with native applications (such as Android and iOS applications), and through JSBridge, developers can realize cross-platform functions, and development efficiency is improved. JSBridge require data to be transferred between JavaScript (the core scripting language of HTML 5) and the environment of different native applications (e.g., iOS WebView or Android WebView), which may be supported by different data types. In the prior art, a large amount of data transmission between JavaScript and native applications needs frequent character string serialization and reverse serialization, so that the CPU utilization rate is high, the overall CPU running speed is reduced, and the overall data processing efficiency is further affected. Disclosure of Invention The invention aims to provide a shared memory management method, a shared memory management device, electronic equipment and a storage medium, which can at least partially solve the technical problems. Embodiments of the invention may be implemented as follows: In a first aspect, an embodiment of the present invention provides a method for managing shared memory, for communication between a native application and a mobile web page, where the native application is provided with a shared memory, and the mobile web page and the native application read/write data on the shared memory in the form of binary data, where the method includes: under the condition that the capacity expansion of the shared memory can be carried out, determining an actual capacity expansion memory according to the size relation between a target memory and a maximum preset memory, and expanding the shared memory according to the actual capacity expansion memory, wherein the target memory is the memory size after the capacity expansion of the shared memory according to a preset rule; and taking the actual capacity-expanded memory as the expanded shared memory, and informing the monitors on the mobile webpage and the native application to update the memory usage statistics. Optionally, the shared memory includes a data storage area, and the method further includes: Obtaining the memory utilization rate of the shared memory according to a first pointer, a second pointer and the size of the shared memory based on a preset memory utilization rate calculation formula, wherein the first pointer is a pointer pointing to the current position of writable data in the data storage area, and the second pointer is a pointer pointing to the current position of readable data in the data storage area; if the memory utilization rate is greater than a preset utilization rate threshold, determining the target memory, and judging whether the capacity expansion of the shared memory can be performed or not based on the maximum preset memory, the shared memory and the target memory; And if the capacity expansion of the shared memory can be carried out, expanding the capacity of the shared memory according to the actual capacity expansion memory. Optionally, the method further comprises: Receiving a writing request, determining a writing data memory required by the writing request, and acquiring the residual memory of a data storage area in the shared memory; If the writing data memory is larger than the residual memory, determining the target memory, and judging whether the capacity expansion of the shared memory can be performed or not based on the maximum preset memory, the shared memory and the target memory; If the capacity expansion of the shared memory can be carried out, the capacity expansion of the shared memory is carried out according to the actual capacity expansion memory, and after the capacity expansion is completed, data are written into the data storage area of the shared memory after the capacity expansion in sequence according to the time sequence. Optionally, the method further comprises: If the shared memory expansion cannot be performed, generating an error signal, recording the continuous error times, and judging whether the shared memory expansion can be performed again after the first interval time; if the shared memory expansion cannot be performed yet, generating an error signal, recording the continuous error times, and re-judging whether the shared memory expansion can be performed after the first interval time until the shared memory expansion can be performed is judged, and resetting the continuous error times; If the continuous error times exceeds a preset continuous error threshold, judging whether the shared memory expa