CN106919513B - Memory management method and system - Google Patents

Memory management method and system Download PDF

Info

Publication number
CN106919513B
CN106919513B CN201710075744.3A CN201710075744A CN106919513B CN 106919513 B CN106919513 B CN 106919513B CN 201710075744 A CN201710075744 A CN 201710075744A CN 106919513 B CN106919513 B CN 106919513B
Authority
CN
China
Prior art keywords
memory
capacity
unit
units
memory capacity
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710075744.3A
Other languages
Chinese (zh)
Other versions
CN106919513A (en
Inventor
刘德建
刘俊
王国栋
方振华
郭玉湖
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian Tianquan Educational Technology Ltd
Original Assignee
Fujian Tianquan Educational Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian Tianquan Educational Technology Ltd filed Critical Fujian Tianquan Educational Technology Ltd
Priority to CN201710075744.3A priority Critical patent/CN106919513B/en
Publication of CN106919513A publication Critical patent/CN106919513A/en
Application granted granted Critical
Publication of CN106919513B publication Critical patent/CN106919513B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

The present invention relates to the field of memory management, and in particular, to a method and system for applying and releasing a memory. The invention receives the memory allocation request; if the first memory capacity of the request application is larger than a preset initial memory capacity value, the request is not executed; otherwise: if the created memory units do not have memory units with unallocated memory capacity greater than or equal to the first memory capacity, and the number of the created memory units is less than the number of preset memory units, then: and creating a memory unit with the memory capacity as the initial value of the memory capacity. The condition of memory fragmentation is avoided, and the operating efficiency of the processor is ensured.

Description

Memory management method and system
Technical Field
The present invention relates to the field of memory management, and in particular, to a memory management method and system.
Background
In the process of memory management, allocation and release of memory need to be performed quickly in real time.
However, when memory resources are very limited. If proper allocation and release operations are not managed well, frequent memory application and release operations may cause the memory of the system to be occupied for a long time or not completely released, thereby causing memory fragments and the like, which may further slow the system response and even cause system crash.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: a memory management method and system are provided to avoid memory fragmentation.
In order to solve the technical problems, the invention adopts the technical scheme that:
the invention provides a memory management method, which comprises the following steps:
receiving a memory allocation request;
if the first memory capacity of the request application is larger than a preset initial memory capacity value, the request is not executed; otherwise:
if the created memory units do not have memory units with unallocated memory capacity greater than or equal to the first memory capacity, and the number of the created memory units is less than the number of preset memory units, then:
and creating a memory unit with the memory capacity as the initial value of the memory capacity.
The present invention further provides a memory management system, including:
the first receiving module is used for receiving a memory allocation request;
the first judgment module is used for judging whether the first memory capacity of the request application is larger than a preset initial memory capacity value or not, and then the request is not executed;
the second judgment module is used for judging whether the created memory units have the unallocated memory capacity larger than or equal to the memory units with the first memory capacity or not and the number of the created memory units is smaller than the number of the preset memory units; a memory unit with the memory capacity of the initial memory capacity value is created.
The invention has the beneficial effects that: presetting an initial value of the memory capacity of the memory unit, and only receiving a memory allocation request smaller than the initial value. For the received request, if the created memory units have unallocated memories and are sufficient to allocate the memories applied by the request, the created memory units are preferentially allocated; otherwise, the memory unit is newly built to distribute the memory. By the mode, the condition of memory fragmentation can be avoided, and the memory allocation efficiency is improved.
Drawings
FIG. 1 is a flow chart of a memory management method according to an embodiment of the present invention;
FIG. 2 is a system diagram of a memory management system according to an embodiment of the present invention;
description of reference numerals:
1. a first receiving module; 2. a first judgment module; 3. a second judgment module;
Detailed Description
In order to explain technical contents, achieved objects, and effects of the present invention in detail, the following description is made with reference to the accompanying drawings in combination with the embodiments.
The most key concept of the invention is as follows: presetting an initial value of the memory capacity of a memory unit; and receiving a memory allocation application which is not greater than the initial value, and allocating the memory by inquiring the existing memory unit or newly building the memory unit. By the method, the condition of memory fragmentation is avoided, and the running efficiency of the processor is ensured.
Please refer to fig. 1 to 2:
as shown in fig. 1, the present invention provides a memory management method:
receiving a memory allocation request;
if the first memory capacity of the request application is larger than a preset initial memory capacity value, the request is not executed; otherwise:
if the created memory units do not have memory units with unallocated memory capacity greater than or equal to the first memory capacity, and the number of the created memory units is less than the number of preset memory units, then:
and creating a memory unit with the memory capacity as the initial value of the memory capacity.
From the above description, the beneficial effects of the present invention are: by specifying a fixed memory capacity of a memory unit, for each received memory allocation application, a memory space is allocated by the memory unit. Therefore, frequent memory application to the system is avoided; meanwhile, the expense of calling the system for applying the memory is reduced, the efficiency is improved, and the situation of fragmenting the memory is avoided.
Further, the method also comprises the following steps:
judging whether the unallocated memory capacity of the currently accessed memory unit is smaller than the first memory capacity;
if the memory capacity is smaller than the first memory capacity, traversing the created memory units, and judging whether memory units with the unallocated memory capacity larger than or equal to the first memory capacity exist in the created memory units;
if not, judging whether the number of the created memory units is less than the number of the preset memory units;
if the ratio is less than the preset value: and creating a memory unit with the memory capacity as the initial value of the memory capacity.
As can be seen from the above description, the efficiency of finding a memory unit capable of allocating sufficient memory capacity among the created memory units is improved by first determining whether the currently accessed memory unit matches the memory capacity required by the memory allocation application.
Further, the method also comprises the following steps:
presetting an identification number corresponding to the memory unit;
and creating a memory unit list according to the identification number and the unallocated memory capacity information of the memory unit.
As can be seen from the above description, the list is set to record the identification number of the created memory unit and the unallocated memory capacity of the corresponding memory unit, and then the memory unit meeting the memory capacity required by the memory allocation application can be found only by accessing the list, thereby improving the efficiency of finding the memory unit capable of allocating sufficient memory capacity in the created memory unit.
Further, the method also comprises the following steps:
presetting an identification number corresponding to the memory unit;
acquiring the identification number of the allocated memory unit and the initial address of the allocated memory;
and feeding back the identification number of the allocated memory unit and the initial address of the allocated memory to the memory allocation requester.
As can be seen from the above description, the identifier of the allocated memory unit and the start address of the allocated memory are fed back to the memory allocation requester, so that the memory allocation requester can access the memory address storage information more quickly and efficiently.
Further, the method also comprises the following steps:
presetting an identification number corresponding to the memory unit;
receiving a memory release request, wherein the memory release request comprises a memory unit identification number of a memory to be released, a memory initial address of the memory to be released and a memory capacity to be released;
and releasing the corresponding memory according to the memory release request.
It can be known from the above description that the released memory unit can be repeatedly used, so that the utilization efficiency of the memory space can be improved, and fragmentation of the memory caused by idle small memories is avoided.
As shown in fig. 2, the present invention provides a memory management system, which includes:
a first receiving module 1, configured to receive a memory allocation request;
a first judging module 2, configured to judge whether the first memory capacity of the request application is greater than a preset initial memory capacity value, and not execute the request;
a second determining module 3, configured to determine that, if there are no memory units with unallocated memory capacity greater than or equal to the first memory capacity in the created memory units, and the number of the created memory units is less than the number of preset memory units; a memory unit with the memory capacity of the initial memory capacity value is created.
Further, the second determining module 2 further includes:
the first judging unit is used for judging whether the unallocated memory capacity of the currently accessed memory unit is smaller than the first memory capacity;
a second judging unit, configured to traverse the created memory units if the number of the memory units is smaller than the first number, and judge whether a memory unit with an unallocated memory capacity greater than or equal to the first memory capacity exists in the created memory units;
a third judging unit, if not, for judging whether the number of the created memory units is less than the number of the preset memory units;
and if the memory capacity is smaller than the initial memory capacity, the creating unit is used for creating the memory unit with the memory capacity as the initial memory capacity.
Further, the method also comprises the following steps:
the first preset module is used for presetting the identification number corresponding to the memory unit;
and the list module is used for creating a memory unit list according to the identification number and the memory unit unallocated memory capacity information.
Further, the method also comprises the following steps:
the second preset module is used for presetting the identification number corresponding to the memory unit;
the acquisition module acquires the identification number of the allocated memory unit and the initial address of the allocated memory;
and the feedback module feeds back the identification number of the allocated memory unit and the initial address of the allocated memory to the memory allocation requester.
Further, the method also comprises the following steps:
the third preset module is used for presetting the identification number corresponding to the memory unit;
the second receiving module is used for receiving a memory release request, wherein the memory release request comprises a memory unit identification number of a memory to be released, a memory initial address of the memory to be released and a memory capacity to be released;
and the releasing module is used for releasing the corresponding memory according to the memory releasing request.
Example (b):
the embodiment of the invention provides a memory management method, which comprises the following steps:
s1, receiving a memory allocation request; and presetting an identification number corresponding to the memory unit.
For example, receiving a memory allocation request, setting an identification number for an existing memory unit in the memory space may be set according to a time sequence of generating the memory unit. For the memory unit divided into a header and a data portion, the header is used to record the basic data of the memory unit, and includes: memory cell identification number, memory cell status, memory cell size, next memory block address, next memory allocation location, and statistical information of memory applications.
The memory cell state refers to the condition whether the memory cell can be used or not; the size of the memory unit refers to the memory capacity of the data part of the memory unit; the next memory allocation position refers to the initial address of the unallocated memory of the memory unit; the statistical information of the memory application refers to the number of times the memory unit is applied for use, if the memory is applied for use twice, the statistical information means that the memory unit records the information of two programs, the statistical information of the memory application is 2, and if the memory unit is not applied for use, the statistical information is 0;
s2, creating a memory unit list according to the identification number and the memory unit unallocated memory capacity information; and if the first memory capacity of the request application is larger than a preset initial memory capacity value, the request is not executed.
For example, all created memory units are recorded in a specially configured list, where the list records the identification number of the memory unit and the unallocated memory capacity corresponding to the memory unit, and when a memory unit is applied or released, the unallocated memory capacity corresponding to the memory unit in the list needs to be recorded again. Judging whether the memory applied for distribution is not greater than a preset initial value of memory capacity or not for the received memory distribution application, and if so, not executing the request; if not, executing the following steps.
S3, if there is no memory cell with unallocated memory capacity greater than or equal to the first memory capacity in the created memory cells, and the number of created memory cells is less than the preset number of memory cells, then: and creating a memory unit with the memory capacity as the initial value of the memory capacity. S3 specifically determines whether the unallocated memory capacity of the currently accessed memory unit is less than the first memory capacity; if the memory capacity is smaller than the first memory capacity, traversing the created memory units, and judging whether memory units with the unallocated memory capacity larger than or equal to the first memory capacity exist in the created memory units; if not, judging whether the number of the created memory units is less than the number of the preset memory units; if the ratio is less than the preset value: and creating a memory unit with the memory capacity as the initial value of the memory capacity.
For example, when the received memory allocation request is judged to be not greater than the preset initial value of the memory capacity through the previous step, the memory to be allocated is determined; and then judging whether the memory is the first memory application, if so, directly creating a memory unit with the memory capacity as the initial value of the memory capacity. If the request is not the initial request, judging whether a memory unit of which the unallocated memory is greater than or equal to the memory required by the memory allocation request exists or not by recording a list of the unallocated memory corresponding to the memory unit identification number; the method mainly comprises the steps of firstly judging a currently accessed memory unit, and traversing other memory units if the currently accessed memory unit does not meet the memory capacity required by the application. If the memory unit of which the unallocated memory is greater than or equal to the memory required by the memory allocation application exists in the created memory units, the memory unit is allocated to the memory allocation application sending party, the allocated memory unit is set as the currently accessed memory unit, and the head information of the memory unit is rewritten, namely the next memory allocation position and the statistical information of the memory application are rewritten by 1. If the memory units with unallocated memory greater than or equal to the memory required by the memory allocation application do not exist in the created memory units, judging whether the number of the created memory units is less than the number of preset memory units, and if not, not executing the memory allocation application; and if the initial address of the memory unit is less than the initial value of the memory capacity, establishing the memory unit with the memory capacity as the initial value of the memory capacity, setting the established memory unit as the currently accessed memory unit, rewriting the head information of the memory unit, namely rewriting the next memory allocation position and adding 1 to the statistical information of the memory application, and recording the initial address of the established memory unit in the head information of the last memory unit.
S4, acquiring the identification number of the allocated memory unit and the initial address of the allocated memory; and feeding back the identification number of the allocated memory unit and the initial address of the allocated memory to the memory allocation requester.
For example, the identification number of the allocated memory unit and the start address of the storage location in the memory unit are fed back to the sending memory allocation requestor.
S5, receiving a memory release request, wherein the memory release request comprises a memory unit identification number of a memory to be released, a memory initial address of the memory to be released and a memory capacity to be released; and releasing the corresponding memory according to the memory release request.
For example, a memory release request is sent, where the memory release request must include a memory unit identification number of a memory to be released, a memory start address of the memory to be released, and a memory capacity to be released; and receiving the memory release request, and releasing the memory according to the memory release request. And at the same time, rewriting the head information of the memory unit of the released memory, namely rewriting the next memory allocation position and subtracting 1 from the statistical information of the memory application. And if the statistical information of the memory application is 0, rewriting the state identifier of the memory unit as not applied for use.
In summary, the present invention provides a memory management method and system, which avoid the situation of memory fragmentation. The method comprises the steps of receiving a memory allocation request smaller than a preset memory capacity initial value, searching a proper memory unit in built memory units to allocate memory to a requester, and if the memory allocation request is not proper, creating a memory unit with a new memory capacity equal to the preset memory capacity to allocate memory. When the created memory unit is searched, the memory unit which is accessed currently is searched, and if the memory unit is not suitable, other memory units are traversed. Meanwhile, the created memory units are recorded by creating a list. Meanwhile, a memory release request can be received, and the memory with the corresponding capacity and position can be released according to the memory release request.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (10)

1. A memory management method, comprising:
receiving a memory allocation request;
if the first memory capacity of the request application is larger than a preset initial memory capacity value, the request is not executed; otherwise:
if the created memory units do not have memory units with unallocated memory capacity greater than or equal to the first memory capacity, and the number of the created memory units is less than the number of preset memory units, then:
creating a memory unit with the memory capacity as the initial value of the memory capacity;
and the memory capacity of the created memory unit is the initial value of the memory capacity.
2. The memory management method according to claim 1, wherein if there is no memory unit with unallocated memory capacity greater than or equal to the first memory capacity among the created memory units, and the number of created memory units is less than a preset number of memory units, then: creating a memory unit with the memory capacity as the initial value of the memory capacity, specifically:
judging whether the unallocated memory capacity of the currently accessed memory unit is smaller than the first memory capacity;
if the memory capacity is smaller than the first memory capacity, traversing the created memory units, and judging whether memory units with the unallocated memory capacity larger than or equal to the first memory capacity exist in the created memory units;
if not, judging whether the number of the created memory units is less than the number of the preset memory units;
if the ratio is less than the preset value: and creating a memory unit with the memory capacity as the initial value of the memory capacity.
3. The memory management method according to claim 1, further comprising:
presetting an identification number corresponding to the memory unit;
and creating a memory unit list according to the identification number and the unallocated memory capacity information of the memory unit.
4. The memory management method according to claim 1, further comprising:
presetting an identification number corresponding to the memory unit;
acquiring the identification number of the allocated memory unit and the initial address of the allocated memory;
and feeding back the identification number of the allocated memory unit and the initial address of the allocated memory to the memory allocation requester.
5. The memory management method according to claim 1, further comprising:
presetting an identification number corresponding to the memory unit;
receiving a memory release request, wherein the memory release request comprises a memory unit identification number of a memory to be released, a memory initial address of the memory to be released and a memory capacity to be released;
and releasing the corresponding memory according to the memory release request.
6. A memory management system, comprising:
the first receiving module is used for receiving a memory allocation request;
the first judgment module is used for judging whether the first memory capacity of the request application is larger than a preset initial memory capacity value or not, and then the request is not executed;
the second judgment module is used for judging whether the created memory units have the unallocated memory capacity larger than or equal to the memory units with the first memory capacity or not and the number of the created memory units is smaller than the number of the preset memory units; creating a memory unit with the memory capacity of the initial memory capacity value, wherein the memory capacity of the created memory unit is the initial memory capacity value.
7. The memory management system according to claim 6, wherein the second determining module further comprises:
the first judging unit is used for judging whether the unallocated memory capacity of the currently accessed memory unit is smaller than the first memory capacity;
a second judging unit, configured to traverse the created memory units if the number of the memory units is smaller than the first number, and judge whether a memory unit with an unallocated memory capacity greater than or equal to the first memory capacity exists in the created memory units;
a third judging unit, if not, for judging whether the number of the created memory units is less than the number of the preset memory units;
and if the memory capacity is smaller than the initial memory capacity, the creating unit is used for creating the memory unit with the memory capacity as the initial memory capacity.
8. The memory management system according to claim 6, further comprising:
the first preset module is used for presetting the identification number corresponding to the memory unit;
and the list module is used for creating a memory unit list according to the identification number and the memory unit unallocated memory capacity information.
9. The memory management system according to claim 6, further comprising:
the second preset module is used for presetting the identification number corresponding to the memory unit;
the acquisition module acquires the identification number of the allocated memory unit and the initial address of the allocated memory;
and the feedback module feeds back the identification number of the allocated memory unit and the initial address of the allocated memory to the memory allocation requester.
10. The memory management system according to claim 6, further comprising:
the third preset module is used for presetting the identification number corresponding to the memory unit;
the second receiving module is used for receiving a memory release request, wherein the memory release request comprises a memory unit identification number of a memory to be released, a memory initial address of the memory to be released and a memory capacity to be released;
and the releasing module is used for releasing the corresponding memory according to the memory releasing request.
CN201710075744.3A 2017-02-13 2017-02-13 Memory management method and system Active CN106919513B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710075744.3A CN106919513B (en) 2017-02-13 2017-02-13 Memory management method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710075744.3A CN106919513B (en) 2017-02-13 2017-02-13 Memory management method and system

Publications (2)

Publication Number Publication Date
CN106919513A CN106919513A (en) 2017-07-04
CN106919513B true CN106919513B (en) 2020-05-12

Family

ID=59453568

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710075744.3A Active CN106919513B (en) 2017-02-13 2017-02-13 Memory management method and system

Country Status (1)

Country Link
CN (1) CN106919513B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8296542B2 (en) * 2009-09-30 2012-10-23 Red Hat, Inc. Dynamic memory allocation for applications
CN103077126A (en) * 2012-12-24 2013-05-01 中兴通讯股份有限公司 Memory management method and device
CN103150257A (en) * 2013-02-28 2013-06-12 天脉聚源(北京)传媒科技有限公司 Memory management method and memory management device
CN105159615A (en) * 2015-09-10 2015-12-16 上海斐讯数据通信技术有限公司 Dynamic memory control method and dynamic memory control system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8296542B2 (en) * 2009-09-30 2012-10-23 Red Hat, Inc. Dynamic memory allocation for applications
CN103077126A (en) * 2012-12-24 2013-05-01 中兴通讯股份有限公司 Memory management method and device
CN103150257A (en) * 2013-02-28 2013-06-12 天脉聚源(北京)传媒科技有限公司 Memory management method and memory management device
CN105159615A (en) * 2015-09-10 2015-12-16 上海斐讯数据通信技术有限公司 Dynamic memory control method and dynamic memory control system

Also Published As

Publication number Publication date
CN106919513A (en) 2017-07-04

Similar Documents

Publication Publication Date Title
US10609150B2 (en) Lock management method in cluster, lock server, and client
CN108132842B (en) Embedded software memory management system
CN105446813B (en) A kind of method and device of resource allocation
CN108038002B (en) Embedded software memory management method
US10152501B2 (en) Rollover strategies in a n-bit dictionary compressed column store
KR101357397B1 (en) Method for tracking memory usages of a data processing system
CN106294190B (en) Storage space management method and device
CN109388590B (en) Dynamic cache block management method and device for improving multichannel DMA (direct memory access) access performance
CN105389264B (en) The method and system of garbage collection in storage system
CN103116552A (en) Method and device for distributing storage space in distributed type storage system
CN105245912A (en) Methods and devices for caching video data and reading video data
CN102063338A (en) Method and device for requesting exclusive resource
CN110727517A (en) Memory allocation method and device based on partition design
CN111984425A (en) Memory management method, device and equipment for operating system
CN103389945A (en) Memory management method and device
CN112685333B (en) Heap memory management method and device
CN108132759A (en) A kind of method and apparatus that data are managed in file system
CN110162395B (en) Memory allocation method and device
CN106919513B (en) Memory management method and system
CN105450679A (en) Method and system for performing data cloud storage
US9652393B1 (en) Managing shared memory in database server
CN110891033B (en) Network resource processing method, device, gateway, controller and storage medium
CN110825732A (en) Data query method and device, computer equipment and readable storage medium
US9170929B2 (en) Memory controller
CN114518962A (en) Memory management method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant