Invention content
The embodiment of the present invention is designed to provide a kind of memory headroom management method and system, is reduced in distribution with realizing
The purpose of counterfoil frequency.
In order to achieve the above objectives, the embodiment of the invention discloses a kind of memory headroom management methods, including:
Determine the memory headroom size needed for function variable;
The idle section that space size is more than the required memory headroom is searched in memory outside recycling stack, if looked into
It finds, then the function variable is distributed into the first part space in the idle section of the space minimum in lookup result,
In, the size in the first part space is identical as the size of the memory headroom needed for the function variable.
Preferably, the letter is being distributed into the first part space in the idle section of the space minimum in lookup result
After number variable, further include:
By the remaining space label in the idle section of the space minimum in lookup result in addition to the first part space
For idle section.
Preferably, further include:
The memory headroom of function variable release is labeled as idle section;
An idle section is merged into continuously arranged multiple idle sections.
Preferably, further include:
Memory block in idle section is put into recycling stack and is recycled.
Preferably, further include:
Judge recycle stack in memory block quantity whether be more than predetermined threshold value, if it is, not recycling memory block until
The quantity for recycling memory block in stack is not more than predetermined threshold value, and the predetermined threshold value is natural number.
Preferably, the free time that space size is more than the required memory headroom is not found in the memory outside recycling stack
When section, the method further includes:
The quantity X for the memory block that need to be function variable distribution is determined according to following formula:
X*A>Y>(X-1)*A
Wherein, A is the size of memory block, and Y is the memory headroom size needed for the function variable;
X memory block is obtained from recycling stack and distributes to the function variable.
A kind of memory headroom management system, including:Space determination unit, range lookup unit and section allocation unit,
The space determination unit, for determining the memory headroom size needed for function variable;
The range lookup unit is more than the required memory for searching space size in the memory outside recycling stack
The section allocation unit is triggered if found in the idle section in space;
The section allocation unit, the free area of the space minimum in result for searching the range lookup unit
Between in first part space distribute to the function variable, wherein the size in the first part space becomes with the function
The size of memory headroom needed for amount is identical.
Preferably, further include:First interval marking unit, in the section allocation unit by the range lookup list
It, will be described after the function variable is distributed in first part space in the idle section of space minimum in the result that member is searched
Remaining space in the idle section of space minimum in the result that range lookup unit is searched in addition to the first part space
Labeled as idle section.
Preferably, further include:Second interval marking unit and section combining unit,
The second interval marking unit, the memory headroom for discharging function variable are labeled as idle section;
The section combining unit, for an idle section to be merged into continuously arranged multiple idle sections.
Preferably, further include:Memory recycle unit is returned for the memory block in idle section to be put into recycling stack
It receives.
Preferably, further include:Memory block quantity control unit, for judging whether the quantity for recycling memory block in stack is more than
Predetermined threshold value, if it is, recycling memory block is not until the quantity of memory block is described pre- no more than predetermined threshold value in recycling stack
If threshold value is natural number.
Preferably, further include:Memory block allocation unit is used in the memory in the range lookup unit outside recycling stack
Need to be the letter according to the determination of following formula when not finding idle section of the space size more than the required memory headroom
The quantity X of the memory block of number variable distribution:
X*A>Y>(X-1)*A
Wherein, A is the size of memory block, and Y is the memory headroom size needed for the function variable;
The memory block allocation unit is additionally operable to obtain X memory block from recycling stack and distributes to the function variable.
A kind of memory headroom management method and system provided in an embodiment of the present invention, can will recycling stack outside memory in
Function variable is distributed in the idle section found, there is no need to obtain memory block from recycling stack again, reduces storage allocation
The frequency of block.Simultaneously as the idle section that the present invention distributes is the part not used by other function variables in memory block, because
This present invention can also effectively improve the service efficiency of memory headroom.Since the present invention is by the memory headroom needed for and function variable
The identical part of size distribute to the function variable, therefore idle section not can be used as still by the part that function variable uses and supply
Other function variables use.Moreover, function variable is distributed in the idle section of most suitable function variable by the present invention, further carry
The high service efficiency of memory.
Specific implementation mode
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation describes, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other
Embodiment shall fall within the protection scope of the present invention.
As shown in Figure 1, a kind of memory headroom management method provided in an embodiment of the present invention, may include:
S100, memory headroom size needed for function variable is determined;
The idle section that space size is more than the required memory headroom is searched in S200, the memory outside recycling stack;
Recycling stack resides at conventional RAM (random access storage device) region, and function can pass through " stack pointer " of recycling stack
Obtain the direct support of processing.If stack pointer can create new memory block to moving down;If, can releasing memory block to moving up.
Since recycling stack carries out Memory Allocation and recycling according to the memory block of fixed size, recycle in the memory outside stack
Certainly exist the memory block not occupied completely by function variable.The part not occupied at this time by function variable in memory block is should
The idle section of memory block can continue to be used by other function variables.Certainly, it to ensure the normal operation of function, distributes to
The size in the idle section of function variable is no less than the size of the memory headroom needed for the function variable.
S300, judge whether to find the idle section that space size is more than the required memory headroom, if it is,
Execute S400;Otherwise, S400 ' is executed;
S400 ', from recycling stack in storage allocation block to function variable.
Specifically, the quantity X for the memory block that need to be function variable distribution can be determined according to following formula:
X*A>Y>(X-1)*A
Wherein, A is the size of memory block, and Y is the memory headroom size needed for the function variable;
X memory block is obtained from recycling stack and distributes to the function variable.
Pass through above-mentioned memory block distribution method, so that it may to distribute enough and minimum memory blocks for function variable, meet
Under the premise of function variable demand, memory block service efficiency is optimized.
S400, the function change is distributed into the first part space in the idle section of the space minimum in lookup result
Amount, wherein the size in the first part space is identical as the size of the memory headroom needed for the function variable.
Optionally, it in another memory headroom management method provided in an embodiment of the present invention, after S400, can also wrap
It includes:
Remaining space in the idle section of space minimum in addition to the first part space is labeled as idle section.
In order to improve the service efficiency of memory, can be allocated according to the size in memory block free time section, most by size
It is suitble to the idle section of memory headroom needed for function variable to distribute to the function variable.Such as:There are three idle in lookup result
Section, size are 10KB, 15KB and 20KB respectively, and the size of the memory headroom needed for number variable is 7KB, due to these three free time
The size in section is all higher than the size of the memory headroom needed for function variable, therefore can distribute the idle section of 10KB sizes
Give the function variable.If the function variable is distributed in other two free time section, it will cause the idle sections distributed
Utilization rate reduce.Meanwhile the 7KB in 10KB is only distributed to function variable by S400, therefore remaining 3KB still can be used as the free time
Section is used for other function variables.
A kind of memory headroom management method provided in an embodiment of the present invention can will be found in the memory outside recycling stack
Idle section distribute to function variable, there is no need to again from recycling stack in obtain memory block, reduce recycling stack storage allocation
The frequency of block.Simultaneously as the idle section that the present invention distributes is the part not used by other function variables in memory block, because
This present invention can also effectively improve the service efficiency of memory headroom.Since the present invention is by the memory headroom needed for and function variable
The identical part of size distribute to the function variable, therefore idle section not can be used as still by the part that function variable uses and supply
Other function variables use.Moreover, function variable is distributed in the idle section of most suitable function variable by the present invention, further carry
The high service efficiency of memory.
As shown in Fig. 2, in another kind memory headroom management method provided in an embodiment of the present invention, can also include:
S500, the memory headroom of function variable release is labeled as idle section;
At function variable no longer committed memory space, which then becomes idle state.
S600, an idle section is merged into continuously arranged multiple idle sections.
In another kind memory headroom management method provided in an embodiment of the present invention, after S600, can also include:
Memory block in idle section is put into recycling stack and is recycled.
Wherein, the execution sequence present invention of S500, S600 and S100 to S400 do not limit.
Multiple idle sections, which are merged into behind a big idle section, can make in the idle section after merging
Counterfoil is recycled.Since memory block can be occupied by multiple function variables simultaneously in the present invention, work as above-mentioned multiple functions
When partial function variable in variable no longer occupies the memory block, since remainder function variable still occupies the memory block, because
This memory block can not still recycle.Embodiment illustrated in fig. 2 is by merging continuously arranged idle section, so that it may so that complete
The various pieces of whole memory block are merged into an idle section during idle time, to recycle entire memory block.
As shown in figure 3, in another kind memory headroom management method provided in an embodiment of the present invention, can also include:
S700, judge whether the quantity for recycling memory block in stack is more than predetermined threshold value, if it is, not recycling memory block
Until the quantity of memory block is not more than predetermined threshold value in recycling stack, otherwise continue to recycle memory block, the predetermined threshold value is nature
Number.
Wherein, predetermined threshold value can be 3 etc..
The execution sequence present invention of S700 and S100 to S400 does not limit.S700 can be with embodiment base shown in Fig. 2
It is executed on plinth, the execution sequence present invention of S700 and S500, S600 do not limit.
Memory block in recycling stack is in state to be allocated, if the quantity of memory block is too many in recycling stack, will cause back
Receive stack management it is complex, simultaneously as recycling stack in memory block quantity there is no limit, will cause frequently to carry out memory block
Recycling.The quantity that embodiment illustrated in fig. 3 recycles memory block in stack by control can effectively reduce the management difficulty for recycling stack, and
Memory block recycling need not frequently be carried out.
Corresponding with above method embodiment, the present invention also provides a kind of memory headrooms to manage system.
As shown in figure 4, a kind of memory headroom provided in an embodiment of the present invention manages system, may include:Space determines single
Member 100, range lookup unit 200 and section allocation unit 300,
The space determination unit 100, for determining the memory headroom size needed for function variable;
The range lookup unit 200, for searching space size more than described required in the memory outside recycling stack
The section allocation unit 300 is triggered if found in the idle section of memory headroom;
Recycling stack resides at conventional RAM (random access storage device) region, and function can pass through " stack pointer " of recycling stack
Obtain the direct support of processing.If stack pointer can create new memory block to moving down;If, can releasing memory block to moving up.
Since recycling stack carries out Memory Allocation and recycling according to the memory block of fixed size, recycle in the memory outside stack
Certainly exist the memory block not occupied completely by function variable.The part not occupied at this time by function variable in memory block is should
The idle section of memory block can continue to be used by other function variables.Certainly, it to ensure the normal operation of function, distributes to
The size in the idle section of function variable is no less than the size of the memory headroom needed for the function variable.
Optionally, system shown in Figure 4 can also include:Memory block allocation unit, in the range lookup unit 200
When not finding idle section of the space size more than the required memory headroom in recycling the memory outside stack, according to as follows
Formula determines the quantity X for the memory block that need to be function variable distribution:
X*A>Y>(X-1)*A
Wherein, A is the size of memory block, and Y is the memory headroom size needed for the function variable;
The memory block allocation unit is additionally operable to obtain X memory block from recycling stack and distributes to the function variable.
Pass through above-mentioned memory block allocation unit, so that it may to distribute enough and minimum memory blocks for function variable, meet
Under the premise of function variable demand, memory block service efficiency is optimized.
The section allocation unit 300, space in the result for searching the range lookup unit 200 are minimum
Distribute to the function variable in first part space in idle section, wherein the size in the first part space with it is described
The size of memory headroom needed for function variable is identical.
Optionally, in another memory headroom management system provided in an embodiment of the present invention, can also include:Firstth area
Between marking unit, most for the space in the result that the section allocation unit 300 searches the range lookup unit 200
After the function variable is distributed in first part space in small idle section, the range lookup unit 200 is searched
As a result the remaining space in the idle section of the space minimum in addition to the first part space is labeled as idle section.
In order to improve the service efficiency of memory, can be allocated according to the size in memory block free time section, most by size
It is suitble to the idle section of memory headroom needed for function variable to distribute to the function variable.Such as:There are three idle in lookup result
Section, size are 10KB, 15KB and 20KB respectively, and the size of the memory headroom needed for number variable is 7KB, due to these three free time
The size in section is all higher than the size of the memory headroom needed for function variable, therefore can distribute the idle section of 10KB sizes
Give the function variable.If the function variable is distributed in other two free time section, it will cause the idle sections distributed
Utilization rate reduce.Meanwhile the 7KB in 10KB is only distributed to function variable, therefore remaining 3KB by section allocation unit 300
Idle section is still can be used as to use for other function variables.
Optionally, a kind of memory headroom management system provided in an embodiment of the present invention can be Memory Controller Hub.
A kind of memory headroom provided in an embodiment of the present invention manages system, can will be found in the memory outside recycling stack
Idle section distribute to function variable, there is no need to again from recycling stack in obtain memory block, reduce recycling stack storage allocation
The frequency of block.Simultaneously as the idle section that the present invention distributes is the part not used by other function variables in memory block, because
This present invention can also effectively improve the service efficiency of memory headroom.Since the present invention is by the memory headroom needed for and function variable
The identical part of size distribute to the function variable, therefore idle section not can be used as still by the part that function variable uses and supply
Other function variables use.Moreover, function variable is distributed in the idle section of most suitable function variable by the present invention, further carry
The high service efficiency of memory.
As shown in figure 5, in another kind memory headroom management system provided in an embodiment of the present invention, can also include:Second
Interval mark unit 400 and section combining unit 500,
The second interval marking unit 400, the memory headroom for discharging function variable are labeled as idle section;
At function variable no longer committed memory space, which then becomes idle state.
The section combining unit 500, for an idle section to be merged into continuously arranged multiple idle sections.
In another kind memory headroom management system provided in an embodiment of the present invention, can also include:Memory recycle unit is used
It is recycled in being put into the memory block in idle section in recycling stack.
Multiple idle sections, which are merged into behind a big idle section, can make in the idle section after merging
Counterfoil is recycled.Since memory block can be occupied by multiple function variables simultaneously in the present invention, work as above-mentioned multiple functions
When partial function variable in variable no longer occupies the memory block, since remainder function variable still occupies the memory block, because
This memory block can not still recycle.Embodiment illustrated in fig. 5 is by merging continuously arranged idle section, so that it may so that complete
The various pieces of whole memory block are merged into an idle section during idle time, to recycle entire memory block.
As shown in fig. 6, in another kind memory headroom management system provided in an embodiment of the present invention, can also include:
Memory block quantity control unit 600, for judging whether the quantity for recycling memory block in stack is more than predetermined threshold value, such as
Fruit is that then for recycling memory block until the quantity of memory block is not more than predetermined threshold value in recycling stack, the predetermined threshold value is not certainly
So number.
Wherein, predetermined threshold value can be 3 etc..
Memory block quantity control unit 600 can also add in system shown in Fig. 5.
Memory block in recycling stack is in state to be allocated, if the quantity of memory block is too many in recycling stack, will cause back
Receive stack management it is complex, simultaneously as recycling stack in memory block quantity there is no limit, will cause frequently to carry out memory block
Recycling.The quantity that embodiment illustrated in fig. 6 recycles memory block in stack by control can effectively reduce the management difficulty for recycling stack, and
Memory block recycling need not frequently be carried out.
It should be noted that herein, relational terms such as first and second and the like are used merely to a reality
Body or operation are distinguished with another entity or operation, are deposited without necessarily requiring or implying between these entities or operation
In any actual relationship or order or sequence.Moreover, the terms "include", "comprise" or its any other variant are intended to
Non-exclusive inclusion, so that the process, method, article or equipment including a series of elements is not only wanted including those
Element, but also include other elements that are not explicitly listed, or further include for this process, method, article or equipment
Intrinsic element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that
There is also other identical elements in process, method, article or equipment including the element.
Each embodiment in this specification is all made of relevant mode and describes, identical similar portion between each embodiment
Point just to refer each other, and each embodiment focuses on the differences from other embodiments.Especially for system reality
For applying example, since it is substantially similar to the method embodiment, so description is fairly simple, related place is referring to embodiment of the method
Part explanation.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the scope of the present invention.It is all
Any modification, equivalent replacement, improvement and so within the spirit and principles in the present invention, are all contained in protection scope of the present invention
It is interior.