CN1327348C - Method for resolving frequently distributing and releasing equal size internal memory - Google Patents

Method for resolving frequently distributing and releasing equal size internal memory Download PDF

Info

Publication number
CN1327348C
CN1327348C CNB2005100607956A CN200510060795A CN1327348C CN 1327348 C CN1327348 C CN 1327348C CN B2005100607956 A CNB2005100607956 A CN B2005100607956A CN 200510060795 A CN200510060795 A CN 200510060795A CN 1327348 C CN1327348 C CN 1327348C
Authority
CN
China
Prior art keywords
memory
memory pool
pool
freen
size
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.)
Expired - Fee Related
Application number
CNB2005100607956A
Other languages
Chinese (zh)
Other versions
CN1740975A (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.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
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 Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CNB2005100607956A priority Critical patent/CN1327348C/en
Publication of CN1740975A publication Critical patent/CN1740975A/en
Application granted granted Critical
Publication of CN1327348C publication Critical patent/CN1327348C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Memory System (AREA)

Abstract

The present invention discloses a method for resolving frequently distributing and releasing memories with the same size. The method of the present invention maintains a chain list of which the memory pools can be expanded, and uses a function to dynamically control the size and the number of the memory pools in the memory pool chain list. The chain list is used to manage the memory pools to avoid the condition that memory fragmentation is increased because a general memory pool distributing manner re-distributes bigger memory blocks as memory pools to meet the requirement for expanding the original memory pools which can not be extended under the condition that the memory pools are not big enough, and avoid the situation of frequently distributing memories caused by continuously extending the memory pools. The function is used to control the size and the number of the distributed memory pools so that an application program can more effectively utilize the memory and save the memory, and improves the customizability of the memory of the application program.

Description

Solve the method for frequently distributing and releasing equal size internal memory
Technical field
The present invention relates to the application program memory management technology, particularly relate to a kind of method that solves frequently distributing and releasing equal size internal memory.
Background technology
Internal memory is the important hardware facility of computer products, and it all is to be based upon operating system on the management of internal memory that the Memory Allocation of application program discharges.Operating system provides interface such as malloc, and function supplies such as free are carried out the associative operation of internal memory with program, and the operating system then internal memory operating position of application programs itself manages.
The memory management mechanism of operating system can produce the situation of several internal memory wastes: internal fragmentation and external fragmentation.
The memory management mechanism of operating system is followed some basic Memory Allocation rules.For example, must originate in can be by 4,8 or 16 addresses of dividing exactly in the distribution of all internal memories.Memory management mechanism only in advance the memory block of sizing distribute to application program.In the time of the memory block of one 43 byte of an application requests, memory management mechanism may be distributed 44 bytes or 48 bytes even the internal memory that satisfies the Memory Allocation rule to it more.By required size round up and the redundant space that produces internal fragmentation.
When the difference that occurs between the storage allocation piece not being used, will produce external fragmentation.For example, three continuous memory blocks of an application assigned, the memory block in the middle of discharging then.Memory block in the middle of the memory management mechanism of operating system can be reused distributes for memory block in the future.But unlikely the size of the memory block that distributes in the future is equally big with all free memory blocks of operating system.Memory management mechanism so can only be partitioned into the little memory block that application program requires that satisfies in the middle of big free memory block, continue to get off so always, fragment between the much little internal memory can appear at last, they can not satisfy any one memory request of application program, and these are exactly external fragmentation.
In frequently distributing and releasing equal size internal memory, operating system can produce a large amount of external memory fragments, and influences the efficient of operating system.Traditional solution is to adopt memory pool.But single memory pool exists, and customization is poor, internal memory waste, might produce defective such as memory fragmentation in the exented memory pond, therefore, method to traditional frequently distributing and releasing equal size internal memory is transformed, can increase the customizability of application program internal memory, improve the service efficiency of Installed System Memory, improve system performance.
A memory pool is the application program contiguous memory that pre-first to file obtains from operating system, and the attribute of memory pool comprises the size of the size of memory pool, start address, end address, memory block, the number of memory block, the sign of memory block, the out of Memory of memory block etc.The size of memory pool is size, the sign size of memory block and the out of Memory size sum of memory block that the number of memory block multiply by memory block.
Application program is the size of storage allocation as required, gets the address of free memory block from the memory pool of correspondence and uses, and returns to memory pool after using.
When memory pool does not have free memory block, the application extensions memory pool, operating system is responsible for according to the memory management mechanism exented memory pond of operating system or is redistributed bigger memory pool, and original memory pool information reproduction is arrived new memory pool.
Existing internal memory pool managing method, when application program is incipient, just limited the size of memory pool, customizability is relatively poor, although can the exented memory pond when memory pool is big inadequately, but may produce the external memory fragment equally, and, do not stop the exented memory pond and just be equivalent to frequent storage allocation always under the condition of enlarged at memory pool, system effectiveness there is tangible influence.
Therefore,, can improve the customizability of whole application program internal memory if can propose the frequent method of distributing equal size of more effective solution, more efficient use internal memory and save memory, the travelling speed of raising application program reduces the response time.
Summary of the invention
The object of the present invention is to provide a kind of method that solves frequently distributing and releasing equal size internal memory.
The technical solution used in the present invention is as follows:
1) size of note frequently distributing and releasing equal size internal memory is msize, the pointer of memory pool chained list is plist, and n memory pool is mpn, and the start address of memory pool is psn, the end address is pen, and the position of interior this memory pool of existence of first free sign of memory pool is freen;
2) function f of definition (n) number that decides memory block in n the memory pool, f (n) value equals 0 or less than 0, the number upper limit of size of then having represented application setting, size for the memory block of msize be front n-1 sub-distribution memory block number with;
3) when application program needed size to be the internal memory of msize, then from first memory pool of memory pool chained list, whether the freen that judges memory pool one by one was greater than f (n); If freen, represents that this memory pool has free memory to distribute, and returns this memory pool smaller or equal to f (n); If freen, represents that this memory pool does not have free memory to use, and judges next memory pool greater than f (n); If there is not next memory pool, and f (n)>0, a so newly-built memory pool that size is F (n), wherein F (n)=(msize+ zone bit size) * f (n); The all zone bits of initialization simultaneously are free, and initialization freen is 1, returns this memory pool then; If f (n)<=0, then notification application has reached the internal memory upper limit;
4) obtained after the operable memory pool of free memory, is the position of this memory pool that the internal memory of freen uses to application program, be the position that the sign of the internal memory of freen is made as used simultaneously, then from position freen+1, whether the sign of judging the internal memory of memory pool one by one is free, if before memory pool finishes, find the internal memory that is masked as free, then make the position at the internal memory place that is masked as free that the freen of this memory pool equals to find, if do not find the internal memory that is masked as free, then make the freen of this memory pool equal f (n)+1;
5) when application program release size is the internal memory of msize, then the sign of this internal memory is made as free, judge that simultaneously the position that has the place memory pool in this whether greater than the freen of place memory pool, if less than freen, then makes freen equal to exist in this position of place memory pool;
When 6) application program withdraws from, destroy all memory pools in the memory pool chained list.
The present invention compares with prior art, the useful effect that has is: quantity and the size of controlling memory pool with the alternative single memory pool of memory pool chained list, with function, thereby improved the customizability of whole application program internal memory, more efficient use internal memory and save memory, improve the travelling speed of application program, reduce the response time.
Description of drawings
Fig. 1 is the memory pool structural drawing;
Fig. 2 is the scantling plan of memory pool chained list;
Fig. 3 is the memory pool chained list that 1 newly-built memory pool is arranged;
Memory pool chained list behind Fig. 4 is an application assigned 1 block size is 32 the internal memory;
Fig. 5 is on Fig. 4 state, the application program continuous dispensing 5 block sizes be memory pool chained list behind 32 the internal memory;
Fig. 6 is on Fig. 5 state, and application program has discharged the memory pool chain table status behind the memory block that is arranged in the 2nd position of memory pool chained list memory pool mp1.
Embodiment
Below in conjunction with accompanying drawing, the situation that how solves frequently distributing and releasing equal size internal memory with the present invention is described with an embodiment.
The size of note frequently distributing and releasing equal size internal memory is msize, the pointer of memory pool chained list is plist, and n memory pool is mpn, and the start address of memory pool is psn, the end address is pen, and the position of interior this memory pool of existence of first free sign of memory pool is freen; Define a function f (n) number that decides memory block in n the memory pool, f (n) value equals 0 or less than 0, the number upper limit of size of then having represented application setting, size for the memory block of msize be front n-1 sub-distribution memory block number with, see illustrated in figures 1 and 2.
Step 1: adopt technical scheme 1) initialization frequently distributes the big or small msize=32 of the internal memory that discharges equal size, and the pointer of memory pool chained list is that plist is empty;
Step 2: adopt technical scheme 2) the initialization function f makes f (1)=5, f (2)=7, f (3)=0, the expression application setting memory size be to be limited to 5+7=12 on the number of 32 memory block;
Step 3: adopt technical scheme 3) obtain the memory pool mp1 of free memory, the sign of 5 memory blocks of memory pool mp1 all is free (writing a Chinese character in simplified form with F), the position free1=1 of first free memory block of memory pool.(seeing shown in Figure 3)
Step 4: after obtaining the memory pool of free memory block, adopt technical scheme 4) be the position that 1 memory block uses to application program, simultaneously the sign of the memory block of position 1 is made into used (writing a Chinese character in simplified form with U), the position free1=2 of first free memory block of memory pool mp1.(seeing shown in Figure 4)
Step 5: adopt technical scheme 3) and 4) 5 block sizes of reallocating are that 32 internal memory uses to application program, the position free1=6 of first free memory block of memory pool mp1 at this moment, the position free2=2 of first free memory block of memory pool mp2.(seeing shown in Figure 5)
Step 6: adopt technical scheme 5) position of releasing memory pond mp1 is 2 memory block, at this moment the sign of this memory block is changed into free, with the position free1=2 of first free memory block of seasonal memory pool mp1.
(seeing shown in Figure 6)
Step 7: adopt technical scheme 6) memory pool mp1 and the mp2 among the destruction memory pool chained list plist.At this moment, plist is empty.

Claims (1)

1 one kinds of methods that solve frequently distributing and releasing equal size internal memory is characterized in that:
1) size of note frequently distributing and releasing equal size internal memory is msize, the pointer of memory pool chained list is plist, and n memory pool is mpn, and the start address of memory pool is psn, the end address is pen, and the position of interior this memory pool of existence of first free sign of memory pool is freen;
2) function f of definition (n) number that decides memory block in n the memory pool, f (n) value equals 0 or less than 0, the number upper limit of size of then having represented application setting, size for the memory block of msize be front n-1 sub-distribution memory block number with;
3) when application program needed size to be the internal memory of msize, then from first memory pool of memory pool chained list, whether the freen that judges memory pool one by one was greater than f (n); If freen, represents that this memory pool has free memory to distribute, and returns this memory pool smaller or equal to f (n); If freen, represents that this memory pool does not have free memory to use, and judges next memory pool greater than f (n); If there is not next memory pool, and f (n)>0, a so newly-built memory pool that size is F (n), wherein F (n)=(msize+ zone bit size) * f (n); The all zone bits of initialization simultaneously are free, and initialization freen is 1, returns this memory pool then; If f (n)<=0, then notification application has reached the internal memory upper limit;
4) obtained after the operable memory pool of free memory, is the position of this memory pool that the internal memory of freen uses to application program, be the position that the sign of the internal memory of freen is made as used simultaneously, then from position freen+1, whether the sign of judging the internal memory of memory pool one by one is free, if before memory pool finishes, find the internal memory that is masked as free, then make the position at the internal memory place that is masked as free that the freen of this memory pool equals to find, if do not find the internal memory that is masked as free, then make the freen of this memory pool equal f (n)+1;
5) when application program release size is the internal memory of msize, then the sign of this internal memory is made as free, judge that simultaneously the position that has the place memory pool in this whether greater than the freen of place memory pool, if less than freen, then makes freen equal to exist in this position of place memory pool;
When 6) application program withdraws from, destroy all memory pools in the memory pool chained list.
CNB2005100607956A 2005-09-16 2005-09-16 Method for resolving frequently distributing and releasing equal size internal memory Expired - Fee Related CN1327348C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2005100607956A CN1327348C (en) 2005-09-16 2005-09-16 Method for resolving frequently distributing and releasing equal size internal memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2005100607956A CN1327348C (en) 2005-09-16 2005-09-16 Method for resolving frequently distributing and releasing equal size internal memory

Publications (2)

Publication Number Publication Date
CN1740975A CN1740975A (en) 2006-03-01
CN1327348C true CN1327348C (en) 2007-07-18

Family

ID=36093377

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2005100607956A Expired - Fee Related CN1327348C (en) 2005-09-16 2005-09-16 Method for resolving frequently distributing and releasing equal size internal memory

Country Status (1)

Country Link
CN (1) CN1327348C (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100530140C (en) * 2007-11-08 2009-08-19 Ut斯达康通讯有限公司 Memory management method for application program
CN101673246A (en) * 2009-08-06 2010-03-17 深圳市融创天下科技发展有限公司 High-efficient first-in first-out (FIFO) data pool reading and writing method
CN102253900B (en) * 2011-06-13 2013-06-12 华中师范大学 Memory optimization method under Windows CE operating system
US20160179668A1 (en) * 2014-05-28 2016-06-23 Mediatek Inc. Computing system with reduced data exchange overhead and related data exchange method thereof
WO2021087662A1 (en) * 2019-11-04 2021-05-14 深圳市欢太科技有限公司 Memory allocation method and apparatus, terminal, and computer readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6574718B2 (en) * 2001-02-28 2003-06-03 International Business Machines Corporation Excessive spin detection and avoidance for systems using a least recently used page replacement algorithm
CN1183453C (en) * 2001-12-21 2005-01-05 上海贝尔有限公司 Internal storage management system and its distribution method
CN1581064A (en) * 2003-08-13 2005-02-16 华为技术有限公司 Timer management method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6574718B2 (en) * 2001-02-28 2003-06-03 International Business Machines Corporation Excessive spin detection and avoidance for systems using a least recently used page replacement algorithm
CN1183453C (en) * 2001-12-21 2005-01-05 上海贝尔有限公司 Internal storage management system and its distribution method
CN1581064A (en) * 2003-08-13 2005-02-16 华为技术有限公司 Timer management method

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
具有服务仲裁机制的内存数据库管理器的研究与设计 宋广华,杨长生,石教英,计算机辅助设计与图形学学报,第14卷第3期 2002 *
具有服务仲裁机制的内存数据库管理器的研究与设计 宋广华,杨长生,石教英,计算机辅助设计与图形学学报,第14卷第3期 2002;有效实现内存管理的方法 潘立登,李婷,北京化工大学学报,第27卷第3期 2000 *
有效实现内存管理的方法 潘立登,李婷,北京化工大学学报,第27卷第3期 2000 *

Also Published As

Publication number Publication date
CN1740975A (en) 2006-03-01

Similar Documents

Publication Publication Date Title
US20200264980A1 (en) Apparatus and method of handling caching of persistent data
US10613762B2 (en) Memory allocation buffer for reduction of heap fragmentation
CN104899156A (en) Large-scale social network service-oriented graph data storage and query method
US7246195B2 (en) Data storage management for flash memory devices
US6505283B1 (en) Efficient memory allocator utilizing a dual free-list structure
US9436595B1 (en) Use of application data and garbage-collected data to improve write efficiency of a data storage device
CN100530140C (en) Memory management method for application program
US9805048B2 (en) System and method for managing a deduplication table
US6760826B2 (en) Store data in the system memory of a computing device
US7519639B2 (en) Method and apparatus for dynamic incremental defragmentation of memory
CN1327348C (en) Method for resolving frequently distributing and releasing equal size internal memory
US7380065B2 (en) Performance of a cache by detecting cache lines that have been reused
CN101847127B (en) Memory management method and device
US11042477B2 (en) Memory management using segregated free lists
US20150154216A1 (en) System and methods for prioritizing data in a cache
CN101859279A (en) Memory allocation and release method and device
CN101320351A (en) Internal memory distribution, cleaning and releasing method, and internal memory management apparatus
CN106681829A (en) Memory management method and system
KR20070015521A (en) Memory allocation
CN1289419A (en) Compression store free-space management
CN103455443A (en) Buffer management method and device
CN102819494B (en) Optimization method when a kind of flash memory is sequentially written in
CN109753361A (en) A kind of EMS memory management process, electronic equipment and storage device
CN110674052B (en) Memory management method, server and readable storage medium
CN102968380A (en) Method and device for managing memory partitions of memory filesystem

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20070718

Termination date: 20160916

CF01 Termination of patent right due to non-payment of annual fee