Memory management method, electronic equipment and vehicle
By determining the memory address list based on memory allocation requests and preset memory unit sizes, the problem of resource waste in memory management is solved, and the rationality of memory management and user experience are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2026-03-13
AI Technical Summary
In existing technologies, memory management methods result in the amount of memory to be allocated being much larger than the amount of memory requested for allocation, leading to resource waste and reducing the rationality of resource management and user experience.
By receiving memory allocation requests, determining the size of the memory to be allocated and the corresponding memory address list based on the memory size indicated in the memory allocation request and the preset memory unit size, obtaining and allocating memory addresses, and using different linked lists to manage memory blocks that are less than or equal to the preset memory unit size and those that are greater than the preset memory unit size.
It improves the rationality of memory address confirmation and user experience, reduces resource waste, and enhances the rationality and efficiency of memory management.
Smart Images

Figure CN121658199A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of vehicle technology, specifically to a memory management method, electronic device, and vehicle. Background Technology
[0002] With the development of vehicle technology, Data Distribution Service (DDS) is becoming increasingly prevalent in vehicle communication, leading to a surge in the number of hardware devices using DDS for communication within vehicles. However, the use of DDS introduces more mechanisms to ensure correct data transmission during vehicle communication, inevitably resulting in greater resource consumption. Therefore, proper memory management is crucial. In existing technologies, in response to memory allocation requests, memory segments with sufficient free memory size to satisfy the requested memory size are typically designated as memory to be allocated. However, this existing memory management method can result in situations where the memory to be allocated is significantly larger than the requested memory, leading to wasted memory resources and reduced efficiency in resource management and user experience. Summary of the Invention
[0003] One objective of this invention is to provide a memory management method to solve the problems of unreasonable resource management and poor user experience in the prior art; another objective is to provide a memory management device; a third objective is to provide an electronic device; a fourth objective is to provide a computer-readable storage medium; a fifth objective is to provide a computer program product; and a sixth objective is to provide a vehicle.
[0004] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0005] A memory management method, the method comprising:
[0006] Receive a memory allocation request; wherein the memory allocation request indicates the size of the memory to be allocated;
[0007] Based on the memory allocation request indicating the requested memory size and the preset memory unit size, determine the size of the memory to be allocated and the corresponding memory address linked list; wherein, the preset memory unit size indicates the size of the pre-divided memory unit; the pre-divided memory unit is a memory unit of the same size as the one pre-divided during memory initialization; the memory address linked list is a linked list used to store memory addresses;
[0008] Based on the determined size of the memory to be allocated, obtain the memory address of the memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated;
[0009] Allocate the memory to be allocated based on the determined memory address.
[0010] Based on the aforementioned technical means, by determining the size of the memory to be allocated and the corresponding memory address list based on the size of the memory requested in the memory allocation request and the size of the preset memory unit, and by retrieving the memory address of the memory to be allocated from the corresponding memory address list based on the determined size of the memory to be allocated, the rationality of the determination of the memory address to be allocated can be improved, and the rationality of memory management based on the determined memory address of the memory to be allocated and the user experience can be further improved.
[0011] Furthermore, the memory address linked list is either a first linked list or a second linked list; wherein, the first linked list is a linked list used to store the memory addresses of memory blocks smaller than the preset memory unit size; and the second linked list is a linked list used to store the memory addresses of memory blocks larger than or equal to the preset memory unit size.
[0012] Based on the above technical means, by storing memory blocks smaller than the preset memory unit size (i.e., the memory addresses of small memory blocks) in a first linked list, and storing memory blocks larger than or equal to the preset memory unit size (i.e., the memory addresses of large memory blocks) in a second linked list, memory management can be improved in terms of rationality and efficiency.
[0013] Furthermore, based on the memory size requested in the memory allocation request and the preset memory unit size, the size of the memory to be allocated and the memory address list corresponding to the memory to be allocated are determined, including: if the memory size requested in the memory allocation request is less than the preset memory unit size, then a value greater than or equal to 2 times the memory size requested in the memory allocation request is determined. n The smallest integer value in bytes is the size of the memory to be allocated, and the first linked list is determined as the memory address linked list corresponding to the memory to be allocated; if the memory size requested by the memory allocation request is N times the size of the preset memory unit, then N times the size of the preset memory unit is determined as the size of the memory to be allocated, and the second linked list is determined as the memory address linked list corresponding to the memory to be allocated; where N is a positive integer; if the memory size requested by the memory allocation request is greater than M times the size of the preset memory unit and less than M+1 times the size of the preset memory unit, then M+1 times the size of the preset memory unit is determined as the size of the memory to be allocated, and the second linked list is determined as the memory address linked list corresponding to the memory to be allocated; where M is a positive integer.
[0014] Based on the aforementioned technical means, when the size relationship between the requested memory size indicated by the memory allocation request and the preset memory unit size is different, determining the size of the memory to be allocated and the memory address list corresponding to the memory to be allocated in different ways can improve the rationality of determining the memory address to be allocated based on the determined size of the memory to be allocated and the memory address list corresponding to the memory to be allocated, and further improve the rationality of memory management based on the determined memory address to be allocated and the user experience.
[0015] Furthermore, based on the determined size of the memory to be allocated, the memory address of the memory to be allocated is obtained from the memory address linked list corresponding to the determined memory to be allocated, including: if the size of the memory requested by the memory allocation request is less than the size of a preset memory unit, then the memory address of the memory to be allocated is obtained from the first linked list based on the determined size of the memory to be allocated; if the size of the memory requested by the memory allocation request is greater than or equal to the size of a preset memory unit, then the memory address of the memory to be allocated is obtained from the second linked list based on the determined size of the memory to be allocated.
[0016] Based on the above technical means, when the size relationship between the memory size requested in the memory allocation request and the preset memory unit size is different, the memory address to be allocated can be obtained from different memory address linked lists. This can improve the rationality of the obtained memory address to be allocated, and further improve the rationality of memory management based on the determined memory address to be allocated and the user experience.
[0017] Further, based on the determined size of the memory to be allocated, the memory address of the memory to be allocated is obtained from the first linked list, including: determining whether there is a memory address in the first linked list that matches the determined size of the memory to be allocated; if there is, then determining one of the at least one matching memory address as the memory address of the memory to be allocated; if there is no such memory address, then determining the pre-divided memory units to be divided, and dividing the determined pre-divided memory units to be divided according to the determined size of the memory to be allocated, storing the memory addresses of multiple divided memory blocks in the first linked list, and determining one of the stored memory addresses of multiple divided memory blocks as the memory address of the memory to be allocated.
[0018] Based on the above technical means, in the process of obtaining the memory address of the memory to be allocated from the first linked list according to the determined size of the memory to be allocated, the method of matching according to the size of the memory to be allocated, or the method of segmenting in combination with the size of the memory to be allocated, can improve the rationality of obtaining the memory address of the memory to be allocated from the first linked list, and further improve the rationality of memory management based on the determined memory address of the memory to be allocated and the user experience.
[0019] Further, determining the pre-partitioned memory unit to be divided includes: determining whether there are pre-partitioned memory units that have been previously divided; wherein, the pre-partitioned memory units that have been previously divided are pre-partitioned memory units that have been divided, allocated, and then completely released; if at least one of the pre-partitioned memory units that have been previously divided exists, then one of the pre-partitioned memory units that have been previously divided is determined as the pre-partitioned memory unit to be divided; otherwise, the memory address of a memory block with the same size as a preset memory unit is obtained from the second linked list, and the preset internal audit unit corresponding to the memory address is determined as the pre-partitioned memory unit to be divided.
[0020] Based on the above technical means, in the process of determining the pre-divided memory units to be divided, first determining whether there are pre-divided memory units that have been previously divided can improve the efficiency of determining the pre-divided memory units to be divided, further improve the efficiency of dividing the determined pre-divided memory units to be divided, and thus improve the efficiency of memory management.
[0021] Further, based on the determined size of the memory to be allocated, obtaining the memory address of the memory to be allocated from the second linked list includes: based on the determined size of the memory to be allocated, filtering the memory address of the most matching combination of preset memory units from the second linked list; wherein, the combination of preset memory units includes at least one preset memory unit; the most matching combination of preset memory units is the smallest combination of preset memory units that is greater than or equal to the determined size of the memory to be allocated; if the size of the filtered most matching combination of preset memory units is the same as the determined size of the memory to be allocated, then the memory address of the filtered most matching combination of preset memory units is determined as the memory address of the memory to be allocated; if the size of the filtered most matching combination of preset memory units is greater than the determined size of the memory to be allocated, then the filtered most matching combination of preset memory units is divided, and the memory address of the divided most matching combination of preset memory units is determined as the memory address of the memory to be allocated.
[0022] Based on the above technical means, in the process of obtaining the memory address of the memory to be allocated from the second linked list according to the determined size of the memory to be allocated, the method of matching according to the size of the memory to be allocated, or the method of partitioning in combination with the size of the memory to be allocated, can improve the rationality of obtaining the memory address of the memory to be allocated from the second linked list, and further improve the rationality of memory management based on the determined memory address of the memory to be allocated and the user experience.
[0023] Furthermore, after allocating the determined memory to be allocated based on the determined memory address, the method further includes: if the size of the memory to be allocated indicated by the memory allocation request is less than the size of the preset memory unit, then the memory address of the determined memory to be allocated is deleted from the first linked list; if the size of the memory to be allocated indicated by the memory allocation request is greater than or equal to the size of the preset memory unit, then the memory address of the determined memory to be allocated is deleted from the second linked list.
[0024] Based on the above technical means, after allocating the determined memory to be allocated based on the determined memory address, deleting the determined memory address from the corresponding linked list can improve the accuracy of memory management and enhance the user experience of memory management.
[0025] Furthermore, the method further includes: receiving a memory release request; wherein the memory release request indicates the address of the memory to be released; and releasing the memory to be released according to the address of the memory to be released indicated by the memory release request.
[0026] Based on the above technical means, the rationality of confirming the memory address to be allocated is improved, and the rationality of releasing the memory to be released is also improved. This further improves the rationality of memory management based on the determined memory address to be allocated and the user experience.
[0027] Furthermore, the memory release request also indicates whether the memory to be released is greater than the size of the preset memory unit; after releasing the memory to be released, the method further includes: if the memory release request indicates that the memory to be released is less than the size of the preset memory unit, then the address of the memory to be released indicated by the memory release request is stored in the first linked list; if the memory release request indicates that the memory to be released is greater than or equal to the size of the preset memory unit, then the address of the memory to be released indicated by the memory release request is stored in the second linked list.
[0028] Based on the above technical means, after releasing the memory to be released, storing the address of the memory to be released indicated by the memory release request into the corresponding linked list can improve the accuracy of memory management and enhance the user experience of memory management.
[0029] A memory management device, the device comprising:
[0030] A receiving module is used to receive a memory allocation request; wherein the memory allocation request indicates the size of the memory to be allocated;
[0031] The determination module is used to determine the size of the memory to be allocated and the memory address list corresponding to the memory to be allocated based on the memory size requested in the memory allocation request and the size of the preset memory unit; wherein, the size of the preset memory unit indicates the size of the pre-divided memory unit; the pre-divided memory unit is a memory unit of the same size as that pre-divided during memory initialization; the memory address list is a linked list used to store memory addresses;
[0032] The acquisition module is used to obtain the memory address of the determined memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated, based on the determined size of the memory to be allocated.
[0033] The management module is used to allocate memory based on the determined memory address to be allocated.
[0034] Furthermore, the memory address linked list is either a first linked list or a second linked list; wherein, the first linked list is a linked list used to store the memory addresses of memory blocks smaller than the preset memory unit size; and the second linked list is a linked list used to store the memory addresses of memory blocks larger than or equal to the preset memory unit size.
[0035] Furthermore, the determining module includes: a first determining unit, configured to determine, if the requested memory size indicated by the memory allocation request is less than the size of a preset memory unit, that the requested memory size is greater than or equal to 2 times the size of the requested memory size indicated by the memory allocation request. nThe first unit is configured to determine the size of the memory to be allocated by the smallest integer value in bytes, and to determine the second linked list as the memory address linked list corresponding to the memory to be allocated; the second unit is configured to determine the size of the memory to be allocated by N times the size of the preset memory unit if the requested memory size indicated by the memory allocation request is N times the size of the preset memory unit, and to determine the second linked list as the memory address linked list corresponding to the memory to be allocated; wherein, N is a positive integer; the third unit is configured to determine the size of the memory to be allocated by M+1 times the size of the preset memory unit if the requested memory size indicated by the memory allocation request is greater than M times the size of the preset memory unit and less than M+1 times the size of the preset memory unit, and to determine the second linked list as the memory address linked list corresponding to the memory to be allocated; wherein, M is a positive integer.
[0036] Furthermore, the acquisition module includes: a first acquisition unit, configured to acquire the memory address of the memory to be allocated from the first linked list according to the determined size of the memory to be allocated if the memory size requested by the memory allocation request is less than the size of a preset memory unit; and a second acquisition unit, configured to acquire the memory address of the memory to be allocated from the second linked list according to the determined size of the memory to be allocated if the memory size requested by the memory allocation request is greater than or equal to the size of a preset memory unit.
[0037] Furthermore, the first acquisition unit is specifically used to: determine whether there is a memory address in the first linked list that matches the size of the determined memory to be allocated; if there is, determine one of the at least one matching memory addresses as the memory address of the memory to be allocated; if there is no matching memory address, determine the pre-divided memory units to be divided, and divide the determined pre-divided memory units to be divided according to the determined size of the memory to be allocated, store the memory addresses of the multiple divided memory blocks in the first linked list, and determine one of the stored memory addresses of the multiple divided memory blocks as the memory address of the memory to be allocated.
[0038] Furthermore, the first acquisition unit is further specifically used for: determining whether there are pre-partitioned memory units with historical partitioning; wherein, the pre-partitioned memory units with historical partitioning are pre-partitioned memory units that have been partitioned, allocated, and then completely released; if there are at least one pre-partitioned memory unit with historical partitioning, then one of the pre-partitioned memory units with historical partitioning is determined as the pre-partitioned memory unit to be partitioned; otherwise, the memory address of a memory block with the same size as a preset memory unit is obtained from the second linked list, and the preset internal audit unit corresponding to the memory address is determined as the pre-partitioned memory unit to be partitioned.
[0039] Further, the second acquisition unit is specifically used for: filtering the memory address of the most matching combination of preset memory units from the second linked list according to the determined size of the memory to be allocated; wherein, the combination of preset memory units includes at least one preset memory unit; the most matching combination of preset memory units is the smallest combination of preset memory units that is greater than or equal to the determined size of the memory to be allocated; if the size of the filtered most matching combination of preset memory units is the same as the determined size of the memory to be allocated, then the memory address of the filtered most matching combination of preset memory units is determined as the memory address of the memory to be allocated; if the size of the filtered most matching combination of preset memory units is greater than the determined size of the memory to be allocated, then the filtered most matching combination of preset memory units is divided, and the memory address of the divided most matching combination of preset memory units is determined as the memory address of the memory to be allocated.
[0040] Furthermore, the management module is also configured to: if the memory size requested by the memory allocation request is less than the size of the preset memory unit, delete the memory address of the determined memory to be allocated from the first linked list; if the memory size requested by the memory allocation request is greater than or equal to the size of the preset memory unit, delete the memory address of the determined memory to be allocated from the second linked list.
[0041] Furthermore, the receiving module is also configured to receive a memory release request; wherein the memory release request indicates the address of the memory to be released; the management module is also configured to release the memory to be released according to the address of the memory to be released indicated by the memory release request.
[0042] Furthermore, the management module is also configured to: if the memory release request indicates that the memory to be released is less than the size of the preset memory unit, then store the address of the memory to be released indicated by the memory release request in the first linked list; if the memory release request indicates that the memory to be released is greater than or equal to the size of the preset memory unit, then store the address of the memory to be released indicated by the memory release request in the second linked list.
[0043] An electronic device includes: a processor, and a memory communicatively connected to the processor;
[0044] The memory stores instructions that the computer executes;
[0045] The processor executes computer execution instructions stored in memory to implement the memory management method as described above in this invention.
[0046] A computer-readable storage medium storing computer program instructions, which, when executed, implement the memory management method described above in this invention.
[0047] A computer program product includes a computer program that, when executed, implements the memory management method as described above in this invention.
[0048] A vehicle, wherein the vehicle is provided with an electronic device that implements the memory management method as described above in this invention.
[0049] The beneficial effects of this invention are:
[0050] By receiving a memory allocation request, determining the size of the memory to be allocated and the corresponding memory address list based on the requested memory size and the preset memory unit size, and then retrieving the memory address from the memory address list based on the determined size of the memory to be allocated, the system can improve the rationality of the memory address confirmation, further enhancing the rationality of memory management based on the determined memory address and improving the user experience. Attached Figure Description
[0051] Figure 1 A flowchart illustrating a memory management method provided in an embodiment of the present invention;
[0052] Figure 2 This is a flowchart provided by an embodiment of the present invention, which determines the size of the memory to be allocated and the memory address linked list corresponding to the memory to be allocated based on the size of the memory requested to be allocated indicated by the memory allocation request and the size of the preset memory unit.
[0053] Figure 3 This is a flowchart provided by an embodiment of the present invention, which describes how to obtain the memory address of a memory to be allocated from a memory address linked list corresponding to the determined memory to be allocated, based on the determined size of the memory to be allocated.
[0054] Figure 4 A flowchart illustrating another memory management method provided in an embodiment of the present invention;
[0055] Figure 5 This is a schematic diagram of the structure of a memory management device provided in an embodiment of the present invention;
[0056] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0057] The embodiments of the present invention will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention and not for limiting the scope of protection of the present invention.
[0058] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0059] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this invention are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with relevant laws, regulations and standards, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0060] In existing technologies, in response to a memory allocation request, a memory segment whose size is sufficient to satisfy the requested memory size is typically identified as the memory to be allocated. However, memory management using existing methods can result in situations where the memory to be allocated is much larger than the requested memory, leading to wasted memory resources, reduced resource management efficiency, and a poor user experience.
[0061] To address the aforementioned problems, this invention provides a memory management method. This method receives a memory allocation request, determines the size of the memory to be allocated and a linked list of memory addresses corresponding to the memory to be allocated based on the requested memory size and a preset memory unit size, retrieves the memory address of the memory to be allocated from the linked list based on the determined size of the memory to be allocated, and allocates the memory based on the determined memory address. By determining the size of the memory to be allocated and the linked list of memory addresses based on the requested memory size and the preset memory unit size, and by retrieving the memory address of the memory to be allocated from the linked list based on the determined size of the memory to be allocated, the rationality of the determination of the memory address to be allocated can be improved, further enhancing the rationality of memory management based on the determined memory address and improving the user experience.
[0062] The technical solution of the present invention will now be described in detail through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0063] Figure 1 This is a flowchart illustrating a memory management method provided in an embodiment of the present invention. Figure 1 As shown, the method of this embodiment of the invention includes:
[0064] Step S101: Receive memory allocation request.
[0065] Specifically, a memory allocation request can be received. This memory allocation request is used to request memory allocation. Specifically, this application does not limit the size of the memory allocation request; any request capable of requesting memory allocation can be used as the memory allocation request provided by this application. Optionally, it can be a request generated in response to an application's startup / running command. The memory allocation request indicates the size of the memory to be allocated. Specifically, this application does not limit the size of the memory to be allocated indicated by the memory allocation request. Optionally, if the received memory allocation request is generated in response to an application's running command, the size of the memory to be allocated indicated by the memory allocation request corresponds to the size of the memory required to run the corresponding application. Optionally, a memory size larger than a preset value for the size of the memory required to run the corresponding application can be determined as the size of the memory to be allocated indicated by the corresponding memory allocation request.
[0066] Step S102: Determine the size of the memory to be allocated and the memory address list corresponding to the memory to be allocated based on the memory size requested in the memory allocation request and the size of the preset memory unit.
[0067] Specifically, based on the memory allocation request size indicated by the memory allocation request received in step S101 and the preset memory unit size, the size of the memory to be allocated and the memory address list corresponding to the memory to be allocated are determined. The preset memory unit size indicates the size of the pre-divided memory units. The pre-divided memory units are memory units of the same size pre-divided during memory initialization. Specifically, memory initialization refers to the process of initializing the memory before receiving the memory allocation request as described in step S101. This application does not limit the process of initializing the memory; optionally, the memory can be pre-divided into multiple memory units of the same size. This application does not limit the size of the pre-divided memory units; optionally, the size of the pre-divided memory units can be set to 4KB, where 4KB is the memory size required to run a management item.
[0068] This application does not limit the process of determining the size of the memory to be allocated based on the requested memory size indicated in the memory allocation request and the preset memory unit size. Any process that can determine the size of the memory to be allocated based on the requested memory size indicated in the memory allocation request and the preset memory unit size can be used as the process provided in this application for determining the size of the memory to be allocated based on the requested memory size indicated in the memory allocation request and the preset memory unit size. Optionally, if the requested memory size indicated in the memory allocation request is less than the preset memory unit size, then the size is determined to be greater than or equal to 2 times the requested memory size indicated in the memory allocation request. nThe smallest integer value is the size of the memory to be allocated; if the memory size requested by the memory allocation request is N times the size of the preset memory unit, then N times the size of the preset memory unit is determined as the size of the memory to be allocated; if the memory size requested by the memory allocation request is greater than M times the size of the preset memory unit and less than M+1 times the size of the preset memory unit, then M+1 times the size of the preset memory unit is determined as the size of the memory to be allocated.
[0069] The memory address linked list is a linked list used to store memory addresses. Specifically, the memory address linked list corresponding to the memory to be allocated is a linked list that stores the memory addresses of the memory to be allocated. This application does not limit the configuration of the memory address linked list; optionally, the memory address linked list can be set as a first linked list and a second linked list. The first linked list is used to store the memory addresses of memory blocks smaller than a preset memory unit size; the second linked list is used to store the memory addresses of memory blocks larger than or equal to the preset memory unit size. This application does not limit the process of determining the memory address list corresponding to the memory to be allocated based on the requested memory size indicated by the memory allocation request and the preset memory unit size. Any process that can determine the memory address list corresponding to the memory to be allocated based on the requested memory size indicated by the memory allocation request and the preset memory unit size can be used as the process provided by this application. Optionally, if the memory address list is set as a first list and a second list, the process of determining the memory address list corresponding to the memory to be allocated based on the requested memory size indicated by the memory allocation request and the preset memory unit size can be as follows: if the requested memory size indicated by the memory allocation request is less than the preset memory unit size, then the first list is determined as the memory address list corresponding to the memory to be allocated; if the requested memory size indicated by the memory allocation request is greater than or equal to the preset memory unit size, then the second list is determined as the memory address list corresponding to the memory to be allocated.
[0070] Optionally, during the memory initialization process described above, one of the pre-divided memory units can be set as the memory control header to store the memory address linked list described above.
[0071] Step S103: Based on the determined size of the memory to be allocated, obtain the memory address of the memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated.
[0072] Specifically, based on the size of the memory to be allocated determined in step S102, the memory address of the memory to be allocated is obtained from the memory address linked list corresponding to the memory to be allocated determined in step S102. This application does not limit the process of obtaining the memory address of the memory to be allocated from the memory address linked list corresponding to the determined size of the memory to be allocated. Any process that can obtain the memory address of the memory to be allocated from the memory address linked list corresponding to the determined size of the memory to be allocated can be considered as the process provided in this application for obtaining the memory address of the memory to be allocated from the memory address linked list corresponding to the determined size of the memory to be allocated. Optionally, if the memory size requested in the memory allocation request is less than the size of a preset memory unit, the process of obtaining the memory address of the memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated can be to obtain the memory address of the memory to be allocated from the first linked list based on the determined memory size; if the memory size requested in the memory allocation request is greater than or equal to the size of a preset memory unit, the process of obtaining the memory address of the memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated can be to obtain the memory address of the memory to be allocated from the second linked list based on the determined memory size.
[0073] Step S104: Allocate the memory to be allocated based on the determined memory address of the memory to be allocated.
[0074] Specifically, the memory to be allocated can be allocated based on the memory address determined in step S103. This application does not limit the process of allocating memory based on the determined memory address; any process capable of allocating memory based on the determined memory address can be considered as the process provided in this application. Optionally, if the received memory allocation request described in step S101 is a request generated in response to an application's execution instruction, the determined memory address can be returned to the device or module that sent the memory allocation request to allocate the memory; that is, the application can access the memory to be allocated through its memory address.
[0075] The memory management method provided in this invention receives a memory allocation request, determines the size of the memory to be allocated and the corresponding memory address list based on the requested memory size and a preset memory unit size, retrieves the memory address of the memory to be allocated from the memory address list based on the determined size of the memory to be allocated, and allocates the memory based on the determined memory address. By determining the size of the memory to be allocated and the corresponding memory address list based on the requested memory size and the preset memory unit size, and by retrieving the memory address of the memory to be allocated from the memory address list based on the determined size of the memory to be allocated, the rationality of the memory address confirmation can be improved, further enhancing the rationality of memory management based on the determined memory address and improving the user experience.
[0076] Figure 2 This is a flowchart illustrating, according to an embodiment of the present invention, the determination of the size of the memory to be allocated and the linked list of memory addresses corresponding to the memory to be allocated based on the size of the memory requested in the memory allocation request and the size of a preset memory unit. Figure 1 Based on the illustrated embodiment, this embodiment of the invention elaborates on the process of determining the size of the memory to be allocated and the linked list of memory addresses corresponding to the memory to be allocated based on the memory size requested in the memory allocation request and the size of a preset memory unit. Figure 2 As shown, the embodiments of the present invention specifically include:
[0077] Optionally, the memory address linked list can be a first linked list or a second linked list. The first linked list stores the memory addresses of memory blocks smaller than a preset memory unit size. The second linked list stores the memory addresses of memory blocks larger than or equal to the preset memory unit size. This application does not limit the size of the memory blocks corresponding to the memory addresses stored in the first linked list; any size smaller than the preset memory unit size can be used as the size of the memory block corresponding to the memory address stored in the first linked list provided in this application. Optionally, a size smaller than the preset memory unit size can be 2... nn bytes are set to the size of the memory block corresponding to the memory address stored in the first linked list provided in this application, where n is an integer value greater than or equal to zero. For example, if the size of the pre-divided memory unit is set to 4KB, the size of the memory block corresponding to the memory address stored in the first linked list can be 1B, or 2B, or 4B, or 8B, or 16B, or 32B, or 64B, or 128B, or 256B, or 516B, or 1024B, or 2048B. In this application, the size of the memory block corresponding to the memory address stored in the second linked list is not limited. Any memory unit larger than or equal to the preset size can be used as the size of the memory block corresponding to the memory address stored in the second linked list provided by this application. Specifically, as described in step S102, before receiving the memory allocation request, the memory is pre-divided into multiple memory units of the same size. Therefore, a positive integer multiple of the preset memory unit size can be set as the size of the memory block corresponding to the memory address stored in the first linked list provided by this application. For example, if the size of the pre-divided memory unit is set to 4KB, then the size of the memory block corresponding to the memory address stored in the second linked list can be 4KB, 8KB, 16KB, or 32KB, etc. By using a first linked list that stores memory blocks smaller than the preset memory unit size (i.e., memory addresses of small memory blocks) and a second linked list that stores memory blocks larger than or equal to the preset memory unit size (i.e., memory addresses of large memory blocks) to manage memory, the rationality and efficiency of memory management can be improved.
[0078] Step S201: If the memory size requested in the memory allocation request is less than the preset memory unit size, then determine that it is greater than or equal to 2 times the memory size requested in the memory allocation request. n The smallest integer value in bytes is the size of the memory to be allocated, and the first linked list is determined as the linked list of memory addresses corresponding to the memory to be allocated.
[0079] Specifically, if the memory size requested in the memory allocation request is smaller than the preset memory unit size, then it can be determined that the memory size requested is greater than or equal to 2 times the size of the memory allocated in the memory allocation request. nThe smallest integer value in bytes represents the size of the memory to be allocated. The description of the memory allocation request and the requested memory size can be found in step S101, and will not be repeated here. The description of the preset memory unit size can be found in step S102, and will not be repeated here. For example: if the preset memory unit size is 4KB, and the requested memory size indicated by the memory allocation request is 120B, then it is determined that the requested memory size indicated by the memory allocation request is less than the preset memory unit size. In this case, it is greater than or equal to 2 times the requested memory size indicated by the memory allocation request. n The smallest integer value is 128 bytes. Therefore, the size of the memory to be allocated can be determined to be 128 bytes. For example, if the preset memory unit size is 4KB, and the memory allocation request indicates a requested memory size of 128 bytes, then the requested memory size is determined to be less than the preset memory unit size. In this case, it is greater than or equal to 2 times the requested memory size. n The smallest integer value is 128 bytes, therefore, the size of the memory to be allocated can be determined to be 128 bytes.
[0080] Specifically, based on the above description of the first linked list, the first linked list is used to store the memory addresses of memory blocks smaller than a preset memory unit size. Therefore, if the memory size requested in the memory allocation request is smaller than the preset memory unit size, the first linked list can be identified as the memory address linked list corresponding to the memory to be allocated. For example, if the preset memory unit size is 4KB, and the memory size requested in the memory allocation request is 120B or 128B, then the first linked list will be identified as the memory address linked list corresponding to the memory to be allocated.
[0081] Step S202: If the memory size requested in the memory allocation request is N times the size of the preset memory unit, then determine N times the size of the preset memory unit as the size of the memory to be allocated, and determine the second linked list as the memory address linked list corresponding to the memory to be allocated.
[0082] Specifically, if the memory size requested in the memory allocation request is N times the size of the preset memory unit, then N times the size of the preset memory unit is determined to be the size of the memory to be allocated. Here, N is a positive integer. For example: if the preset memory unit size is 4KB, and the memory size requested in the memory allocation request is 4KB, then the memory size requested in the memory allocation request is determined to be one time the size of the preset memory unit. In this case, the size of the memory to be allocated can be determined to be one time the size of the preset memory unit, i.e., 4KB. For example: if the preset memory unit size is 4KB, and the memory size requested in the memory allocation request is 8KB, then the memory size requested in the memory allocation request is determined to be twice the size of the preset memory unit. In this case, the size of the memory to be allocated can be determined to be twice the size of the preset memory unit, i.e., 8KB.
[0083] Specifically, based on the above description of the second linked list, it is a linked list used to store the memory addresses of memory blocks larger than or equal to a preset memory unit size. Therefore, if the memory size requested in the memory allocation request is N times the preset memory unit size, it is determined that the memory size requested in the memory allocation request is greater than or equal to the preset memory unit size. Thus, the second linked list can be identified as the memory address linked list corresponding to the memory to be allocated. For example, if the preset memory unit size is 4KB or 8KB, and the memory size requested in the memory allocation request is 4KB, then the second linked list is identified as the memory address linked list corresponding to the memory to be allocated.
[0084] Step S203: If the memory size requested in the memory allocation request is greater than M times the size of the preset memory unit and less than M+1 times the size of the preset memory unit, then M+1 times the size of the preset memory unit is determined as the size of the memory to be allocated, and the second linked list is determined as the memory address linked list corresponding to the memory to be allocated.
[0085] Specifically, if the memory size requested in the memory allocation request is greater than M times the size of the preset memory unit and less than M+1 times the size of the preset memory unit, then M+1 times the size of the preset memory unit is determined as the size of the memory to be allocated. Here, M is a positive integer. For example: If the preset memory unit size is 4KB, and the memory allocation request indicates a requested memory size of 5KB, then the requested memory size of 5KB is greater than twice the preset memory unit size (i.e., twice 4KB) and less than twice the preset memory unit size (i.e., twice 4KB). Therefore, twice the preset memory unit size, i.e., 8KB, can be determined as the size of the memory to be allocated. For example: If the preset memory unit size is 4KB, and the memory allocation request indicates a requested memory size of 10KB, then the requested memory size of 10KB is greater than twice the preset memory unit size (i.e., twice 4KB) and less than three times the preset memory unit size (i.e., three times 4KB). Therefore, three times the preset memory unit size, i.e., 12KB, can be determined as the size of the memory to be allocated.
[0086] Specifically, based on the above description of the second linked list, it is a linked list used to store the memory addresses of memory blocks larger than or equal to a preset memory unit size. Therefore, if the memory size requested in the memory allocation request is greater than M times the preset memory unit size, it is determined that the memory size requested in the memory allocation request is greater than or equal to the preset memory unit size. Thus, the second linked list can be identified as the memory address linked list corresponding to the memory to be allocated. For example, if the preset memory unit size is 5KB or 10KB, and the memory size requested in the memory allocation request is 4KB, then the second linked list is identified as the memory address linked list corresponding to the memory to be allocated.
[0087] The present invention provides a method for determining the size of the memory to be allocated and the corresponding memory address list based on the requested memory size indicated by the memory allocation request and the size of a preset memory unit. When the size relationship between the requested memory size indicated by the memory allocation request and the preset memory unit size is different, different methods are used to determine the size of the memory to be allocated and the corresponding memory address list. This improves the rationality of determining the memory address to be allocated based on the determined size of the memory to be allocated and the corresponding memory address list, further enhancing the rationality of memory management based on the determined memory address and improving the user experience.
[0088] Figure 3This is a flowchart illustrating how, according to an embodiment of the present invention, the memory address of a memory to be allocated is obtained from a linked list of memory addresses corresponding to the determined memory to be allocated. Figure 1 or Figure 2 Based on the illustrated embodiment, this embodiment elaborates on the process of obtaining the memory address of the determined memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated, according to the determined size of the memory to be allocated. Figure 3 As shown, the embodiments of the present invention specifically include:
[0089] Step S301: If the memory size requested by the memory allocation request is less than the size of the preset memory unit, then the memory address of the memory to be allocated is obtained from the first linked list according to the determined size of the memory to be allocated.
[0090] Specifically, based on the above description of the process of determining the size of the memory to be allocated and the linked list of memory addresses corresponding to the memory to be allocated according to the size of the memory requested in the memory allocation request and the size of the preset memory unit, if the size of the memory requested in the memory allocation request is smaller than the size of the preset memory unit, then the first linked list is determined to be the linked list of memory addresses corresponding to the memory to be allocated. Therefore, if the size of the memory requested in the memory allocation request is smaller than the size of the preset memory unit, the memory address of the memory to be allocated can be obtained from the first linked list according to the determined size of the memory to be allocated.
[0091] This application does not limit the process of obtaining the memory address of the memory to be allocated from the first linked list based on the determined size of the memory to be allocated. Any process that can obtain the memory address of the memory to be allocated from the first linked list based on the determined size of the memory to be allocated can be used as the process provided by this application for obtaining the memory address of the memory to be allocated from the first linked list based on the determined size of the memory to be allocated.
[0092] Optionally, it can be first determined whether there exists a memory address in the first linked list that matches the determined size of the memory to be allocated. Specifically, if the size of the memory to be allocated determined in step S201 is the same as the memory size of the memory block corresponding to at least one of the multiple memory addresses stored in the first linked list, then it is determined that there exists a memory address in the first linked list that matches the determined size of the memory to be allocated; if the size of the memory to be allocated determined in step S201 is different from the memory size of the memory block corresponding to each of the multiple memory addresses stored in the first linked list, then it is determined that there exists a memory address in the first linked list that matches the determined size of the memory to be allocated.
[0093] Optionally, if such a memory address exists, one of the at least one matched memory addresses is determined as the memory address of the memory to be allocated. Specifically, based on the above judgment, if it is determined that there is a memory address in the first linked list that matches the size of the memory block to be allocated, that is, the size of the memory to be allocated determined in step S201 is the same as the size of the memory block corresponding to at least one of the multiple memory addresses stored in the first linked list, then one of the at least one matched memory addresses, that is, the memory address of one of the memory blocks in the first linked list that is the same size as the memory to be allocated, is determined as the memory address of the memory to be allocated. For example: if the determined size of the memory to be allocated is 128B, and the memory addresses stored in the first linked list include the memory addresses of at least one 128B memory block, then the memory address of one of the at least one 128B memory block addresses is determined as the memory address of the memory to be allocated.
[0094] Optionally, if no such memory unit exists, a pre-divided memory unit to be segmented is determined, and the determined pre-divided memory unit is segmented according to the determined size of the memory to be allocated. The memory addresses of the multiple segmented memory blocks are stored in a first linked list, and one of the stored memory addresses of the multiple segmented memory blocks is determined as the memory address of the memory to be allocated. Specifically, based on the above judgment, if it is determined that there is no memory address of a memory block matching the determined size of the memory to be allocated in the first linked list, that is, the size of the memory to be allocated determined in step S201 is different from the memory size of the memory block corresponding to each of the multiple memory addresses stored in the first linked list, then a pre-divided memory unit to be segmented is determined, and the determined pre-divided memory unit is segmented according to the determined size of the memory to be allocated. The memory addresses of the segmented memory blocks are stored in the first linked list, and one of the stored memory addresses of the multiple segmented memory blocks is determined as the memory address of the memory to be allocated.
[0095] Among them, by matching according to the size of the memory to be allocated, or by dividing it according to the size of the memory to be allocated, the memory address of the memory to be allocated can be obtained. This can improve the rationality of obtaining the memory address of the memory to be allocated from the first linked list, and further improve the rationality of memory management based on the determined memory address of the memory to be allocated and the user experience.
[0096] The pre-divided memory units to be divided refer to memory addresses in the first linked list that do not match the determined size of the memory to be allocated. That is, when the size of the memory to be allocated determined in step S201 is different from the size of the memory block corresponding to each memory address stored in the first linked list, it needs to be divided to obtain multiple pre-divided memory units that match the size of the memory block to be allocated. This application does not limit the process for determining the pre-divided memory units to be divided; any process capable of determining the pre-divided memory units to be divided can be used as the process provided in this application. Optionally, the process for determining the pre-divided memory units to be divided may include: first determining whether there are historically divided pre-divided memory units. Historically divided pre-divided memory units are those that have been divided, allocated, and then completely released. Specifically, historically partitioned pre-partitioned memory units are reserved for use when determining the pre-partitioned memory units to be partitioned. One of these reserved historically partitioned pre-partitioned memory units is selected first as the pre-partitioned memory unit to be partitioned. If at least one historically partitioned pre-partitioned memory unit exists, then one of these at least one historically partitioned pre-partitioned memory units is determined as the pre-partitioned memory unit to be partitioned. Otherwise, the memory address of a memory block with the same size as a preset memory unit is obtained from the second linked list, and the preset internal audit unit corresponding to that memory address is determined as the pre-partitioned memory unit to be partitioned. Specifically, if no historically partitioned pre-partitioned memory unit exists, the memory address of a memory block with the same size as a preset memory unit is selected from multiple memory addresses in the second linked list, and the preset internal audit unit corresponding to that memory address is determined as the pre-partitioned memory unit to be partitioned. That is, a pre-partitioned memory unit that has not undergone partitioning, allocation, or deallocation processing is re-selected as the pre-partitioned memory unit to be partitioned.
[0097] In the process of determining the pre-partitioned memory units to be divided, first determining whether there are historically divided pre-partitioned memory units can improve the efficiency of determining the pre-partitioned memory units to be divided, further improve the efficiency of dividing the determined pre-partitioned memory units to be divided, and thus improve the efficiency of memory management.
[0098] Optionally, after selecting a memory address of a memory block with the same size as the preset memory unit from multiple memory addresses in the second linked list, and determining the preset internal audit unit corresponding to the memory address as the pre-divided memory unit to be segmented, the memory address can be deleted from the second linked list.
[0099] Specifically, after determining the pre-divided memory units to be partitioned, the pre-divided memory units can be partitioned according to the determined size of the memory to be allocated. This application does not limit the process of partitioning the pre-divided memory units according to the determined size of the memory to be allocated; any process that can partition the pre-divided memory units according to the determined size of the memory to be allocated can be considered as the process provided in this application. Optionally, the determined pre-divided memory units can be divided into multiple memory blocks of the same size as the memory to be allocated. For example: if the preset memory unit size is 4KB and the size of the memory to be allocated is 1024B, then the determined pre-divided memory unit to be divided is divided into four 1024B memory blocks; for example: if the preset memory unit size is 4KB and the size of the memory to be allocated is 516B, then the determined pre-divided memory unit to be divided is divided into eight 516B memory blocks.
[0100] Specifically, after dividing the pre-divided memory units into segments according to the determined size of the memory to be allocated, the memory addresses of multiple segmented memory blocks can be stored in the first linked list, and one of the stored memory addresses of the multiple segmented memory blocks can be determined as the memory address of the memory to be allocated. For example: If the determined pre-divided memory unit is divided into four 1024B memory blocks, then the memory address of each of the four 1024B memory blocks is stored in the first linked list, and the memory address of one of the stored four 1024B memory block addresses is determined as the memory address of the memory to be allocated; For example: If the determined pre-divided memory unit is divided into eight 516B memory blocks, then the memory address of each of the eight 516B memory blocks is stored in the first linked list, and the memory address of one of the stored eight 516B memory block addresses is determined as the memory address of the memory to be allocated.
[0101] Step S302: If the memory size requested by the memory allocation request is greater than or equal to the size of the preset memory unit, then the memory address of the memory to be allocated is obtained from the second linked list according to the determined size of the memory to be allocated.
[0102] Specifically, based on the above description of the process of determining the size of the memory to be allocated and the corresponding memory address linked list according to the size of the memory requested in the memory allocation request and the size of the preset memory unit, if the size of the memory requested in the memory allocation request is greater than or equal to the size of the preset memory unit, then the second linked list is determined to be the memory address linked list corresponding to the memory to be allocated. Therefore, if the size of the memory requested in the memory allocation request is greater than or equal to the size of the preset memory unit, the memory address of the memory to be allocated can be obtained from the second linked list according to the determined size of the memory to be allocated.
[0103] This application does not limit the process of obtaining the memory address of the memory to be allocated from the second linked list based on the determined size of the memory to be allocated. Any process that can obtain the memory address of the memory to be allocated from the second linked list based on the determined size of the memory to be allocated can be used as the process provided by this application for obtaining the memory address of the memory to be allocated from the second linked list based on the determined size of the memory to be allocated.
[0104] Optionally, based on the determined size of the memory to be allocated, the memory addresses of the most matching combinations of preset memory units can be selected from the second linked list. Each combination of preset memory units includes at least one preset memory unit. Specifically, if a combination of preset memory units includes multiple preset memory units, these multiple preset memory units are adjacent preset memory units. The memory block corresponding to the memory address stored in the second linked list is a combination of preset memory units. For example, it could be a combination of preset memory units consisting of one preset memory unit (e.g., a 4KB memory block), a combination of preset memory units consisting of two adjacent preset memory units (e.g., an 8KB memory block), or a combination of preset memory units consisting of three adjacent preset memory units (e.g., a 12KB memory block), etc. The most matching combination of preset memory units is the smallest combination of preset memory units that is greater than or equal to the determined size of the memory to be allocated. For example: if the preset memory unit size is 4KB, and the memory unit sizes corresponding to the preset memory unit combinations stored in the second linked list are 4KB and 12KB respectively, then if the size of the memory to be allocated is 4KB, the best matching preset memory unit combination is the combination of preset memory units with a memory size of 4KB; if the size of the memory to be allocated is 8KB, then the best matching preset memory unit combination is the combination of preset memory units with a memory size of 12KB.
[0105] Specifically, if the size of the most matching preset memory unit combination is the same as the determined size of the memory to be allocated, then the memory address of the most matching preset memory unit combination is determined as the memory address of the memory to be allocated. For example, if the size of the preset memory unit is 4KB, and the sizes of the preset memory unit combinations corresponding to the memory addresses stored in the second linked list are 4KB and 12KB respectively, and the size of the memory to be allocated is 4KB, then the most matching preset memory unit combination is the combination of preset memory units with a size of 4KB. In this case, the most matching preset memory unit combination, i.e., the combination of preset memory units with a size of 4KB, can be determined as the memory address of the memory to be allocated.
[0106] Optionally, if there are multiple combinations of the most matching preset memory units, the memory address of one of the most matching preset memory unit combinations will be randomly selected as the memory address of the memory to be allocated.
[0107] Specifically, if the size of the most matching preset memory unit combination is greater than the determined size of the memory to be allocated, then the most matching preset memory unit combination is partitioned, and the memory address of the partitioned most matching preset memory unit combination is determined as the memory address of the memory to be allocated. For example, if the size of the most matching preset memory unit combination is greater than the determined size of the memory to be allocated, for instance: if the preset memory unit size is 4KB, and the memory sizes of the preset memory unit combinations corresponding to the memory addresses stored in the second linked list are 4KB and 12KB respectively, and the size of the memory to be allocated is 8KB, then the most matching preset memory unit combination is a combination of preset memory units with a memory size of 12KB. In this case, if the size of the most matching preset memory unit combination, i.e., 12KB, is greater than the determined size of the memory to be allocated, i.e., 8KB... Specifically, in the above scenario, the selected combination of the most matching preset memory units, i.e., the combination of preset memory units with a size of 12KB, can be partitioned. This partitioning results in two combinations of preset memory units. One combination has the same memory size as the memory to be allocated, while the other combination has a memory size equal to the difference between the selected combination of the most matching preset memory units and the memory to be allocated. For example, one combination has a memory size of 8KB, and the other has a memory size of 4KB. The final most matching combination of preset memory units is the one of the two combinations that has the same size as the memory to be allocated, i.e., the combination of preset memory units with a size of 8KB. Specifically, after partitioning the selected combination of the most matching preset memory units to obtain the partitioned combination of the most matching preset memory units, the memory address of the partitioned combination of the most matching preset memory units can be determined as the memory address of the memory to be allocated.
[0108] Optionally, if there are multiple combinations of the most matching preset memory units, one of the most matching preset memory unit combinations is randomly divided, and the memory address of the most matching preset memory unit combination after division is determined as the memory address of the memory to be allocated.
[0109] In the process of obtaining the memory address of the memory to be allocated from the second linked list based on the determined size of the memory to be allocated, the method of matching based on the size of the memory to be allocated, or the method of partitioning based on the size of the memory to be allocated, can improve the rationality of obtaining the memory address of the memory to be allocated from the second linked list, and further improve the rationality of memory management based on the determined memory address of the memory to be allocated and the user experience.
[0110] The process provided in this embodiment of the invention, which obtains the memory address of the memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated based on the determined size of the memory to be allocated, can improve the rationality of the obtained memory address when the size relationship between the memory size requested in the memory allocation request and the size of the preset memory unit is different. This further improves the rationality of memory management based on the determined memory address of the memory to be allocated and the user experience.
[0111] In some embodiments, after allocating the determined memory to be allocated based on the determined memory address, the memory management method provided in this application further includes: if the size of the memory to be allocated indicated by the memory allocation request is less than the size of a preset memory unit, then the memory address of the determined memory to be allocated is deleted from the first linked list. If the size of the memory to be allocated indicated by the memory allocation request is greater than or equal to the size of the preset memory unit, then the memory address of the determined memory to be allocated is deleted from the second linked list. Specifically, after the memory to be allocated is allocated, the memory address of the memory to be allocated can be deleted from the corresponding memory address linked list. Specifically, if the size of the memory to be allocated indicated by the memory allocation request is less than the size of the preset memory unit, then the address of the memory to be allocated is the memory address obtained from the first linked list, therefore, the memory address of the determined memory to be allocated can be deleted from the first linked list; if the size of the memory to be allocated indicated by the memory allocation request is greater than or equal to the size of the preset memory unit, then the address of the memory to be allocated is the memory address obtained from the second linked list, therefore, the memory address of the determined memory to be allocated can be deleted from the second linked list. In particular, after allocating the determined memory to be allocated based on the determined memory address, deleting the determined memory address from the corresponding linked list can improve the accuracy of memory management and enhance the user experience of memory management.
[0112] Figure 4 A flowchart illustrating another memory management method provided in an embodiment of the present invention. Figure 1 or Figure 2 or Figure 3Based on the embodiments shown, this application describes another memory management method in detail, such as... Figure 4 As shown, the method of this embodiment of the invention includes:
[0113] Step S401: Receive memory allocation request.
[0114] The memory allocation request indicates the size of the memory to be allocated.
[0115] Specifically, the detailed process of this step can be found in the description of step S101, and will not be repeated here.
[0116] Step S402: Based on the memory size requested in the memory allocation request and the preset memory unit size, determine the size of the memory to be allocated and the linked list of memory addresses corresponding to the memory to be allocated.
[0117] The preset memory unit size indicates the size of the pre-allocated memory units. The pre-allocated memory units are those of the same size as those pre-allocated during memory initialization. The memory address linked list is a linked list used to store memory addresses.
[0118] Specifically, the detailed process of this step can be found in the description of step S102, and will not be repeated here.
[0119] Step S403: Based on the determined size of the memory to be allocated, obtain the memory address of the memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated.
[0120] Specifically, the detailed process of this step can be found in the description of step S103, and will not be repeated here.
[0121] Step S404: Allocate the memory to be allocated based on the determined memory address of the memory to be allocated.
[0122] Specifically, the detailed process of this step can be found in the description of step S104, and will not be repeated here.
[0123] Step S405: Receive memory release request.
[0124] Specifically, after allocating the memory to be allocated based on the determined memory address, a memory release request can be received. This memory release request is used to request the release of memory. Specifically, this application does not limit the memory release request; any request capable of requesting memory release can be used as the memory release request provided in this application. Optionally, it can be a request generated in response to a stop instruction from an application. The memory release request indicates the address of the memory to be released. Optionally, the address of the memory to be released corresponds to the address of the memory to be allocated; that is, the size of the memory to be released corresponds to the size of the memory to be allocated.
[0125] Step S406: Release the memory to be released according to the address of the memory to be released indicated by the memory release request.
[0126] Specifically, after receiving a memory release request, the memory to be released can be released according to the address of the memory to be released indicated in the memory release request. This application does not limit the process of releasing the memory to be released according to the address of the memory to be released indicated in the memory release request; any process that can release the memory to be released according to the address of the memory to be released indicated in the memory release request can be used as the process provided in this application. Optionally, the data stored in the memory to be released can be deleted.
[0127] Optionally, the memory release request may also indicate whether the memory to be released is greater than a preset memory unit size. Specifically, if the memory release request indicates that the memory to be released is greater than or equal to the preset memory unit size, based on the correspondence between the size of the requested memory to be released and the size of the requested memory to be allocated as described above, the size of the corresponding requested memory to be allocated is greater than or equal to the preset memory unit size; if the memory release request indicates that the memory to be released is less than the preset memory unit size, based on the correspondence between the size of the requested memory to be released and the size of the requested memory to be allocated as described above, the size of the corresponding requested memory to be allocated is less than the preset memory unit size.
[0128] Optionally, after releasing the memory to be released, the memory management method provided in this application further includes:
[0129] If a memory release request indicates that the memory to be released is smaller than a preset memory unit size, then the address of the memory to be released indicated by the memory release request is stored in the first linked list. Specifically, if a memory release request indicates that the memory to be released is smaller than a preset memory unit size, then the memory address of the corresponding memory to be allocated is the memory address obtained from the first linked list. Therefore, after releasing the memory to be released, the address of the memory to be released indicated by the memory release request can be stored in the first linked list.
[0130] If a memory release request indicates that the memory to be released is greater than or equal to a preset memory unit size, then the address of the memory to be released indicated by the memory release request is stored in the second linked list. Specifically, if a memory release request indicates that the memory to be released is greater than or equal to the preset memory unit size, the memory address of the corresponding memory to be allocated is the memory address obtained from the second linked list. Therefore, after releasing the memory to be released, the address of the memory to be released indicated by the memory release request can be stored in the second linked list. Storing the address of the memory to be released indicated by the memory release request in the corresponding linked list after releasing the memory to be released can improve the accuracy of memory management and enhance the user experience of memory management.
[0131] Optionally, during the process of storing the address of the memory to be released as indicated by the memory release request into the second linked list, if there is a memory address adjacent to the address of the memory to be released in the second linked list, the address of the memory to be released is combined with the adjacent memory address to obtain the memory address corresponding to the larger memory block, so as to update the memory address stored in the second linked list, thereby improving the rationality of memory management and user experience.
[0132] The present invention provides another memory management method, which, based on the above embodiments, releases the memory to be released according to the address of the memory to be released indicated by the received memory release request. Therefore, by determining the size of the memory to be allocated and the memory address list corresponding to the memory to be allocated according to the size of the memory to be allocated indicated by the memory allocation request and the size of the preset memory unit, and obtaining the memory address of the memory to be allocated from the memory address list corresponding to the determined memory to be allocated according to the determined size of the memory to be allocated, the rationality of confirming the memory address to be allocated is improved, and the rationality of releasing the memory to be released is also improved. This further improves the rationality of memory management based on the determined memory address of the memory to be allocated and the user experience.
[0133] Figure 5 This is a schematic diagram of the structure of a memory management device provided in an embodiment of the present invention, as shown below. Figure 5As shown, the memory management device 500 of this embodiment includes: a receiving module 501, a determining module 502, an acquiring module 503, and a management module 504. Wherein:
[0134] The receiving module 501 is used to receive a memory allocation request; wherein the memory allocation request indicates the size of the memory to be allocated;
[0135] The determination module 502 is used to determine the size of the memory to be allocated and the memory address linked list corresponding to the memory to be allocated based on the memory size requested in the memory allocation request and the size of the preset memory unit; wherein, the size of the preset memory unit indicates the size of the pre-divided memory unit; the pre-divided memory unit is a memory unit of the same size as that pre-divided during memory initialization; the memory address linked list is a linked list used to store memory addresses;
[0136] The acquisition module 503 is used to obtain the memory address of the determined memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated, based on the determined size of the memory to be allocated.
[0137] Management module 504 is used to allocate memory based on the determined memory address of the memory to be allocated.
[0138] Furthermore, the memory address linked list can be either a first linked list or a second linked list; wherein, the first linked list is used to store the memory addresses of memory blocks smaller than a preset memory unit size; and the second linked list is used to store the memory addresses of memory blocks larger than or equal to the preset memory unit size.
[0139] In some embodiments, the determining module 502 includes:
[0140] The first determining unit 5021 (not shown in the figure) is used to determine if the memory size requested in the memory allocation request is less than the size of a preset memory unit, then the memory size requested in the memory allocation request is greater than or equal to 2 times the size of the memory unit requested. n The smallest integer value in bytes is the size of the memory to be allocated, and the first linked list is determined as the linked list of memory addresses corresponding to the memory to be allocated;
[0141] The second determining unit 5022 (not shown in the figure) is used to determine that if the memory size requested by the memory allocation request is N times the size of the preset memory unit, then N times the size of the preset memory unit is the size of the memory to be allocated, and the second linked list is determined as the memory address linked list corresponding to the memory to be allocated; where N is a positive integer.
[0142] The third determining unit 5023 (not shown in the figure) is used to determine the size of the memory to be allocated as M+1 times the size of the preset memory unit if the size of the memory requested in the memory allocation request is greater than M times the size of the preset memory unit and less than M+1 times the size of the preset memory unit, and to determine the second linked list as the memory address linked list corresponding to the memory to be allocated; where M is a positive integer.
[0143] In some embodiments, the acquisition module 503 includes:
[0144] The first acquisition unit 5031 (not shown in the figure) is used to obtain the memory address of the memory to be allocated from the first linked list according to the determined size of the memory to be allocated if the memory size requested by the memory allocation request is smaller than the size of the preset memory unit.
[0145] The second acquisition unit 5032 (not shown in the figure) is used to obtain the memory address of the memory to be allocated from the second linked list according to the determined size of the memory to be allocated if the size of the memory requested to be allocated indicated by the memory allocation request is greater than or equal to the size of the preset memory unit.
[0146] In some embodiments, the first acquisition unit 5031 (not shown in the figure) is specifically used for:
[0147] Determine if the first linked list contains a memory address that matches the size of the memory block to be allocated;
[0148] If it exists, then one of the at least one matched memory addresses will be determined as the memory address to be allocated.
[0149] If it does not exist, the pre-divided memory unit to be divided is determined, and the pre-divided memory unit to be divided is divided according to the determined size of the memory to be allocated. The memory addresses of the multiple divided memory blocks are stored in the first linked list, and one of the memory addresses of the multiple divided memory blocks is determined as the memory address of the memory to be allocated.
[0150] In some embodiments, the first acquisition unit 5031 (not shown in the figure) is specifically used for:
[0151] Determine whether there are pre-partitioned memory units with historical partitioning; wherein, pre-partitioned memory units with historical partitioning are pre-partitioned memory units that have been partitioned, allocated and then completely released.
[0152] If there is at least one historically partitioned pre-partitioned memory cell, then one of the historically partitioned pre-partitioned memory cells is determined as the pre-partitioned memory cell to be partitioned.
[0153] Otherwise, retrieve the memory address of a memory block with the same size as the preset memory unit from the second linked list, and determine the preset internal audit unit corresponding to the memory address as the pre-divided memory unit to be segmented.
[0154] In some embodiments, the second acquisition unit 5032 (not shown in the figure) is specifically used for:
[0155] Based on the determined size of the memory to be allocated, the memory addresses of the most matching combination of preset memory units are selected from the second linked list; wherein the combination of preset memory units includes at least one preset memory unit; the most matching combination of preset memory units is the smallest combination of preset memory units that is greater than or equal to the determined size of the memory to be allocated.
[0156] If the size of the most matching preset memory unit combination is the same as the size of the determined memory to be allocated, then the memory address of the most matching preset memory unit combination is determined as the memory address of the memory to be allocated.
[0157] If the size of the most matching preset memory unit combination selected is greater than the determined size of the memory to be allocated, then the most matching preset memory unit combination selected is divided, and the memory address of the most matching preset memory unit combination after division is determined as the memory address of the memory to be allocated.
[0158] In some embodiments, the management module 504 is further configured to:
[0159] If the memory size requested by the memory allocation request is smaller than the preset memory unit size, then the memory address of the memory to be allocated is deleted from the first linked list.
[0160] If the memory allocation request indicates that the requested memory size is greater than or equal to the preset memory unit size, then the memory address of the determined memory to be allocated is removed from the second linked list.
[0161] In some embodiments, the receiving module 501 is further configured to receive a memory release request; wherein the memory release request indicates the address of the memory to be released;
[0162] The management module 504 is also used to release the memory to be released according to the address of the memory to be released indicated by the memory release request.
[0163] In some embodiments, the management module 504 is further configured to:
[0164] If a memory release request indicates that the memory to be released is smaller than the preset memory unit size, then the address of the memory to be released indicated by the memory release request is stored in the first linked list;
[0165] If a memory release request indicates that the memory to be released is greater than or equal to the size of a preset memory unit, then the address of the memory to be released indicated by the memory release request is stored in the second linked list.
[0166] The apparatus of this invention can be used to execute the technical solutions of any of the method embodiments shown above. Its implementation principle and technical effect are similar, and will not be repeated here.
[0167] Figure 6 This is a schematic diagram of the structure of an electronic device provided according to an embodiment of the present invention. Figure 6 As shown, the electronic device 600 may include at least one processor 601 and a memory 602.
[0168] The memory 602 is used to store programs. Specifically, the program may include program code, which includes computer-executable instructions.
[0169] The memory 602 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.
[0170] Processor 601 executes computer execution instructions stored in memory 602 to implement the memory management method described in the foregoing method embodiments. Processor 601 may be a Central Processing Unit (CPU), an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. Specifically, when implementing the memory management method described in the foregoing method embodiments, the electronic device may be, for example, an electronic control unit in a vehicle, a server, or other electronic device with processing capabilities.
[0171] Optionally, the electronic device 600 may also include a communication interface 603. In specific implementations, if the communication interface 603, memory 602, and processor 601 are implemented independently, they can be interconnected via a bus to complete communication. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc., but this does not imply that there is only one bus or one type of bus.
[0172] Optionally, in a specific implementation, if the communication interface 603, memory 602, and processor 601 are integrated on a single chip, then the communication interface 603, memory 602, and processor 601 can communicate through an internal interface.
[0173] The present invention also provides a computer-readable storage medium storing computer program instructions, which implements the above-described memory management method when the processor executes the computer program instructions.
[0174] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the memory management method described above.
[0175] The present invention also provides a vehicle, wherein the vehicle is equipped with an electronic device that implements the memory management method described above.
[0176] The aforementioned computer-readable storage medium can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read Only Memory (PROM), Read Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0177] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an application-specific integrated circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in a memory management device.
[0178] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0179] Finally, it should be noted that the above embodiments are merely preferred embodiments provided to fully illustrate the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention.
Claims
1. A memory management method, characterized in that, The method includes: Receive a memory allocation request; wherein the memory allocation request indicates the size of the memory to be allocated; Based on the memory allocation request indicating the requested memory size and the preset memory unit size, determine the size of the memory to be allocated and the corresponding memory address linked list; wherein, the preset memory unit size indicates the size of the pre-divided memory unit; the pre-divided memory unit is a memory unit of the same size as the one pre-divided during memory initialization; the memory address linked list is a linked list used to store memory addresses; Based on the determined size of the memory to be allocated, obtain the memory address of the memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated; Allocate the memory to be allocated based on the determined memory address.
2. The method according to claim 1, characterized in that, The memory address linked list is either a first linked list or a second linked list; wherein, the first linked list is used to store the memory addresses of memory blocks smaller than the preset memory unit size; and the second linked list is used to store the memory addresses of memory blocks larger than or equal to the preset memory unit size.
3. The method according to claim 2, characterized in that, Based on the requested memory size indicated in the memory allocation request and the preset memory unit size, determine the size of the memory to be allocated and the linked list of memory addresses corresponding to the memory to be allocated, including: If the memory allocation request indicates a memory size smaller than the preset memory unit size, then it is determined to be greater than or equal to 2 times the memory size indicated by the memory allocation request. n The smallest integer value in bytes is the size of the memory to be allocated, and the first linked list is determined as the memory address linked list corresponding to the memory to be allocated; If the memory allocation request indicates that the requested memory size is N times the size of the preset memory unit, then N times the size of the preset memory unit is determined as the size of the memory to be allocated, and the second linked list is determined as the memory address linked list corresponding to the memory to be allocated; wherein, N is a positive integer; If the memory size requested in the memory allocation request is greater than M times the size of the preset memory unit and less than M+1 times the size of the preset memory unit, then M+1 times the size of the preset memory unit is determined as the size of the memory to be allocated, and the second linked list is determined as the memory address linked list corresponding to the memory to be allocated; wherein, M is a positive integer.
4. The method according to claim 3, characterized in that, Based on the determined size of the memory to be allocated, the memory address of the memory to be allocated is obtained from the linked list of memory addresses corresponding to the determined memory to be allocated, including: If the memory size requested by the memory allocation request is smaller than the size of the preset memory unit, then the memory address of the memory to be allocated is obtained from the first linked list according to the determined size of the memory to be allocated. If the memory size requested in the memory allocation request is greater than or equal to the size of the preset memory unit, then the memory address of the memory to be allocated is obtained from the second linked list according to the determined size of the memory to be allocated.
5. The method according to claim 4, characterized in that, Based on the determined size of the memory to be allocated, the memory address of the memory to be allocated is obtained from the first linked list, including: Determine whether there exists a memory address in the first linked list that matches the size of the memory block to be allocated; If it exists, then one of the at least one matched memory addresses will be determined as the memory address of the memory to be allocated; If it does not exist, then the pre-divided memory unit to be divided is determined, and the determined pre-divided memory unit to be divided is divided according to the determined size of the memory to be allocated. The memory addresses of the multiple divided memory blocks are stored in the first linked list, and one of the memory addresses of the multiple divided memory blocks is determined as the memory address of the memory to be allocated.
6. The method according to claim 5, characterized in that, Determine the pre-divided memory units to be segmented, including: Determine whether there are pre-partitioned memory units with historical partitioning; wherein, the pre-partitioned memory units with historical partitioning are pre-partitioned memory units that have been partitioned, allocated, and then completely released. If there is at least one pre-partitioned memory cell of the historical segmentation, then one of the pre-partitioned memory cells of the historical segmentation is determined as the pre-partitioned memory cell to be segmented. Otherwise, obtain the memory address of a memory block with the same size as the preset memory unit from the second linked list, and determine the preset internal audit unit corresponding to the memory address as the pre-divided memory unit to be segmented.
7. The method according to claim 4, characterized in that, Based on the determined size of the memory to be allocated, the memory address of the memory to be allocated is obtained from the second linked list, including: Based on the determined size of the memory to be allocated, the memory addresses of the most matching combination of preset memory units are selected from the second linked list; wherein, the combination of preset memory units includes at least one preset memory unit; the most matching combination of preset memory units is the smallest combination of preset memory units that is greater than or equal to the determined size of the memory to be allocated. If the size of the most matching preset memory unit combination selected is the same as the size of the determined memory to be allocated, then the memory address of the most matching preset memory unit combination selected is determined as the memory address of the memory to be allocated. If the size of the most matching preset memory unit combination selected is greater than the determined size of the memory to be allocated, then the most matching preset memory unit combination selected is divided, and the memory address of the most matching preset memory unit combination after division is determined as the memory address of the memory to be allocated.
8. The method according to any one of claims 2-6, characterized in that, After allocating the determined memory to be allocated based on the determined memory address, the method further includes: If the memory size requested by the memory allocation request is smaller than the size of the preset memory unit, then the memory address of the determined memory to be allocated is deleted from the first linked list. If the memory size requested in the memory allocation request is greater than or equal to the size of the preset memory unit, then the memory address of the determined memory to be allocated is deleted from the second linked list.
9. The method according to claim 8, characterized in that, The method further includes: Receive a memory release request; wherein the memory release request indicates the address of the memory to be released; Release the memory to be released according to the address of the memory to be released indicated by the memory release request.
10. The method according to claim 9, characterized in that, The memory release request also indicates whether the memory to be released is larger than the preset memory unit size; After releasing the memory to be released, the method further includes: If the memory release request indicates that the memory to be released is smaller than the preset memory unit size, then the address of the memory to be released indicated by the memory release request is stored in the first linked list; If the memory release request indicates that the memory to be released is greater than or equal to the size of the preset memory unit, then the address of the memory to be released indicated by the memory release request is stored in the second linked list.
11. A memory management device, characterized in that, The device includes: A receiving module is used to receive a memory allocation request; wherein the memory allocation request indicates the size of the memory to be allocated; The determination module is used to determine the size of the memory to be allocated and the memory address list corresponding to the memory to be allocated based on the memory size requested in the memory allocation request and the size of the preset memory unit; wherein, the size of the preset memory unit indicates the size of the pre-divided memory unit; the pre-divided memory unit is a memory unit of the same size as that pre-divided during memory initialization; the memory address list is a linked list used to store memory addresses; The acquisition module is used to obtain the memory address of the determined memory to be allocated from the memory address linked list corresponding to the determined memory to be allocated, based on the determined size of the memory to be allocated. The management module is used to allocate memory based on the determined memory address to be allocated.
12. An electronic device, characterized in that, The device includes: a memory and a processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-9.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-9.
14. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-9.
15. A vehicle, characterized in that, The vehicle is equipped with an electronic device that implements the memory management method as described in any one of claims 1-9.