A memory allocation method, device and computer readable storage medium

By adopting an adaptive dynamic memory allocation method on the MCU platform, by comparing the initial value and recording the data location and content of the changed part, the problem of low memory utilization caused by traditional memory allocation methods is solved, and efficient memory usage is achieved.

CN119782203APending Publication Date: 2025-04-08GOSUNCNWELINK TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510047873.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-10
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

On MCU platforms with limited RAM resources, traditional static or simple dynamic memory allocation methods lead to low memory utilization and waste a lot of actual unused RAM space.

Method used

An adaptive dynamic memory allocation method is proposed. By determining the initial value of specific data in flash memory, when data is modified, the initial value is compared, the data location and content of the changed part are recorded, and the original memory is released when the original memory is not modified for the first time, and new memory is applied to store the data of the new changed part.

Benefits of technology

It realizes data scenarios with large data volume, initial set value, and occasional changes. Only some dynamic application contents are applied for changes in specific data and initial values, and memory is released in time when the changes are reduced, greatly improving memory usage efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119782203A_ABST
    Figure CN119782203A_ABST
Patent Text Reader

Abstract

The present invention discloses a memory allocation method, device and computer-readable storage medium, wherein the method comprises: determining the initial value of specific data in a flash memory; when the application modifies the specific data, if it is the first modification, the initial value before and after the modification is compared to determine and record the location and content of the changed data, and if it is not the first modification, the original memory is released and new memory is applied for according to the new changed data to store the new changed data. The present invention implements an adaptive dynamic memory allocation scheme, which targets data scenarios with large data volume, initial setting value, occasional application changes and no need to power off to save, only dynamically applies for the part of the specific data that has changed from the initial value, and releases the memory in time when the changed content decreases, greatly improving the memory usage efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded systems, and in particular to a memory allocation method, device and computer-readable storage medium. Background Art

[0002] In current embedded system design, especially on MCU (Microcontroller Unit) platforms with limited RAM (Random Access Memory) resources, efficient memory management is crucial.

[0003] Traditional memory allocation strategies often use static allocation or simple dynamic allocation mechanisms, which may lead to a problem: for specific data with a lot of content and only a few fields that may be modified, the above simple memory allocation method will waste a lot of RAM space that is not actually used, thus causing system RAM resources to be tight.

[0004] Therefore, how to effectively improve memory utilization and reduce unnecessary memory usage has become a technical problem that needs to be solved urgently. Summary of the invention

[0005] In order to overcome the deficiencies in the prior art, the purpose of the present invention is to provide a method to solve the problem of low memory utilization when static allocation or simple dynamic allocation mechanism is used for specific data with large content and only a few fields may be modified.

[0006] The present invention proposes a memory allocation method, which comprises: Determine the initial value of specific data in the flash memory; When the application modifies the specific data, if it is the first modification, the initial values ​​before and after the modification are compared to determine and record the location and content of the changed data. If it is not the first modification, the original memory is released and new memory is applied for according to the new changed data to store the new changed data.

[0007] Optionally, if it is the first modification, the initial values ​​before and after the modification are compared to determine and record the location and content of the changed data, specifically including: Temporarily define the first local variable; Calculating the offset address of the change member according to the first local variable, and comparing the bytes of the change member to determine the offset address of the change byte corresponding to the change member; Memory corresponding to the changed byte is allocated, and the offset address of the changed byte and the content of the changed byte are recorded respectively through a position pointer and a content pointer.

[0008] Optionally, if it is not the first modification, releasing the original memory and applying for new memory according to the new changed data to store the new changed data, specifically includes: Summarize the data of new changes and old changes; For the aggregated data, compare the initial values ​​before and after the modification, and determine the data of the modified part after the aggregation; Record the offset address and content of the modified part of the data after summary.

[0009] Optionally, the offset address and content of the modified part of the data after the summary of the record specifically include: Check whether the number of changed bytes of the modified items in the summarized modified part is the same as the number of changed bytes before the non-first modification; If they are not the same, the original dynamic memory is released first, and the corresponding memory is re-applied for the position pointer and the content pointer to store the new changed data. If they are the same, the position pointer and the content pointer are directly updated.

[0010] Optionally, determining the initial value of the specific data in the flash memory further includes: When reading the specific data, temporarily defining a second local variable; Assign the second local variable to the initial value.

[0011] Optionally, after assigning the second local variable to the initial value, the method further comprises: Determine the offset address of the changed byte and the content of the changed byte recorded by the position pointer and the content pointer respectively; Taking the second local variable as a reference, the changed byte is obtained according to the position pointer and the content pointer.

[0012] Optionally, before determining the initial value of the specific data in the flash memory, the method further comprises: Detect whether one or more of the content attribute, initial value attribute, rewrite attribute, and retention attribute of the current data meets the preset processing conditions; If the current data meets the processing condition, the current data is modified by the preset keyword to serve as the specific data.

[0013] Optionally, the modifying the current data by using a preset keyword to serve as the specific data includes: Define a null pointer for indicating the data of the changed part, wherein the null pointer is a position pointer and a content pointer; Dynamically request memory of a specified length from the position pointer and content pointer to record the data of the changed part of the specific data that is different from the initial value.

[0014] The present invention also proposes a memory allocation device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the memory allocation method as described in any one of the above items when executed by the processor.

[0015] The present invention also proposes a computer-readable storage medium, on which a memory allocation program is stored. When the memory allocation program is executed by a processor, the steps of the memory allocation method as described in any one of the above items are implemented.

[0016] The memory allocation method, device and computer-readable storage medium of the present invention are implemented by determining the initial value of specific data in the flash memory; when the application modifies the specific data, if it is the first modification, the initial value before and after the modification is compared to determine and record the location and content of the changed data, and if it is not the first modification, the original memory is released and new memory is applied for according to the new changed data to store the new changed data. The present invention implements an adaptive dynamic memory allocation scheme, which only dynamically applies for the content of the specific data that has changed from the initial value, and releases the memory in time when the changed content decreases, greatly improving the memory usage efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which: Figure 1 is a first flow chart of the memory allocation method of the present invention; Figure 2 is a second flow chart of the memory allocation method of the present invention; Figure 3 is a third flow chart of the memory allocation method of the present invention; Figure 4 is a fourth flow chart of the memory allocation method of the present invention; Figure 5 is a fifth flow chart of the memory allocation method of the present invention; Figure 6 is a sixth flow chart of the memory allocation method of the present invention; Figure 7 is the seventh flow chart of the memory allocation method of the present invention; Figure 8 is an eighth flow chart of the memory allocation method of the present invention; Fig. 9 It is a processing logic diagram of the memory allocation method of the present invention. DETAILED DESCRIPTION

[0018] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0019] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present invention, and have no specific meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.

[0020] Figure 1 This is the first flow chart of the memory allocation method of the present invention. This embodiment proposes a memory allocation method, which includes: S1, determining the initial value of specific data in the flash memory; S2. When the application modifies the specific data, if it is the first modification, the initial values ​​before and after the modification are compared to determine and record the location and content of the changed data. If it is not the first modification, the original memory is released and new memory is applied for according to the new changed data to store the new changed data.

[0021] In this embodiment, for data scenarios with large data volumes, initial setting values, occasional application changes, and no need to power off to save data, an optimization solution for specific data memory allocation is proposed to improve memory usage efficiency and reduce unnecessary memory usage.

[0022] In this embodiment, in order to describe the problems existing in the currently commonly used memory allocation scheme, please refer to the following data content, where it is assumed that the following data content belongs to specific data with less modification. It should be noted that, for the convenience of describing the problem, a data type that occupies a small amount of memory (only 20 bytes) is defined as an example, and in fact, specific data refers to a data type of several hundred bytes or even larger.

[0023] #pragma pack (1) / *Use 1-byte alignment* / / * * - Contains 4 U8 type variables, 2 U16 type variables, and 3 U32 type variables * - If you define this type of variable, you will need to occupy a total of (4*1 + 2*2 + 3*4) = 20 bytes of RAM resources * / typedef struct{ uint8_t U8_Val_1; uint8_t U8_Val_2 uint32_t u32_data_1 uint16_t u16_para_1; uint32_t u32_data_2; uint8_t U8_Val_3 uint16_t u16_para_2; uint8_t U8_Val_4 uint32_t u32_data_3; }cfg_val_T; #pragma pack () Based on this, in the current commonly used memory allocation scheme, a variable of this type is generally defined directly, that is: cfg_val_T usr_cfg_val = {0}; It can be seen that through the static memory allocation method, assuming 1-byte alignment, a 20-byte RAM resource needs to be occupied throughout the entire power-on cycle.

[0024] Further, to illustrate the current commonly used memory allocation scheme, when only a small number of member variables have changed, unnecessary RAM resources are wasted, please refer to the following table:

[0025] Based on the above table, it can be seen that in a power-on cycle, 2 of the 9 member variables (i.e., the bold 2499 and 8 in the "Member Value Change" column in the above table) have changed, and the corresponding RAM content has changed in total 3 bytes (i.e., the bold 0xC3, 0x09 and 0x08 in the "RAM Change" column in the above table), while the remaining 17 bytes have not changed. It can be seen that the above solution is equivalent to wasting 17 bytes of RAM; it can also be seen that in order to avoid waste, the initial value stored in the Flash can be directly taken.

[0026] Therefore, in order to solve the problems existing in the above-mentioned common solutions, this embodiment proposes an optimization solution for memory allocation of specific data. On the one hand, for specific data with more content, initial value, support for rewriting, occasional modification, and no need to maintain the modified state after the device is powered off and restarted, when defining it, it is modified by the cosnt keyword (wherein the const keyword is an important feature used to declare constants or limit variable modification), that is, RAM is not used directly, and only Flash resources are occupied; on the other hand, for dynamic memory allocation and release, after each system is powered on, if the application modifies the specific data, only the modified content is dynamically allocated memory to achieve refined control of memory use, and when these changed contents are modified back to the initial value, the corresponding dynamic memory will be released, thereby avoiding memory waste. Specifically, first, the initial value of the specific data in the flash memory is determined; then, when the application modifies the specific data, if it is the first modification, the initial value before and after the modification is compared to determine and record the location and content of the changed part of the data, and if it is not the first modification, the original memory is released according to the new changed part of the data and a new memory is applied to store the new changed part of the data. Furthermore, this embodiment also proposes a marking mechanism for the changed part of the data, that is, after using the above-mentioned const to define the specific data, two additional empty pointers indicating the changed part bytes are defined, namely the position pointer pIndex and the content pointer pData. Based on this, when part of the content in the specific data is different from the initial value, a specified length of memory is dynamically applied for the position pointer pIndex and the content pointer pData, respectively, to record the part of the specific data that is different from the initial value.

[0027] It should be noted that in a power-on operation cycle, the upper-level application may modify any part of the above-mentioned specific data multiple times. What needs to be noted is that during each modification, if the number of bytes changed changes, it is necessary to first release the originally applied dynamic memory, and then re-apply for memory of the corresponding size based on the current total change size to store the location and content of the current changed part.

[0028] The beneficial effect of this embodiment is that by determining the initial value of specific data in the flash memory; when the application modifies the specific data, if it is the first modification, the initial value before and after the modification is compared to determine and record the location and content of the changed data, and if it is not the first modification, the original memory is released and new memory is applied for according to the new changed data to store the new changed data. An adaptive dynamic memory allocation scheme is implemented. For data scenarios with large data volume, initial setting value, occasional application changes and no need to power off to save, only the content of the specific data that has changed from the initial value is dynamically applied, and the memory is released in time when the changed content decreases, which greatly improves the memory usage efficiency.

[0029] Figure 2 : is a second flow chart of the memory allocation method of the present invention. Based on the above embodiment, if it is the first modification, the initial values ​​before and after the modification are compared to determine and record the location and content of the changed data, which specifically includes: S21, temporarily define a first local variable; S22, calculating the offset address of the changed member according to the first local variable, and comparing the bytes of the changed member to determine the offset address of the changed byte corresponding to the changed member; S23. Allocate memory corresponding to the changed byte, and record the offset address of the changed byte and the content of the changed byte through a position pointer and a content pointer respectively.

[0030] In this embodiment, the user-defined data type cfg_val_T is used as an example. First, the specific data is defined in the Flash and the initial value is set, that is: const cfg_val_T usr_cfg_val={...initial value...}; Then, when modifying specific data, if it is the first modification, compare the initial value and record the location and content of the changed data. The specific method is as follows: First, temporarily define local variables to facilitate the subsequent calculation of the offset address of the changed member, that is: cfg_val_T tmp_val; / / Define local variables so that they will not occupy memory continuously; Second, calculate the offset address of the changed member and further refine it to the offset address of the corresponding changed byte; As shown in the above table, if u32_data_1 changes, the corresponding offset address is calculated as follows: - Subtract the address of tmp_val.u32_data_1 from the address of tmp_val to get the offset address of 2; - Further compare the changed bytes of the member. As shown in the table above, the corresponding offset addresses are 2 and 3; - Similarly, the offset address of the byte change caused by the change of u32_data_3 is 16; Third, record the changed offset address and content; - A total of 3 bytes are changed here, corresponding to the dynamic allocation of 3 bytes of memory to the pointers pIndex and pData; - The 3-byte memory pointed to by pIndex records the offset addresses of the changed bytes {2,3,16} in sequence; - The 3-byte memory pointed to by pData records the contents of the changed bytes {0xC3, 0x09, 0x08} in sequence.

[0031] Figure 3 This is a third flow chart of the memory allocation method of the present invention. Based on the above embodiment, if it is not the first modification, the original memory is released and new memory is applied for according to the data of the new changed part to store the data of the new changed part, which specifically includes: S24, summarizing the data of the new changed part and the old changed part; S25. Compare the initial values ​​before and after the modification with respect to the aggregated data, and determine the data of the modified part after the aggregation; S26. Record the offset address and content of the aggregated modified data.

[0032] In this embodiment, first, the current modification item and the previously modified part are summarized to calculate the total modified part relative to the initial value; then, the offset address and content of the summarized modified part are recorded.

[0033] Figure 4 4 is a fourth flow chart of the memory allocation method of the present invention. Based on the above embodiment, the offset address and content of the modified part of the data after the summary are recorded specifically include: S271, detecting whether the number of changed bytes of the modified items of the modified part after the summary is the same as the number of changed bytes before the non-first modification; S272. If they are not the same, first release the original dynamic memory, and re-apply for the corresponding memory for the position pointer and the content pointer to store the new changed data; if they are the same, directly update the position pointer and the content pointer.

[0034] In this embodiment, on the one hand, if the number of changed bytes of the summarized modified items is different from that of the previous ones, the original dynamic memory is released first, and memory of corresponding size is re-applied for pIndex and pData to store the changed parts; on the other hand, if the number of changed bytes of the summarized modified items is the same as that of the previous ones, the contents of pIndex and pData can be directly updated.

[0035] Figure 5 is a fifth flow chart of the memory allocation method of the present invention. Based on the above embodiment, the determining the initial value of the specific data in the flash memory further includes: S11, temporarily defining a second local variable when reading the specific data; S12. Assign the second local variable to the initial value.

[0036] Figure 6 is a sixth flow chart of the memory allocation method of the present invention, based on the above embodiment, after assigning the second local variable to the initial value, it includes: S13, determining the offset address of the changed byte and the content of the changed byte respectively recorded by the position pointer and the content pointer; S14. Taking the second local variable as a reference, obtaining the changed byte according to the position pointer and the content pointer.

[0037] In this embodiment, first, a temporary local variable is defined and assigned an initial value stored in the specific data Flash; cfg_val_T tmp_val; / / define temporary local variables; / / Initialize the local variable content to the initial value in Flash; memcpy(&tmp_val,&usr_cfg_val,sizeof(cfg_val_T)); Then, get the content of the changed bytes from pIndex and pData; - If pIndex points to the current offset address in memory {2,3,16}; - If the current changed content in the memory pointed to by pData is {0xC3, 0x09, 0x08}; - Based on the address of the local variable tmp_va, modify the byte contents of the corresponding offset addresses 2, 3, and 6 to 0xC3, 0x09, and 0x08 respectively.

[0038] It can be seen that at this time, all member variables in the local variable tmp_val have become the latest content, and the upper-level application can access the member value of any of them as needed.

[0039] Figure 7 7 is a flow chart of the memory allocation method of the present invention. Based on the above embodiment, before determining the initial value of the specific data in the flash memory, the method includes: S01, detecting whether one or more of the content attribute, initial value attribute, rewrite attribute, and retention attribute of the current data meets a preset processing condition; S02. If the current data meets the processing condition, the current data is modified by a preset keyword to serve as the specific data.

[0040] In this embodiment, data with a data volume greater than a preset value, an initial value attribute of having an initial value, an overwrite attribute of supporting overwrite, a retention attribute of occasional modification, and no need to maintain the modified state after the device is powered off and restarted is regarded as specific data.

[0041] Figure 8 The eighth flow chart of the memory allocation method of the present invention is based on the above embodiment, and after the current data is modified by the preset keyword to serve as the specific data, it includes: S03, defining a null pointer for indicating the data of the changed part, wherein the null pointer is a position pointer and a content pointer; S04. Dynamically apply for a memory of a specified length from the position pointer and the content pointer to record the data of the changed part of the specific data that is different from the initial value.

[0042] In this embodiment, in combination with the following table, the operation process of the memory allocation in the application process is further explained for the above implementation logic.

[0043]

[0044] Among them, for the change process of specific data when the system is powered on (that is, the change amount displayed in bold), you can see: In the change 1 stage: 3 bytes are different from the initial value (i.e., 0xC3, 0x09, and 0x08); In phase 2 of change: 3 bytes are different from the initial value (i.e., 0x02, 0x08, and 0x23); In phase 3 of the change: 1 byte is different from the initial value (i.e., 0x08); Please refer to Fig. 9 , the figure shows the three stages of the above-mentioned RAM changes, corresponding to the position pointer pIndex indicating the changed bytes and the content pointer pData and the processing logic of the occupied memory.

[0045] Specifically, when change 1 is determined to be the first modification, the initial values ​​before and after the modification are compared to determine and record the location and content of the data of the changed part, which specifically includes: temporarily defining a first local variable; calculating the offset address of the changed member according to the first local variable, and comparing the bytes of the changed member to determine the offset address of the changed byte corresponding to the changed member; allocating memory corresponding to the changed byte, and recording the offset address of the changed byte and the content of the changed byte through a position pointer and a content pointer. When change 2 is determined to be not the first modification, the original memory is released and a new memory is applied for according to the data of the new changed part to store the data of the new changed part, which specifically includes: summarizing the data of the new changed part and the old changed part; for the summarized data, comparing the initial values ​​before and after the modification, and determining the data of the modified part after the summary; recording the offset address and content of the data of the modified part after the summary.

[0046] Based on the above embodiments, the present invention also proposes a memory allocation device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the memory allocation method as described in any one of the above items when executed by the processor.

[0047] It should be noted that the above-mentioned device embodiment and method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are correspondingly applicable in the device embodiment, which will not be repeated here.

[0048] Based on the above embodiments, the present invention further proposes a computer-readable storage medium, on which a memory allocation program is stored. When the memory allocation program is executed by a processor, the steps of the memory allocation method described in any one of the above items are implemented.

[0049] It should be noted that the above-mentioned medium embodiment and method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are correspondingly applicable in the medium embodiment, which will not be repeated here.

[0050] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0051] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0052] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.

Claims

1. A memory allocation method, characterized in that: The method comprises: Determine the initial value of specific data in the flash memory; When the application modifies the specific data, if it is the first modification, the initial values ​​before and after the modification are compared to determine and record the location and content of the changed data. If it is not the first modification, the original memory is released and new memory is applied for according to the new changed data to store the new changed data.

2. The memory allocation method according to claim 1, characterized in that: If it is the first modification, the initial values ​​before and after the modification are compared to determine and record the location and content of the changed data, specifically including: Temporarily define the first local variable; Calculating the offset address of the change member according to the first local variable, and comparing the bytes of the change member to determine the offset address of the change byte corresponding to the change member; Memory corresponding to the changed byte is allocated, and the offset address of the changed byte and the content of the changed byte are recorded respectively through a position pointer and a content pointer.

3. The memory allocation method according to claim 2, characterized in that: If it is not the first modification, the original memory is released according to the new changed data and new memory is applied to store the new changed data, which specifically includes: Summarize the data of new changes and old changes; For the aggregated data, compare the initial values ​​before and after the modification, and determine the data of the modified part after the aggregation; Record the offset address and content of the modified part of the data after aggregation.

4. The memory allocation method according to claim 3, characterized in that: The offset address and content of the modified part of the data after the summary of the record specifically include: Check whether the number of changed bytes of the modified items in the summarized modified part is the same as the number of changed bytes before the non-first modification; If they are not the same, the original dynamic memory is released first, and the corresponding memory is re-applied for the position pointer and the content pointer to store the new changed data. If they are the same, the position pointer and the content pointer are directly updated.

5. The memory allocation method according to claim 4, characterized in that: The determining of the initial value of the specific data in the flash memory further comprises: When reading the specific data, temporarily defining a second local variable; Assign the second local variable to the initial value.

6. The memory allocation method according to claim 4, characterized in that: After assigning the second local variable to the initial value, the method further comprises: Determine the offset address of the changed byte and the content of the changed byte recorded by the position pointer and the content pointer respectively; Taking the second local variable as a reference, the changed byte is obtained according to the position pointer and the content pointer.

7. The memory allocation method according to claim 1, characterized in that: Before determining the initial value of the specific data in the flash memory, the method includes: Detect whether one or more of the content attribute, initial value attribute, rewrite attribute, and retention attribute of the current data meets the preset processing conditions; If the current data meets the processing condition, the current data is modified by the preset keyword to serve as the specific data.

8. The memory allocation method according to claim 7, characterized in that: The step of modifying the current data by using the preset keywords to serve as the specific data includes: Define a null pointer for indicating the data of the changed part, wherein the null pointer is a position pointer and a content pointer; Dynamically request memory of a specified length from the position pointer and content pointer to record the data of the changed part of the specific data that is different from the initial value.

9. A memory allocation device, characterized in that: The device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the memory allocation method according to any one of claims 1 to 8 when executed by the processor.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a memory allocation program, and when the memory allocation program is executed by a processor, the steps of the memory allocation method according to any one of claims 1 to 8 are implemented.