Dynamic memory management method, system, terminal and storage medium for embedded system

By dividing different memory areas in the embedded system and allocating memory blocks or pages according to needs, the problem of frequent memory applications and space waste in embedded system memory management is solved, and the efficiency and reliability of memory management are improved.

CN117724991BActive Publication Date: 2024-09-06HOPEN SOFTWARE ENG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311771736.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-21
Publication Date
2024-09-06
Estimated Expiration
2043-12-21

AI Technical Summary

Technical Problem

The existing memory management methods of embedded systems are difficult to meet the target machine's frequent memory application requirements, resulting in reduced reliability, high maintenance costs, and the problem of wasted memory space.

Method used

By dividing the long-term memory area, large memory area and small memory area in the embedded system, the target memory area is determined according to the software type and the amount of memory occupied, and it is judged whether there is a suitable memory block or memory page in the area, and priority is given to the existing memory area. Allocate free memory blocks or allocate new memory pages to the occupied memory blocks to reduce the number of memory pages.

Benefits of technology

It implements support for embedded software to frequently apply for memory, making full use of the applied memory space, reducing memory fragmentation, saving memory space resources, and improving memory management efficiency and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117724991B
    Figure CN117724991B
Patent Text Reader

Abstract

The present application relates to a dynamic memory management method, system, terminal and storage medium for an embedded system, which belongs to the field of dynamic memory management technology. The method comprises: obtaining a request memory instruction, which includes a software type and an occupied memory amount; determining a target memory area according to the software type, wherein the target memory area is one of a long-term memory area, a large memory area and a small memory area; in the target memory area, determining whether there is a memory page whose memory block is larger than the occupied memory amount, wherein the memory page is composed of at least one memory block; if so, marking the memory page whose memory block is larger than and closest to the occupied memory amount as the target memory page, and allocating one of the free memory blocks in the target memory page to the embedded software; if not, allocating one of the free memory pages in the target memory area to the embedded software. The present application has the effect of saving the memory space resources of the embedded system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of dynamic memory management, and in particular to a dynamic memory management method, system, terminal and storage medium for an embedded system. Background Art

[0002] In the process of embedded system development, there are two roles: the host machine and the target machine: the host machine is the computer that compiles and links the embedded software; the target machine is the hardware platform that runs the embedded software. For example, the PC is a commonly used host machine, and the development board is the target machine. Due to the small capacity of the target machine, it cannot support large-capacity media, such as embedded erasable programmable read-only memory (E-PROM) and electrically erasable programmable read only memory (EEPROM), so the target machine cannot realize large-capacity storage functions.

[0003] In the prior art, in order to ensure the normal operation of the target machine embedded software and the stable operation of the embedded system. Commonly used memory management methods mainly include heap mode and memory pool mode. The heap mode is to allocate a page of memory in the system heap space according to the actual size of the embedded software, and the allocated memory pages are managed in series with linked lists. However, as the system running time increases, a large number of unoccupied memory fragments will be generated. The memory pool mode is to divide the memory of different levels from small to large according to a certain granularity, and each level of memory is configured with a certain number. However, since it is not easy to count the number of small memory of each level, it can only be configured as much as possible during operation, resulting in a waste of memory space.

[0004] Therefore, the existing memory management methods in embedded systems are difficult to meet the requirements of the target machine for frequent memory applications, which reduces the reliability of the embedded system and increases the maintenance cost. Summary of the invention

[0005] The present application provides a dynamic memory management method, system, terminal and storage medium for an embedded system, which has the characteristic of saving memory space resources of the embedded system.

[0006] The first purpose of this application is to provide a dynamic memory management method for an embedded system.

[0007] The above-mentioned application objective 1 of the present application is achieved through the following technical solutions:

[0008] In a first aspect of the present application, a dynamic memory management method for an embedded system is provided. The method comprises:

[0009] Obtaining a memory request instruction, wherein the memory request instruction includes a software type and an amount of occupied memory;

[0010] Determine a target memory area according to the software type, the target memory area being one of a long-term memory area, a large memory area, and a small memory area;

[0011] In the target memory area, determining whether there is a memory page with a memory block larger than the occupied memory amount, the memory page being composed of at least one memory block;

[0012] If so, mark the memory page whose memory block is larger than and closest to the occupied memory amount as the target memory page, and allocate one of the free memory blocks in the target memory page to the embedded software, wherein the free memory block is an unoccupied memory block;

[0013] If not, one of the free memory pages in the target memory area is allocated to the embedded software, and the free memory page is an unoccupied memory page.

[0014] By adopting the above technical solution, the target memory area for providing memory space for the embedded software is determined according to the received memory application instruction, and in the target memory area, it is determined whether there is a memory page with a memory block larger than the occupied memory amount. If so, one of the free memory blocks in the target memory page is allocated to the embedded software for the embedded software to occupy. Otherwise, the free memory page is retrieved and allocated to the embedded software for occupation. In other words, for the memory page where some memory blocks are occupied, when the embedded software has the same memory demand, the available memory blocks are preferentially found from the memory pages of this part; when the memory page where some memory blocks are occupied cannot be used, new free memory pages are continuously allocated, thereby reducing the number of memory pages occupied by the embedded software. Therefore, the present application can support the embedded software to frequently apply for memory from the embedded system, and can also make full use of the memory space already applied for by the embedded software, thereby achieving the purpose of saving the memory space resources of the embedded software.

[0015] In a possible implementation, allocating one of the free memory blocks in the target memory page to the embedded software includes:

[0016] Retrieving a second management table of the target memory page, where the second management table is used to manage the target memory page;

[0017] The second management table selects the first-ranked free memory block from the free memory blocks of the target memory page and allocates it to the embedded software.

[0018] By adopting the above technical solution, the second management table orderly allocates free memory blocks to embedded software, thereby providing technical support for reducing the number of memory pages occupied by embedded software, and also facilitating the management of target memory pages, thereby saving memory space resources.

[0019] In a possible implementation, the method further includes storing string table information in the second management table, the string table information being used to point to a second management table adjacent thereto, and memory blocks of memory pages managed by any two adjacent second management tables being of the same size.

[0020] By adopting the above technical solution, multiple second management tables with the same memory block size of managed memory pages are associated with each other, so that when one of the second management tables is located and the second management table cannot provide free memory blocks for the embedded software, the mutually associated second management tables can provide free memory blocks for the embedded software, thereby improving the efficiency of allocating memory resources of the present application and ensuring the timeliness of the embedded software.

[0021] In a possible implementation manner: the software type is one of a type that only applies for memory but does not release the memory and a type that applies for memory during runtime and releases the memory when the runtime ends;

[0022] The determining the target memory area according to the software type includes:

[0023] When the software type is a type that only applies for memory but does not release memory, marking the long-term memory area as a target memory area;

[0024] When the software type is a type that applies for memory during runtime and releases memory when the runtime ends, it is determined whether the small memory area satisfies:

[0025] ,

[0026] If yes, marking the large memory area as a target memory area;

[0027] If not, the small memory area is marked as the target memory area.

[0028] By adopting the above technical solution, the present application preferentially allocates the required memory to the embedded software in the small memory area, so as to avoid the embedded software with smaller memory occupying the larger memory block in the large memory area, that is, it can save memory resources in the large memory area.

[0029] In a possible implementation manner: the target memory area includes memory pages and a first management table, and the first management table is used to manage all memory pages in the target memory area;

[0030] The first management table is configured with a positioning pointer, and the positioning pointer is used to connect all free memory pages in the target memory area in series.

[0031] By adopting the above technical solution, the memory pages are managed by the first management table, thereby providing technical support for reducing the number of memory pages occupied by embedded software.

[0032] In a possible implementation, the method further includes: the positioning pointer points to all free memory pages in the priority order of "unoccupied and sorted first > released first".

[0033] By adopting the above technical solution, the first management table can dynamically manage all free memory pages to ensure the stability of the first management table.

[0034] In a possible implementation manner: when the large memory area is used as the target memory area, the method further includes:

[0035] When the memory block is smaller than the occupied memory amount or there is no free memory block, the new memory page is divided into multiple memory blocks according to the occupied memory amount and a preset memory block configuration table, and the address of the memory block in the second row of the new memory page is returned to the embedded software.

[0036] By adopting the above technical solution, when there is indeed no free memory block or the memory block is smaller than the occupied memory amount, the new memory page is divided into multiple memory blocks according to the occupied memory amount and the preset memory block configuration table. Since in the divided new memory page, except for the first row being occupied, the memory blocks from the second row to the last row are not occupied, the address of the memory block in the second row is returned to the embedded software, and the embedded software occupies the free memory block in the second row, thereby reducing the number of memory pages occupied by the embedded software.

[0037] In a second aspect of the present application, a dynamic memory management system for an embedded system is provided. The system comprises:

[0038] A data acquisition module is used to acquire a memory request instruction, wherein the memory request instruction includes a software type and an amount of memory occupied;

[0039] A data judgment module, used for determining a target memory area according to the software type, wherein the target memory area is one of a long-term memory area, a large memory area and a small memory area;

[0040] A first processing module, configured to determine, in the target memory area, whether there is a memory page with a memory block larger than the occupied memory amount, wherein the memory page is composed of at least one memory block;

[0041] The second processing module is used to mark the memory page whose memory block is larger than and closest to the occupied memory amount as the target memory page when there is a memory page whose memory block is larger than the occupied memory amount in the target memory area, and allocate one of the free memory blocks in the target memory page to the embedded software, and the free memory block is an unoccupied memory block; and is also used to allocate one of the free memory pages in the target memory area to the embedded software, and the free memory page is an unoccupied memory page, when there is no memory page whose memory block is larger than the occupied memory amount in the target memory area.

[0042] In a third aspect of the present application, a dynamic memory management terminal for an embedded system is provided, which comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the program, any of the above dynamic memory management methods for embedded systems is implemented.

[0043] In a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, any of the above-mentioned dynamic memory management methods for embedded systems is implemented.

[0044] In summary, the present application includes at least one of the following beneficial technical effects:

[0045] The present application first divides the memory space of the embedded software into three memory areas. When a request memory instruction sent by the embedded software is received, the appropriate memory area is first matched for it according to the request memory instruction. In the memory area obtained by matching, for the memory pages where some memory blocks are occupied, when the embedded software has the same memory demand, it is preferred to find available memory blocks from the memory pages of this part; when the memory pages where some memory blocks are occupied cannot be used, new memory pages are allocated, thereby reducing the number of memory pages occupied by the embedded software. Therefore, the present application can support the embedded software to frequently apply for memory from the embedded system, and can also make full use of the memory space that the embedded software has applied for, reduce the memory fragmentation of the embedded system, thereby achieving the purpose of saving the memory space resources of the embedded software. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 This is a flow chart of a dynamic memory management method for an embedded system of the present application.

[0047] Figure 2 It is a structural diagram of the memory pages in the long-term memory area in the method embodiment of the present application.

[0048] Figure 3 It is a structural diagram of a memory page and a first management table corresponding to the memory page in a method embodiment of the present application.

[0049] Figure 4 yes Figure 3 An example diagram of a memory page and a first management table corresponding to the memory page.

[0050] Figure 5 yes Figure 4 An example diagram of a memory page and a first management table after being occupied for a period of time.

[0051] Figure 6 It is a structural diagram of a target memory page and a second management table corresponding to the target memory page in a method embodiment of the present application.

[0052] Figure 7 This is an example diagram of the second management table in the method embodiment of the present application.

[0053] Figure 8 This is a block diagram of a dynamic memory management system for an embedded system of the present application.

[0054] Explanation of the accompanying drawings: 1. Data management module; 2. Data acquisition module; 3. Data judgment module; 4. First processing module; 5. Second processing module. DETAILED DESCRIPTION

[0055] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0056] When an embedded system runs embedded software, it first applies for memory according to the embedded software, and then runs the embedded software in the memory space obtained by the application. Since the memory space of the embedded system is limited, in order to make full use of the memory space allocated to the embedded software and manage the memory space not occupied by the embedded software, this application proposes a dynamic memory management system for the embedded system, hereinafter referred to as the management system.

[0057] Specifically, the management system is applicable to embedded devices and is an application program that can manage the memory space resources of the embedded system. In order to illustrate the process of the management system managing the memory space resources of the embedded system, this application also proposes a dynamic memory management method for the embedded system, such as Figure 1 As shown, the main process of the method is described as follows.

[0058] Step S100: Obtain a memory request instruction.

[0059] When the embedded device is powered on, the management system first divides the memory of the embedded system into a long-term memory area and an active memory area, and the active memory area is further divided into a large memory area and a small memory area. The long-term memory area is used for embedded software that only applies for memory but does not release memory. The large memory area and the small memory area are both used for embedded software that applies for memory during runtime and releases memory at the end of runtime. The difference is that the memory page in the large memory area is larger than the memory page in the small memory area. For example, the memory page in the large memory area is 4KByte, while the memory page in the small memory area is 64Byte. In this example, the size of the memory pages in different types of memory areas may be different, and the size of two memory pages in the same memory area may also be different, but any two memory pages in the same memory area are integer multiples of the minimum memory unit that the memory area can provide. The minimum memory unit is also called a memory block.

[0060] In practical applications, the types of embedded software installed in the embedded system and the historical operation data of each embedded software can be used as the basis for dividing the memory pages and the number of memory pages in the long-term memory area. For example, embedded software a and b are installed in the embedded system, and both a and b belong to the type of only applying for memory but not releasing memory, and the amount of memory applied by embedded software a in the historical operation is 129Byte, and the amount of memory applied by b in the historical operation is 64Byte, then any value of 1Byte, 2Byte, ..., 64Byte can be used as the memory page in the long-term memory area (that is, the minimum memory unit that can be provided). This application is only to reduce resource waste. For example, when 64Byte is selected as the memory page, b will occupy 3 memory pages (that is, 129=64+64+1), and the third memory page only occupies 1Byte, that is, "1" in "64+64+1" occupies a memory page alone. Therefore, when selecting the memory page in the long-term memory area, a smaller value should be selected. However, if a value that is too small (such as 1 Byte) is selected, the management system's calculation amount will increase, thereby increasing the management system's memory space occupied by the embedded system. Therefore, the memory page in the long-term memory area should not be too small. In a specific example, the memory page in the long-term memory area is set to a multiple of 4 Bytes, and 4 Bytes is a memory block.

[0061] When the management system divides the memory pages and the number of memory pages in the large memory area and the memory pages and the number of memory pages in the small memory area, it adopts the process of dividing the memory pages and the number of memory pages in the long-term memory area as described above. Therefore, the process of dividing the large memory area and the small memory area is not described in detail here. In a specific example, the memory pages in the large memory area divided by the management system are 4KByte, and the number of memory pages is 14; and the memory pages in the small memory area divided are 256Byte, and the number of memory pages is 15.

[0062] In this example, for multiple memory pages of the same size in a large memory area, the memory blocks divided by each memory page may be different. For example, if the large memory area includes memory page I and memory page II, memory page I can be divided into multiple blocks of 8 bytes, and memory page II can be divided into multiple blocks different from 8 bytes, such as 32 bytes, 64 bytes, or 128 bytes. Similarly, for multiple identical memory pages in a small memory area, the memory block size of each memory page may also be different. It should be noted that multiple memory blocks in the same memory page have the same size.

[0063] The management system of the present application provides a custom interface, through which administrators can configure the memory pages and the number of memory pages in the long-term memory area, the memory pages and the number of memory pages in the large memory area, and the memory pages and the number of memory pages in the small memory area.

[0064] While the management system divides the long-term memory area, the large memory area and the small memory area, the management system also monitors the memory request instructions sent by the embedded software to the embedded system. The memory request instructions contain the type of embedded software and the amount of memory required for its operation. The amount of memory is referred to as the occupied memory amount below. There are two types of embedded software: one is the embedded software that only applies for memory but does not release the memory, and the other is the embedded software that applies for memory when running and releases the memory when the running ends.

[0065] After the management system has divided the long-term memory area, the large memory area, and the small memory area and received the memory request instruction, it enters step S200.

[0066] Step S200: determining a target memory area according to the request memory instruction, where the target memory area is one of a long-term memory area, a large memory area and a small memory area.

[0067] First, the management system extracts the type of embedded software in the memory request instruction. If the embedded software is a type that only applies for memory but does not release memory, memory pages are allocated to it in the long-term memory area, and the long-term memory area is marked as the target memory area, and the process proceeds to step S300. If the embedded software is a type that applies for memory during operation and releases memory at the end of operation, memory pages are allocated to it in the active memory area, and the active memory area is marked as the target memory area, and the process proceeds to step S400.

[0068] Step S300: When the target memory area is a long-term memory area, a memory frame that is larger than and closest to the occupied memory amount and is an integer multiple of 4 Byte is set according to the size of the occupied memory amount, and the memory frame is allocated to the embedded software.

[0069] The memory page in the long-term memory area is also called a memory frame. Each memory frame consists of a frame header segment, a frame length segment, and a data segment. The frame header segment is used to indicate the beginning of the memory frame. The data segment is used for embedded software. Its length is the size represented by the frame length segment. Figure 2 As shown, there are multiple memory frames in the long-term memory area. The frame header segment, frame length segment and data segment of each memory frame are represented by FEFE, Size and DTAT respectively. The FEFE of the first memory frame represents the beginning of a new memory frame, and Size1 is used to represent the size of the data segment. In order to distinguish the frame length segments of different memory frames, Size1 and Size2 are used to represent the frame length segment of the first memory frame and the frame length segment of the second memory frame. The data segment of the first memory frame is represented by DTAT1, which is used for embedded software. The length of DTAT1 is the size represented by Size1, and the data segment of the second memory frame is represented by DTAT2, and the length occupied by DTAT2 is exactly the size represented by Size2. Figure 2 For example, when there is embedded software c that needs to occupy a memory frame of 4 bytes, memory frame Size1 has been occupied and the second memory frame is exactly 4 bytes, the address of the second memory frame is sent to the embedded software c, and the embedded software c automatically occupies DTAT2 of the second memory frame. At the same time, the management system also records the end address of the third memory frame as the head address of the next memory frame to point to the next free memory frame.

[0070] Step S400: When the target memory area is an active memory area, determine whether the small memory area satisfies:

[0071] ,

[0072] If any of the above conditions is met, the large memory area is used as the target memory area; otherwise, the small memory area is used as the target memory area to avoid the embedded software with a smaller memory footprint from monopolizing a larger memory block in the large memory area, thereby saving memory resources in the large memory area.

[0073] Specifically, when the large memory area is used as the target memory area, the process of allocating the required memory usage amount for the embedded software in the large memory area is shown in steps S411 to S413:

[0074] Step S411, determining whether there is a memory page whose memory block is larger than the occupied memory amount among the multiple memory pages in the large memory area;

[0075] Step S412: If yes, mark the memory page whose memory block is larger than and closest to the occupied memory amount as the target memory page, and allocate one of the memory blocks in the target memory page to the embedded software;

[0076] Step S413: Otherwise, one of the free memory pages in the large memory area is allocated to the embedded software.

[0077] Specifically, the large memory area includes memory pages and a first management table corresponding to the memory pages. When any memory page is occupied and divided into multiple memory blocks, a second management table is generated corresponding to the divided memory page. The first management table is used to manage all memory pages in the large memory area, such as Figure 3 As shown, if column x is composed of all memory pages in the large memory area, the first management table is composed of columns y and z. According to the top-to-bottom arrangement order of the memory pages in column x and the top-to-bottom arrangement order of each row in the first management table, the memory pages with the same arrangement order and the rows in the first management table have a mapping relationship. The mapping relationship is expressed as Figure 3 The arrow in . Among them, the memory page Page0 ranked first in the x column has been occupied by the first management table used to control all memory pages, so the first row of the first management table:

[0078] The y column is displayed as 0|used, and the z column is displayed as Pages=1, where "0" means the memory page is Page0, "used" means Page0 has been occupied, that is, Page0 is in the occupied state, and Pages=1 means that only one memory page "Page0" is occupied;

[0079] In the second row of the first management table:

[0080] The y column is displayed as 0, the z column is displayed as Pages=N-1, and the second row is the positioning point of the free_list positioning pointer, which is represented by a dotted arrow. In the second row of the y column, "0" means that in the x column, the memory pages have been in a free state since the second row, that is, Pages1-PagesN-1 are all free memory pages, and Pages1-PagesN-1 are not separated by memory pages in the used state; in the second row of the z column, "Pages=N-1" means that in the x column, the free memory pages have been continuous since the second row, that is, Pages1-PagesN-1 are all free memory pages.

[0081] It should be noted that Figure 3 The x column, y column, and z column are all set to distinguish different columns. In practical applications, they are not limited to the x column, y column, and z column, and can also be the first column, the second column, and the third column. No specific limitation is made here.

[0082] In addition, the free_list positioning pointer in the first management table also has the ability to connect all free memory pages in the large memory area in series. The specific connection method is: the positioning pointer points to the free memory page in the priority order of "unoccupied and sorted first > released first", and the y column in the free memory page is also connected in series in the priority order of "unoccupied and sorted first > released first". Its data structure in the management table is:

[0083] struct Free_List

[0084] {

[0085] int next_free_list; / / That is, column y, the index number of the first page of the next set of consecutive free memory pages.

[0086] int Pages; / / That is, column z, the number of current consecutive free memory pages.

[0087] };

[0088] like Figure 4As shown, if the x column consists of Page0, Page1, Page2, Page3, Page4, Page5, and Page6, and during use, Page1, Page2, and Page3 are occupied respectively, and Page1 and Page2 are occupied at the same time, then the positioning pointer is moved to the fifth row of the first management table, and the status of the fifth row of the first management table is: the y column shows 0, and the z column shows Pages=3. At this time, it means that the consecutive Page4, Page5, and Page6 are all free memory pages, but there are no free memory pages after Page6, that is, the y column is "0" indicating that there are no free memory pages after the current free_list positioning pointer, and the z column is "Pages=3" indicating that the three consecutive memory pages starting from the fifth row are all free memory pages. If after a period of time, Figure 5 As shown in the figure, Page1 and Page2 are released at the same time, while Page4, Page5, and Page6 have not been occupied. At this time, the positioning pointer still stays on the fifth row of the first management table, and will not dynamically move to the second row to ensure the stability of the first management table. However, the first management table will connect the released Page1 and Page2 in series. Specifically, the status of the fifth row of the first management table is:

[0089] The y column shows 1, and the z column shows Pages=3;

[0090] The "1" on the fifth row of column y points to Page1, and the "Pages=3" on the fifth row of column z indicates that consecutive Page4, Page5, and Page6 are all free memory pages.

[0091] After pointing to the second row, that is, to Page1, the status of the second row of the first management table is:

[0092] The y column is displayed as 0, and the z column is displayed as Pages=2;

[0093] The "0" on the second row of column y indicates that there is no free pointer, that is, there is no next free memory page, and the "Pages=2" on the second row of column z indicates that the consecutive Page1 and Page2 are free memory pages.

[0094] This design can collect and manage the gradually released memory pages.

[0095] Based on the above-mentioned way of managing memory pages by the first management table, the above-mentioned steps S411 to S413 can be briefly described as follows: after obtaining the amount of occupied memory, the management system first determines the size of the amount of occupied memory. If the amount of occupied memory is at least lower than the memory block in a memory page in the large memory area, the first management table allocates free memory pages to the embedded software in the order of memory pages from front to back. However, when the amount of occupied memory is greater than the memory block of the memory page in the large memory area, the first management table allocates continuous free memory pages to the embedded software in the order of memory pages from back to front, so that when the target memory area is a large memory area, the fragmented amount of occupied memory is further placed in the front memory page, and the larger amount of occupied memory is placed in the back memory page, so as to facilitate the first management table to manage embedded software with different amounts of occupied memory.

[0096] Furthermore, the second management table is used to manage the target memory page. Figure 6 As shown, if column x is a target memory page divided into multiple memory blocks of the same size, then the data in columns y and z of the second management table are arranged according to the arrangement order of the memory blocks in column x from top to bottom and the arrangement order of each row in the second management table from top to bottom. The memory blocks with the same arrangement order have a mapping relationship with the rows in the second management table. The mapping relationship is expressed as Figure 6 It should be noted that the first memory block block0 in the x column has been occupied by the management table used to control the target memory page, so in the first row of the second management table: the y column is displayed as 0|used, and the z column is displayed as blocks=1, where "0" indicates the memory block block0, "used" indicates that block0 has been occupied, that is, block0 is in an occupied state, and blocks=1 indicates that only one memory block "block0" is occupied.

[0097] Therefore, the data in the first row of the second management table and the first management table have the same meaning. The difference is that in the second management table, the management system for managing memory blocks occupies the memory block corresponding to the first row and occupies 16 bytes, but the amount of memory occupied will change with the change of free memory blocks. Figure 7As shown, in the first row of the second management table: "prev" is the address of the second management table adjacent to the second management table and sorted in front, "next" is the address of the second management table adjacent to the second management table and sorted in the back, "prev" and "next" are collectively referred to as string table information, which contains the addresses of two second management tables with the same memory block size and adjacent to it. The string table information occupies the first memory block of this memory page. When there is no free memory block in the memory page, the memory page will not have string table information, that is, "prev" and "next" will be automatically deleted. When the memory blocks in the memory page are released and recycled, the management system will rebuild the string table information and mount the current memory page in the same memory page string table.

[0098] in addition, Figure 7 The "blocks" here refers to the number of memory blocks managed by the second management table, and "free_blk" is a positioning pointer, which is used to locate free memory blocks. The positioning pointer in the second management table connects free memory blocks in the same way as the positioning pointer in the first management table connects free memory pages in the same way, so it will not be repeated here.

[0099] Therefore, when the target memory area is a large memory area, determine whether there is a memory block corresponding to the amount of occupied memory, that is, whether there is a memory block equal to the amount of occupied memory or a memory block that is larger than the target memory block but has the smallest difference with the amount of occupied memory. If it exists, call the second management table where the memory block is located, and use the second management table to find out whether there are any free memory blocks, and then return the address of the free memory block that is ranked first among the free memory blocks to the embedded software, so that the embedded software can occupy the free memory block at runtime. If there is no free memory block in the second management table that is searched, continue to search for free memory blocks in the next second management table through the string table information of the second management table until a free memory block is found. If there is indeed no free memory block or the memory block is less than the amount of occupied memory, the new memory page is divided into multiple memory blocks based on the amount of occupied memory and the preset memory block configuration table. The memory block configuration table is shown in Table 1:

[0100]

[0101] The values ​​in Table 1 are all optional memory block sizes. Therefore, after obtaining the occupied memory amount, the size relationship between the occupied memory amount and the memory blocks in Table 1 is compared in turn, and the memory block that is equal to the occupied memory amount or greater than the occupied memory amount but has the smallest difference with the occupied memory amount is used as the target memory block, thereby dividing the new memory page into multiple target memory blocks of equal amount. In other words, a target memory block size is first selected according to the occupied memory amount, and then the target memory block size is used as the division standard to divide the new memory page into multiple target memory blocks of the same size. In the divided new memory page, except for the first row being occupied, the memory blocks from the second row to the last row are not occupied, so the second management table returns the address of the memory block of the second row to the embedded software, and the embedded software occupies the free memory block of the second row. And mark the memory block as "occupied" in the second management table, and modify the free_blk pointer to point to the second row.

[0102] From this, it can be seen that, for the memory pages where some memory blocks are occupied, when the embedded software has the same memory requirement, the present application will give priority to finding available memory blocks from the memory pages in that part; when the memory pages where some memory blocks are occupied cannot be used, new memory pages will continue to be allocated, thereby reducing the number of memory pages occupied by the embedded software in the large memory area, so as to achieve the purpose of saving memory space.

[0103] The above is the memory allocation process when the target memory area is a large memory area, and when the target memory area is a small memory area, the required memory amount can be allocated to the embedded software by the division method in the long-term memory area, or the required memory amount can be allocated to the embedded software according to the division method in the large memory area. When the required memory amount is allocated to the embedded software in the small memory area, the allocation process is the same as the above-mentioned process of allocating to the embedded software in the large memory area, that is, the small memory area also includes the first management table and the second management table, and for the memory pages occupied by some memory blocks, when the embedded software has the same memory demand, it is preferred to find available memory blocks from the memory pages of this part; when the memory pages occupied by some memory blocks cannot be used, new memory pages are continuously allocated, thereby reducing the number of memory pages occupied by the embedded software in the large memory area, so as to achieve the purpose of saving memory space. For this reason, this application will no longer elaborate on allocating the required memory amount to the embedded software in the small memory area.

[0104] In summary, the present application first divides the memory space of the embedded software into three memory areas. When receiving the request memory instruction sent by the embedded software, first match the appropriate memory area for it according to the request memory instruction. If the matching result is a large memory area or a small memory area, then continue to judge the memory area adapted to the occupied memory amount, avoid the large occupied memory amount occupying a smaller memory block and increasing the number of memory blocks, and also prevent the small occupied memory amount from occupying a larger memory block and wasting the space resources of the larger memory block. Further, in each memory page, for the memory page where part of the memory block is occupied, when the embedded software has the same memory demand, it is preferred to find the available memory block from the memory page of this part; when the memory page where part of the memory block is occupied cannot be used, continue to allocate new memory pages, thereby reducing the number of memory pages occupied by the embedded software. Therefore, the present application can support the embedded software to frequently apply for memory from the embedded system, and can also reduce the degree of memory fragmentation during use, avoid the waste of memory fragments, thereby achieving the purpose of saving the memory space resources of the embedded software.

[0105] In order to support the above-mentioned dynamic memory management method of embedded systems, Figure 8 As shown, the management system includes a data management module 1 , a data acquisition module 2 , a data judgment module 3 , a first processing module 4 and a second processing module 5 .

[0106] The data management module 1 is used to divide the memory space of the embedded system into a long-term memory area, a large memory area and a small memory area.

[0107] The data acquisition module 2 is used to obtain the memory request instruction, which includes the software type and the amount of memory occupied.

[0108] The data judgment module 3 is used to determine the target memory area according to the software type, and the target memory area is one of the long-term memory area, the large memory area and the small memory area.

[0109] The first processing module 4 is used to determine whether there is a memory page whose memory block is larger than the occupied memory amount in the target memory area, and the memory page is composed of at least one memory block.

[0110] The second processing module 5 is used to mark the memory page whose memory block is larger than the occupied memory amount as the target memory page when there is a memory page whose memory block is larger than the occupied memory amount in the target memory area, and allocate one of the free memory blocks in the target memory page to the embedded software, and the free memory block is an unoccupied memory block; it is also used to allocate one of the free memory pages in the target memory area to the embedded software, and the free memory page is an unoccupied memory page when there is no memory page whose memory block is larger than the occupied memory amount in the target memory area.

[0111] The modules involved in the embodiments described in the present application may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a data management module 1, a data acquisition module 2, a data judgment module 3, a first processing module 4 and a second processing module 5. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the data acquisition module 2 may also be described as a "module for obtaining request instructions".

[0112] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the described module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0113] In order to better execute the program of the above method, the present application also provides a dynamic memory management terminal of an embedded system, which includes a memory and a processor.

[0114] The memory may be used to store instructions, programs, codes, code sets or instruction sets. The memory may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function, and instructions for implementing the above-mentioned dynamic memory management method for an embedded system, etc.; the data storage area may store data involved in the above-mentioned dynamic memory management method for an embedded system, etc.

[0115] The processor may include one or more processing cores. The processor calls the data stored in the memory by running or executing the instructions, programs, code sets or instruction sets stored in the memory, performs various functions of the present application and processes data. The processor may be at least one of a special purpose integrated circuit, a digital signal processor, a digital signal processing device, a programmable logic device, a field programmable gate array, a central processing unit, a controller, a microcontroller and a microprocessor. It is understandable that for different devices, the electronic device used to implement the above-mentioned processor function can also be other, and the embodiments of the present application are not specifically limited.

[0116] The present application also provides a computer-readable storage medium, for example, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes. The computer-readable storage medium stores a computer program that can be loaded by a processor and execute the dynamic memory management method of the above embedded system.

[0117] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the aforementioned disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present application (but not limited to) by each other to form a technical solution.

Claims

1. A dynamic memory management method for an embedded system, characterized in that: include: Obtaining a memory request instruction, wherein the memory request instruction includes a software type and an amount of occupied memory; Determine a target memory area according to the software type, the target memory area includes memory pages and a first management table, the first management table is used to manage all memory pages in the target memory area; the first management table is configured with a positioning pointer, the positioning pointer is used to concatenate all free memory pages in the target memory area, the positioning pointer points to all free memory pages in the priority order of "unoccupied and sorted first>released first"; The target memory area is one of a long-term memory area, a large memory area, and a small memory area; In the target memory area, determining whether there is a memory page with a memory block larger than the occupied memory amount, the memory page being composed of at least one memory block; If so, the memory page whose memory block is larger than and closest to the occupied memory amount is marked as the target memory page, and one of the free memory blocks in the target memory page is allocated to the embedded software, including: calling the second management table of the target memory page, the second management table is used to manage the target memory page; the second management table selects the first-ranked free memory block from the free memory blocks of the target memory page and allocates it to the embedded software; the second management table stores string table information, the string table information is used to point to the second management table adjacent to it, and the memory blocks of the memory pages managed by any two adjacent second management tables are the same size; the free memory block is an unoccupied memory block; If not, one of the free memory pages in the target memory area is allocated to the embedded software, and the free memory page is an unoccupied memory page.

2. The dynamic memory management method for embedded systems according to claim 1, characterized in that: The software type is one of a type that only applies for memory but does not release the memory and a type that applies for memory during operation and releases the memory when the operation ends; The determining the target memory area according to the software type includes: When the software type is a type that only applies for memory but does not release memory, marking the long-term memory area as a target memory area; When the software type is a type that applies for memory during runtime and releases memory when the runtime ends, it is determined whether the small memory area satisfies: , If yes, marking the large memory area as a target memory area; If not, the small memory area is marked as the target memory area.

3. The dynamic memory management method for embedded systems according to claim 1, characterized in that: When the large memory area is used as the target memory area, the method further includes: When the memory block is smaller than the occupied memory amount or there is no free memory block, the new memory page is divided into multiple memory blocks according to the occupied memory amount and a preset memory block configuration table, and the address of the memory block in the second row of the new memory page is returned to the embedded software.

4. A dynamic memory management system for an embedded system, characterized in that: include: A data acquisition module (2) is used to acquire a memory request instruction, wherein the memory request instruction includes a software type and an amount of memory occupied; A data judgment module (3) is used to determine a target memory area according to the software type, wherein the target memory area includes memory pages and a first management table, wherein the first management table is used to manage all memory pages in the target memory area; a positioning pointer is configured in the first management table, wherein the positioning pointer is used to connect all free memory pages in the target memory area in series, wherein the positioning pointer points to all free memory pages in the priority order of "unoccupied and sorted first>released first"; and the target memory area is one of a long-term memory area, a large memory area, and a small memory area; A first processing module (4) is used to determine whether there is a memory page in the target memory area whose memory block is larger than the occupied memory amount, wherein the memory page is composed of at least one memory block; The second processing module (5) is used to mark the memory page whose memory block is larger than the occupied memory amount as the target memory page when there is a memory page whose memory block is larger than and closest to the occupied memory amount in the target memory area, and allocate one of the free memory blocks in the target memory page to the embedded software, including: calling the second management table of the target memory page, the second management table is used to manage the target memory page; the second management table selects the free memory block with the first ranking from the free memory blocks of the target memory page and allocates it to the embedded software; the second management table stores string table information, the string table information is used to point to the second management table adjacent to it, and the memory blocks of the memory pages managed by any two adjacent second management tables are the same size; the free memory block is an unoccupied memory block; and is also used to allocate one of the free memory pages in the target memory area to the embedded software when there is no memory page whose memory block is larger than the occupied memory amount in the target memory area, the free memory page is an unoccupied memory page.

5. A dynamic memory management terminal for an embedded system, characterized in that: The method comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the program, the method according to any one of claims 1 to 3 is implemented.

6. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.