Memory management method for dynamic allocation of operating system and storage medium

Through the dynamic memory management method of embedded systems, a small amount of memory is allocated for the first time and dynamically expanded according to demand, which solves the problem of memory resource waste and improves memory utilization and system stability.

CN120653439AActive Publication Date: 2025-09-16GUANGZHOU JINQILI INFORMATION TECH CO LTD

Patent Information

Application Number
CN202510763407.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-09
Publication Date
2025-09-16
Estimated Expiration
2045-06-09

AI Technical Summary

Technical Problem

In the prior art, memory resources in embedded systems are scarce, which leads to over-allocation when applying for memory, resulting in resource waste and low utilization.

Method used

The operating system dynamically allocates memory management methods, initially allocating a fixed small amount of memory, which is then dynamically expanded according to actual needs. By modifying the memory allocation and operation interface, the program is ensured to run stably and memory redundancy is avoided.

Benefits of technology

It improves the utilization of memory resources, supports more programs running simultaneously, reduces system maintenance costs, and ensures program stability and flexibility of memory management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653439A_ABST
    Figure CN120653439A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of embedded systems, in particular to a memory management method for dynamic allocation of an operating system and a storage medium, and dynamic memory management is realized by transforming a memory allocation interface and an operation interface of the operating system. A memory applicant adds a flag bit when initiating a demand application, an operating system executes allocation operation according to the flag bit, when the flag bit indicates that the demand is determined, allocation is performed according to a specified length, and when the flag bit indicates that the demand is not determined, a fixed-length memory block is allocated firstly. And when the memory operation is executed, detecting the idle state of the subsequent memory block according to the memory head flag bit, and expanding the original memory block or redistributing and copying data. According to the method, the memory waste can be remarkably reduced, the memory use efficiency under resource-limited scenes such as an embedded scene and the like is improved, the system flexibility is enhanced through configuration file adjustment and a flag bit strategy while stable operation of a program is guaranteed, and memory management and maintenance are facilitated in combination with detailed memory information records.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of embedded systems, and in particular relates to a memory management method and storage medium dynamically allocated by an operating system. Background Art

[0002] In the embedded industry, limited hardware resources are a long-standing problem. Memory resources, in particular, are extremely scarce. Device memory capacity is typically only a few hundred megabytes, and some low-power or compact devices even have less than a few hundred kilobytes. When allocating memory, operating systems and various applications generally adopt conservative memory allocation strategies for program stability. To avoid abnormal situations such as program crashes and data loss caused by memory overflow, developers often request more memory than actually needed. This phenomenon is particularly pronounced when memory usage is dynamic or difficult to accurately estimate.

[0003] An existing patent (publication number CN109522121A) discloses a memory allocation method and apparatus, comprising: dividing memory space into a general memory area and a reserved memory area; upon receiving a memory request from an application, determining whether the amount of memory in the general memory area reaches the amount of memory requested by the application; if not, determining whether the application is an emergency application; if so, allocating memory resources from the reserved memory area to the emergency application. By establishing an independent reserved memory area, the present invention prevents the system from being unable to run some critical applications due to insufficient memory resources, thereby ensuring stable system operation. While this memory allocation strategy ensures program reliability to a certain extent, it inevitably leads to excessive occupation and waste of memory resources, affecting their effective utilization.

[0004] In view of this, the present invention is proposed. Summary of the Invention

[0005] In order to solve the above-mentioned technical problems existing in the prior art, the present invention provides a memory management method and storage medium for dynamic allocation of an operating system. Aiming at the problem of memory waste caused by excessive allocation when a program applies for memory in the prior art, the present invention uses a memory dynamic allocation method to allocate only a small amount of memory during the first allocation, and then dynamically allocate memory according to actual needs. This avoids allocating memory exceeding actual needs while ensuring the normal operation of the program, thereby improving the effective utilization of memory resources.

[0006] To achieve the above object, the technical solution of the present invention is as follows: In a first aspect, a memory management method for dynamic allocation of an operating system comprises: The memory requester initiates a memory demand application, wherein the demand application includes a flag bit added according to whether the memory demand size is confirmed or not; The operating system side performs a memory allocation operation based on the flag bit, wherein: if the flag bit indicates that the memory requirement size is determined, a memory block is allocated according to the length specified by the applicant; if the flag bit indicates that the memory requirement size is uncertain, a corresponding memory block is allocated to the applicant according to the memory requirement size determined by the detection.

[0007] Furthermore, the specific steps of allocating corresponding memory blocks according to the memory requirement size determined by the detection include: Get the length of the memory to be operated, and check whether the consecutive memory blocks of the set length after this memory space are all free; If the memory block is free, apply for the free memory block and expand it onto the original memory, and perform the predetermined memory operation; If the memory block is not free, search for a memory block of matching size again, allocate a memory block of preset length, copy the data on the original memory block to the new memory block in sequence, then perform the established memory operation, finally release the space of the original memory block and return the first address of the new memory block.

[0008] Furthermore, when the flag bit indicates that the memory requirement size is determined, the flag bit is set to 0, and the operating system allocates a memory block according to the length specified by the applicant; When the flag bit indicates that the memory requirement size is uncertain, the flag bit is set to 1, and the operating system ignores the length specified by the applicant and allocates the memory block according to the first preset length.

[0009] Furthermore, the specified length is 3 bytes or 10 bytes.

[0010] Furthermore, when allocating memory, an additional memory having a second preset length is requested to store the memory header information, and no matter whether the flag bit is 0 or 1, the value of the flag bit is stored in the memory header information.

[0011] Furthermore, if the flag bit in the read memory header information is 0, the memory block allocation of the length specified by the applicant is directly executed.

[0012] Furthermore, if the flag bit in the read memory header information is 1, the memory length to be operated is obtained as a third preset length, and it is detected whether the continuous memory blocks after the memory space are all free.

[0013] Furthermore, the length of the continuous memory block=the third preset length-the first preset length.

[0014] Furthermore, if it is detected that the continuous memory blocks are free after the memory space is checked, the free memory blocks are requested and extended onto the original memory, and then the predetermined memory operation is performed.

[0015] Furthermore, if it is detected that the continuous memory blocks after the memory space are not free, a memory block with a length of the third preset length + the second preset length is allocated, the data on the original memory block is copied to the new memory block in sequence, and then the established memory operation is performed.

[0016] Furthermore, after reallocating the memory block and performing the operation, the space of the original memory block is released and the first address of the new memory block is returned.

[0017] Furthermore, the releasing of the space of the original memory block is to include the original memory block into an allocatable memory pool through the operating system for subsequent memory allocation.

[0018] Furthermore, the detection of whether the memory block is idle is performed by recording the memory usage status of the operating system to determine whether the corresponding memory block is in an unused state.

[0019] In a second aspect, the present invention further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the computer program implements the above-mentioned memory management method for dynamic allocation of an operating system.

[0020] Compared with the prior art, the present invention realizes dynamic memory management by transforming the operating system's memory allocation interface and operation interface, which has significant and multi-dimensional beneficial effects. For embedded and other hardware resource-constrained scenarios, when memory requirements are uncertain, the traditional mode of pre-allocating a large amount of memory is abandoned, and only a fixed small amount of memory is allocated for the first time, and then dynamically expanded according to actual needs. This mechanism effectively avoids memory redundancy, maximizes the utilization of limited memory resources, can support more programs running at the same time, and significantly improves the efficiency of memory resource utilization. In terms of ensuring the stable operation of the program, when a memory operation is performed and a memory block is detected to be non-free, the program is ensured not to cause exceptions due to insufficient memory or overflow during operation by re-searching a suitable memory block and copying the data. It not only guarantees the memory space required for the normal operation of the program, but also avoids excessive occupation of memory resources, and achieves a balance between stability and resource utilization. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 A flowchart of a memory management method for dynamic allocation of an operating system provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] The technical solution of the present invention will be clearly described below in conjunction with the accompanying drawings. Obviously, the described embodiments are not all embodiments of the present invention. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0023] It should be noted that, unless otherwise specifically stated, the relative arrangements of components and steps, and numerical expressions set forth in these embodiments should not be construed as limiting the scope of the present invention.

[0024] The following description of exemplary embodiments is merely illustrative and is not intended to limit the present invention, its application, or use in any sense. Technologies, methods, and apparatus known to those skilled in the art may not be discussed in detail herein, but to the extent applicable, such technologies, methods, and apparatuses should be considered part of this specification.

[0025] See Figure 1 The following is a flowchart of a memory management method for dynamically allocated memory in an operating system, proposed by the present invention. This method solves the problem of memory waste by dynamically allocating memory. During the initial allocation, only a small amount of memory is allocated, and subsequent memory allocation is dynamically allocated based on actual needs. This is achieved by modifying the memory allocation interface and memory operation interface in the operating system. The specific steps include: S1. Memory allocation interface transformation When a memory requester initiates a memory request, it needs to add a flag to the request based on whether the memory requirement size is confirmed. The operating system performs memory allocation operations based on this flag, as follows: S11. When the applicant clearly knows the memory length he needs and does not need redundancy, the mark position is set to 0. At this time, the memory allocation interface of the operating system will allocate a memory block according to the length specified by the applicant.

[0026] For example, if in a certain application scenario, the applicant specifies that 100 bytes of memory are required after calculation or knowing the memory required for program operation, the operating system will strictly follow the application requirement and allocate a continuous memory block of 100 bytes in length from the memory resources. At the same time, when allocating memory, an additional fixed-length memory segment will be requested, namely the second preset length, assuming that this length is n bytes. The second preset length is usually 16 bytes or more, which may vary slightly from operating system to operating system. It is mainly used to store memory header information and is sufficient to store header information.

[0027] This additional memory is used to store memory header information. Memory header information is an important data structure in memory management, containing key attributes and management information of the memory block, such as the size and usage status of the memory block. At this time, the operating system will store the value of the mark bit, which is 0, in the memory header information to facilitate subsequent identification and management of the memory block. After completing the allocation and information recording of the memory block, the operating system returns the first address of the memory block to the applicant, and the applicant can then access and operate the allocated memory through this first address.

[0028] S12. When the applicant is unsure of the actual memory length required, the flag is set to 1. At this point, the operating system's memory allocation interface ignores the length specified by the applicant and instead allocates a memory block according to a first preset length. The first preset length is assumed to be h bytes. This length can be determined by the user based on actual application requirements and the hardware environment, and can be flexibly configured through a configuration file. For example, to conserve more memory, the first preset length can be set as small as possible, or even 0. However, if the user finds a setting of 5 more appropriate, this can eliminate the need to expand memory in most cases while still achieving memory savings.

[0029] For example, in some embedded devices that are more cautious about memory usage, h can be set to 3 bytes; in some scenarios with slightly larger initial memory requirements, it can be adjusted to 10 bytes. For example, even if a program with uncertain memory requirements specifies an arbitrary length when requesting a memory block, the operating system will still allocate a memory block of h bytes because the flag bit is 1. Similarly, during memory allocation, an additional n bytes of memory are requested to store memory header information, and the flag bit value 1 is stored in the memory header information. Finally, the operating system returns the starting address of the memory block to the requester for subsequent use.

[0030] S2. Memory operation interface modification When an operation is required on the allocated memory, the operating system reads the flag bit from the memory header information to be operated on and performs different operations based on the value of the flag bit: If the flag bit in the memory header information read is 0, it indicates that the applicant has clearly defined their memory requirements when allocating the memory block and no subsequent adjustments are required. At this point, the operating system will directly execute the specified memory operation. For example, in a data processing program, if a data write operation is required, the operating system will directly and accurately write the data to the corresponding memory block storage location based on the memory block's first address and operation instructions, without the need for additional memory checks and adjustments.

[0031] S22. If the flag bit in the memory header information is 1, indicating that the applicant is unsure of the actual memory requirements when allocating the memory block, the operating system will perform the following steps: S221. Obtaining the Length of the Memory to be Operated: The operating system obtains the length of the memory to be operated on based on the current memory operation instruction and program execution requirements, and records this length as a third preset length, assuming it is m bytes. The third preset length is determined by user operation. When a memory operation is required to write to this memory segment, the memory operation interface obtains the desired length. This length m is dynamically determined based on the memory requirements generated during actual program execution. For example, during program execution, an increase in data volume or expansion of functional modules may require more memory space to store data or run code.

[0032] S222. Checking the free status of memory blocks: After obtaining the length m, the operating system checks whether all consecutive memory blocks of length (mh) following the memory space are free. The operating system maintains a memory usage status record mechanism, typically in the form of a data structure such as a table or linked list. This records detailed information such as the starting address, length, and usage status of each memory block. By traversing and comparing these records, the operating system can determine whether the corresponding memory block is unused, i.e., free.

[0033] S223. Idle Condition Processing: If all consecutive memory blocks are detected as free, this indicates that the current memory space can meet the program's further memory needs. The operating system will request this free memory block from the memory management module and extend it onto the original memory block. For example, if the original memory block is h bytes long, after extension, the memory block length becomes m bytes, providing sufficient memory space for the program. The operating system can then perform designated memory operations, such as writing new data to the expanded memory area.

[0034] S224. Non-Idle Handling: If it is detected that not all of these consecutive memory blocks are free, it indicates that the current memory space cannot directly meet the program's memory needs. At this point, the operating system initiates a memory reallocation mechanism to search for a new appropriately sized memory block within the memory resources. The newly allocated memory block is (m+n) bytes long, where m is the actual memory length required by the program and n is the length used to store memory header information.

[0035] The operating system copies the data from the original memory blocks to the new memory blocks one by one in the order in which the data was stored, ensuring data integrity and accuracy. After the data is copied, the specified memory operations are performed to meet the program's running requirements.

[0036] The operating system adds the original memory block to the allocatable memory pool, updates the memory usage status record, marks it as reallocatable for subsequent use by other memory requests, and returns the first address of the new memory block to the relevant program so that the program can continue to operate on the memory through the new address.

[0037] In a second aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the computer program implements the above-mentioned memory management method for dynamic allocation of an operating system.

[0038] In summary, the present invention has the following advantages: 1. By detecting and properly handling the idle state of memory blocks, it can ensure that the program has sufficient and appropriate memory space during operation, avoiding program exceptions caused by insufficient or overflow memory, and providing a solid guarantee for the stable operation of the program; 2. The preset length of memory allocation can be flexibly adjusted through the configuration file, making it easier for the operating system to track and maintain memory usage, greatly improving the flexibility and operability of memory management; 3. The interface has been modified to form an efficient management mechanism, which reduces the complexity of memory management and enables the system to more conveniently locate and handle memory-related issues during operation, effectively reducing the cost and difficulty of system maintenance.

[0039] The above specific embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to examples, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the scope of the technical solutions of the present invention, and all of these should be included in the scope of the claims of the present invention.

Claims

1. A memory management method for dynamic allocation of an operating system, characterized in that: include: The memory requester initiates a memory demand application, wherein the demand application includes a flag bit added according to whether the memory demand size is confirmed or not; The operating system side performs a memory allocation operation based on the flag bit, wherein: if the flag bit indicates that the memory requirement size is determined, a memory block is allocated according to the length specified by the applicant; if the flag bit indicates that the memory requirement size is uncertain, a corresponding memory block is allocated to the applicant according to the memory requirement size determined by the detection.

2. The memory management method for dynamic allocation of an operating system according to claim 1, characterized in that: The specific steps of allocating the corresponding memory block according to the memory requirement size determined by the detection include: Get the length of the memory to be operated, and check whether the consecutive memory blocks of the set length after this memory space are all free; If the memory block is free, apply for the free memory block and expand it onto the original memory, and perform the predetermined memory operation; If the memory block is not free, search for a memory block of matching size again, allocate a memory block of preset length, copy the data on the original memory block to the new memory block in sequence, then perform the established memory operation, finally release the space of the original memory block and return the first address of the new memory block.

3. The memory management method for dynamically allocated memory of an operating system according to claim 1, characterized in that: When the flag bit indicates that the memory requirement size is determined, the flag bit is set to 0, and the operating system allocates a memory block according to the length specified by the applicant; When the flag bit indicates that the memory requirement size is uncertain, the flag bit is set to 1, and the operating system ignores the length specified by the applicant and allocates the memory block according to the first preset length.

4. The memory management method for dynamic allocation of an operating system according to claim 3, characterized in that: The specified length is 3 bytes or 10 bytes.

5. The memory management method for dynamic allocation of an operating system according to claim 3, characterized in that: When allocating memory, an additional memory having a length of the second preset length is requested to store the memory header information, and no matter whether the flag bit is 0 or 1, the value of the flag bit is stored in the memory header information.

6. The memory management method for dynamic allocation of an operating system according to claim 5, characterized in that: If the flag bit in the memory header information read is 0, the memory block is allocated directly with the length specified by the applicant.

7. The memory management method for dynamic allocation of an operating system according to claim 5, characterized in that: If the flag bit in the read memory header information is 1, the memory length to be operated is obtained as the third preset length, and it is detected whether the continuous memory blocks after the memory space are all free.

8. The memory management method for dynamic allocation of an operating system according to claim 7, characterized in that: The length of the continuous memory block=the third preset length-the first preset length.

9. The memory management method for dynamic allocation of an operating system according to claim 7, characterized in that: If the continuous memory blocks are free after detecting the memory space, the free memory blocks are requested and extended to the original memory, and then the established memory operations are performed.

10. The memory management method for dynamic allocation of an operating system according to claim 7, characterized in that: If it is detected that the continuous memory blocks after the memory space are not free, a memory block with a length of the third preset length + the second preset length is allocated, the data on the original memory block is copied to the new memory block in sequence, and then the established memory operation is performed.

11. The memory management method for dynamic allocation of an operating system according to claim 10, characterized in that: After reallocating the memory block and performing the operation, the space of the original memory block is released and the first address of the new memory block is returned.

12. The memory management method for dynamic allocation of an operating system according to claim 2 or 11, characterized in that: The releasing of the space of the original memory block is to include the original memory block into an allocatable memory pool through the operating system for subsequent memory allocation.

13. The memory management method for dynamic allocation of an operating system according to claim 7, characterized in that: The detection of whether the memory block is idle is performed by recording the memory usage status of the operating system to determine whether the corresponding memory block is in an unused state.

14. A computer-readable storage medium, characterized in that The storage medium stores a computer program, which, when executed by a processor, implements a memory management method for dynamic allocation of an operating system according to any one of claims 1 to 13.

Citation Information

Patent Citations

  • Memory application method and device, terminal and computer readable storage medium

    CN109522121A

  • Memory processing method and device, electronic equipment and storage medium

    CN118193222A

  • Memory pool dynamic management method and device, electronic equipment and storage medium

    CN118916154A

  • Memory allocation method and device and storage medium

    CN119440794A

  • Heap management using dynamic memory allocation

    US20140325177A1

Cited By

  • Memory block management method and controller

    CN122019198A

  • Memory management method of real-time operating system, real-time operating system and storage medium

    CN122064496A