Summary of the invention
Technical matters to be solved by this invention is to provide a kind of method, Apparatus and system of the random memory based on the fixed memory sendout, frequently in the prior art produces the poor technical matters of extendability in memory fragmentation and the random memory process to solve.
For achieving the above object, the present invention is achieved through the following technical solutions,
A kind of memory allocation method comprises:
Request distributes at least two heap districts of presetting the fixed memory sendout;
Obtain the Memory Allocation request;
Judge whether the length of described Memory Allocation storage allocation that request is asked surpasses the maximal value of fixed memory sendout in the described heap district;
As no, then be hashing onto the heap district of mating with described Memory Allocation request according to described length and the equal difference coefficient that presets, from the heap district distribution internal memory of described coupling; In this way, then from operating system free memory allocation of space internal memory.
A kind of memory release method comprises:
Obtain the internal memory releasing request;
Judge whether the length of the required releasing memory of described internal memory releasing request surpasses the maximal value of the fixed memory sendout that presets in the described heap district,
As no, then obtain sequential labeling according to described length, obtain according to described sequential labeling and reclaim the chain list index, and memory block corresponding to described internal memory releasing request added to the last-of-chain of described recovery chain list index recovery chained list pointed; In this way, then from operating system free memory space releasing memory.
A kind of Memory Allocation device, described device comprise that presetting heap distinguishes module, the first request module, the first judge module, heap district distribution module and system assignment module;
The described heap district module that presets links to each other with described the first request module, is used for request and distributes at least two heap districts of presetting the fixed memory sendout;
Described the first request module links to each other with the first judge module with the described heap district module that presets, and is used for obtaining the Memory Allocation request;
Described the first judge module, distribute module to link to each other with the system assignment module with described the first request module, heap district, be used for judging whether the length of the required storage allocation of described Memory Allocation request surpasses the maximal value of described heap district fixed memory sendout, as no, then send the heap district and distribute instruction to distribute module to described heap district; In this way, then the transmitting system distribution instruction arrives described system assignment module;
Described heap district distributes module, link to each other with described the first judge module, be used for receiving the heap district distribution instruction that described the first judge module sends, and be hashing onto heap district with described Memory Allocation request coupling according to described length and the equal difference coefficient that presets, distribute internal memory from the heap district of described coupling;
Described system assignment module links to each other with described the first judge module, is used for receiving the system assignment instruction that described the first judge module sends, and from operating system free memory allocation of space internal memory.
A kind of internal memory releasing means, described device comprise the second request module, the second judge module, obtain the label module, upgrade chained list module and system's release module;
Described the second request module links to each other with described the second judge module, is used for obtaining the internal memory releasing request;
Described the second judge module, with described the second request module, obtain the label module and link to each other with the system release module, be used for judging described internal memory releasing request asks releasing memory length whether to surpass the maximal value of the fixed memory sendout that presets in described heap district, as no, then send and obtain the label instruction to the described label module of obtaining, in this way, the transmitting system described system release module that releases order then;
The described label module of obtaining, with described the second judge module with upgrade the chained list module and link to each other, what be used for receiving described the second judge module transmission obtains the label instruction, obtains sequential labeling according to described length;
Described renewal chained list module links to each other with the described label module of obtaining, and is used for obtaining recovery chain list index according to described sequential labeling, and memory block corresponding to described internal memory releasing request is added to the last-of-chain of described recovery chain list index recovery chained list pointed;
Described system release module links to each other with described the second judge module, releases order for the system that receives described the second judge module transmission, and releases order invoke memory release function from operating system free memory space releasing memory according to described system.
A kind of system of random memory, described system comprise Memory Allocation device and internal memory releasing means, and described Memory Allocation device comprises that presetting heap distinguishes module, the first request module, the first judge module, heap district distribution module and system assignment module; Described internal memory releasing means comprises the second request module, the second judge module, obtains the label module, upgrades chained list module and system's release module;
The described heap district module that presets links to each other with described the first request module, is used for request and distributes at least two heap districts of presetting the fixed memory sendout;
Described the first request module links to each other with the first judge module with the described heap district module that presets, and is used for obtaining the Memory Allocation request;
Described the first judge module, distribute module to link to each other with the system assignment module with described the first request module, heap district, be used for judging whether the length of the required storage allocation of described Memory Allocation request surpasses the maximal value of described heap district fixed memory sendout, as no, then send the heap district and distribute instruction to distribute module to described heap district; In this way, then the transmitting system distribution instruction arrives described system assignment module;
Described heap district distributes module, link to each other with described the first judge module, be used for receiving the heap district distribution instruction that described the first judge module sends, and be hashing onto heap district with described Memory Allocation request coupling according to described length and the equal difference coefficient that presets, distribute internal memory from the heap district of described coupling;
Described system assignment module links to each other with described the first judge module, is used for receiving the system assignment instruction that described the first judge module sends, and from operating system free memory allocation of space internal memory;
Described the second request module links to each other with described the second judge module, is used for obtaining the internal memory releasing request;
Described the second judge module, with described the second request module, obtain the label module and link to each other with the system release module, be used for judging whether the length of the required releasing memory of described internal memory releasing request surpasses the maximal value of the fixed memory sendout that presets in described heap district, as no, then send and obtain the label instruction to the described label module of obtaining, in this way, the transmitting system described system release module that releases order then;
The described label module of obtaining, with described the second judge module with upgrade the chained list module and link to each other, what be used for receiving described the second judge module transmission obtains the label instruction, obtains the sequential labeling in heap district according to described length;
Described renewal chained list module links to each other with the described label module of obtaining, and is used for obtaining recovery chain list index according to described sequential labeling, and memory block corresponding to described internal memory releasing request is added to the last-of-chain of described recovery chain list index recovery chained list pointed;
Described system release module links to each other with described the second judge module, releases order for the system that receives described the second judge module transmission, and releases order invoke memory release function from operating system free memory space releasing memory according to described system.
The present invention obtains the fixed memory sendout that meets arithmetic sequence by the equal difference coefficient that presets, then according to described fixed memory sendout each heap district is distributed sequential labeling, again according to its corresponding sequential labeling of Memory Allocation acquisition request, obtain the heap district according to described sequential labeling, at last come the storage allocation piece according to the fixed memory sendout in the described heap district, and from described memory block storage allocation.The present invention is based on the fixed memory sendout and can realize dynamic expansion to the heap district, when receiving the Memory Allocation request, can apply for fast the internal memory of appropriate length, reduced the quantity of memory fragmentation; Simultaneously, the internal memory that the list structure by directorial area has discharged in can priority allocation heap district has reduced time of search, has improved the utilization factor of memory headroom and the efficient of memory management.
Embodiment
The invention will be further described below in conjunction with drawings and Examples.
Embodiment one
Fig. 1 is the process flow diagram of the memory allocation method of the specific embodiment of the invention, and as shown in Figure 1, described method comprises step,
S101 to the heap district that the fixed memory sendout has been preset at least two of operating system requests, distributes sequential labeling for each heap district according to the incremental order of fixed memory sendout;
Described fixed memory sendout is arranged according to arithmetic sequence according to the equal difference coefficient that presets;
The fixed memory sendout that presets in the described heap district can arrange according to the equal difference coefficient that presets; Described equal difference coefficient refers to, if an ordered series of numbers from second, each equals same constant with its last difference, this constant just is called the equal difference coefficient; All heap districts that distributed distribute sequential labeling for each heap district according to the incremental order of fixed memory sendout; Described sequential labeling can represent the sequence number of incremental order for all, for example 1,2 ... or A, B Wherein, the number in described heap district is preferably 10~50;
Operating system is distributed a plurality of heaps district according to the fixed memory sendout that presets, when getting access to the Memory Allocation request, operating system is according to the length of described Memory Allocation storage allocation that request is asked fixed memory sendout storage allocation piece that preset according to described heap district in the heap district therein, and the internal memory block size that same heap district distributes when distributing internal memory is identical;
Storage allocation heap district is used to less than or equal to the peaked Memory Allocation request of the fixed memory sendout that presets and comes storage allocation, and the remaining memory headroom of operating system is used to greater than presetting fixed memory as a large integral body and distributes the peaked Memory Allocation request of value to come storage allocation;
Setting tool has the heap district number n=40 of predetermined memory space, 40 heap districts with predetermined memory space are made as Stack 1, Stack 2 ... Stack 40, the fixed memory sendout that preset in corresponding heap district is made as Stack m1 according to default equal difference coefficient, Stack m2 ... Stack m40, the fixed memory sendout equal difference coefficient k of each heap district maximum=512 bits, 40 heap districts carry out label according to incremental order, then described heap district maximum fixed memory sendout formation is 512,1024,1536,2048 ... 20480 bits;
Wherein, the internal memory block size that distributes from same heap district Stack i all be identical be its sendout Stack mi, the memory space in each heap district is variable, dynamic extending.
S102 obtains the Memory Allocation request;
Described Memory Allocation request comprises the length of asking storage allocation;
S103 judges whether the length of described Memory Allocation storage allocation that request is asked surpasses the maximal value of fixed memory sendout in each heap district; As no, then enter step S104, in this way, then enter step S106;
Whether the bit of namely judging current Memory Allocation request storage allocation that A asks surpasses default fixed allocation amount maximal value 20KB in the heap district;
S104 is hashing onto the heap district of mating with described Memory Allocation request according to described length and the equal difference coefficient that presets, is specially,
Thereby the length of described Memory Allocation storage allocation that request is asked is added sequential labeling equal difference coefficient gained and obtain again the heap district divided by described equal difference coefficient; Obtain heap district corresponding to described sequential labeling according to described sequential labeling;
In the present embodiment, obtain the sequential labeling corresponding with the heap district of described Memory Allocation request coupling according to following formula (1), make the previous heap of the Length Ratio district fixed memory sendout of the storage allocation that calls request large, and less than current heap district fixed memory sendout
i=(A+k)/k (1)
Wherein, i represents the sequential labeling in the heap district that is complementary with described Memory Allocation request; A represents the length of described Memory Allocation storage allocation that request is asked, and k represents the equal difference coefficient, and k is positive integer;
Be illustrated in figure 2 as heap district in the embodiment of the invention, concern synoptic diagram between memory block and pointer, as shown in Figure 2, operating system has been distributed a plurality of heap districts of presetting the fixed memory sendout, such as heap district 1, heap district 2 ... heap district N, described each heap district comprises directorial area and data field, described data field comprises memory block (also claiming memory pool), described memory block is distributed according to the length of Memory Allocation request by operating system, the length of described memory block is the internal memory of (X+Y) * N, wherein, the fixed memory sendout that preset in the heap district with Memory Allocation request coupling that X represents to be hashing onto, Y represents the length of internal memory head, and N represents the alignment figure place of memory address;
Described directorial area is list structure, comprises node and reclaims the chain list index, and described node is stored the address of releasing memory, when having discharged a plurality of internal memory, will create a plurality of nodes, form the single linked list structure of a plurality of nodes, wherein reclaim the first node of chained list pointed;
Described memory block can carry out repeatedly Memory Allocation according to the Memory Allocation request;
Be illustrated as an example of heap district 1 example, directorial area comprises recovery chain list index in the heap district 1, and the memory block of data field comprises start pointer, end pointer and current pointer; Wherein start pointer (MBEGIN) points to the starting point that is managed memory block, and end pointer (MEND) is pointed to the terminal point that is managed memory block, and current pointer (MCURRENT) points to the end of having used internal memory between start pointer and the end pointer; Reclaim the first node in chain list index (PFREELIST) the sensing list structure, each node has the pointer that points to last node of list structure, the pointed of last node itself, be convenient to after certain internal memory discharges, need not travel through whole list structure, and directly be linked into the last-of-chain of described list structure.When the process requested internal memory initialization, the PFREELIST pointer is NULL, MCURRENT pointed MBEGIN pointer;
When not having node in the list structure, the PFREELIST pointer also is NULL;
S105, the heap district distribution internal memory from described coupling is specially,
S1051 judges whether the recovery chain list index corresponding to heap district of described coupling is empty, as no, then enters step S1052, in this way, then enters step S1053;
S1052, according to the internal memory of the address assignment fixed memory sendout in the first node, and with the next node of described recovery chained list pointed list structure;
S1053, storage allocation from the memory block remaining space that current pointer points to, namely storage allocation in the current memory block remaining space from described heap district comprises step,
S10531 judges that described memory block remaining space whether greater than " fixed memory sendout and internal memory head and ", in this way, then enters step S10532, as no, then enters step S10533;
Judge that namely whether described heap district remaining space is greater than X+Y;
S10532, stored memory head Y also distributes the internal memory that meets fixed memory sendout X, upgrades current pointer;
S10533, memory block from the unallocated memory headroom application of operating system " (fixed memory sendout with internal memory head and) multiply by the figure place of aliging of memory address " length, upgrade simultaneously start pointer, end pointer and current pointer, and from described memory block storage allocation;
Namely from the memory block of the unallocated memory headroom application of operating system (X+Y) * N length, upgrade simultaneously start pointer, end pointer and current pointer, and from described memory block storage allocation;
Wherein, the fixed memory sendout that preset in the heap district with Memory Allocation request coupling that X represents to be hashing onto, Y represents the length of internal memory head, the length of described internal memory head is 4 bytes, described internal memory head has been stored the length X (being the fixed memory sendout) of internal memory main body, and N represents the alignment figure place of memory address;
S106 is from operating system free memory allocation of space internal memory.
The internal memory that distributes in memory block comprises internal memory head and internal memory main body, and described internal memory head has been stored the length X (being the fixed memory sendout) of internal memory main body, and described internal memory main body is used for depositing the required data that write of described Memory Allocation request.
For ease of understanding, illustrate, as shown in Figure 2, when a Memory Allocation request arrives, judge whether the length of the required storage allocation of described Memory Allocation request surpasses the maximal value of the fixed memory sendout that presets in each heap district, in this way, then from operating system remaining space storage allocation piece; As no, then be hashing onto the heap district of mating with described Memory Allocation request according to described request storage allocation length and the equal difference coefficient that presets, then the heap district from described coupling distributes internal memory.
Wherein, when distributing internal memory from the heap district of described coupling, when initial, it be empty reclaiming the chain list index, and reclaiming chain list index (PFREELIST) be sky (NULL) when initial, then storage allocation from the memory block remaining space of current pointer sensing.When releasing memory, then the address in institute's releasing memory is appended and be a node in the list structure, reclaim the chain list index and always point to first node, address in first node is assigned with again, reclaim again the chain list index and just point to next node, described next node has just become first node, and when not having next node, the value that reclaims the chain list index is NULL just;
The renewal process of pointer is identical with prior art in the same area, repeats no more herein.
The Memory Allocation program need to be followed some basic Memory Allocation rules.For example, N represents the alignment figure place of memory address.All Memory Allocation must originate in can be by 4,8 or 16 addresses of dividing exactly (deciding on processor architecture).So, during from the physical memory of the unallocated memory headroom application of operating system (X+Y) * N, can select according to actual conditions the size of application physical memory.
The heap district 2 of fixed memory sendout is preset in setting, generates the memory block in described heap district according to (X+Y) * N, according to fixed memory sendout storage allocation from memory block.
In the present embodiment, all Memory Allocation addresses must originate in and can be divided exactly by 4, all can be divided exactly by 4 through result after the above computing;
Fig. 3 is the structural representation of the Memory Allocation device of the specific embodiment of the invention, and as shown in Figure 3, described device comprises that presetting heap distinguishes module, the first request module, the first judge module, heap district distribution module and system assignment module;
The described heap district module that presets links to each other with described the first request module, is used for request and distributes at least two heap districts of presetting the fixed memory sendout;
Described the first request module links to each other with the first judge module with the described heap district module that presets, and is used for obtaining the Memory Allocation request;
Described the first judge module, distribute module to link to each other with the system assignment module with described the first request module, heap district, be used for judging whether the length of described Memory Allocation storage allocation that request is asked surpasses the maximal value of described heap district fixed memory sendout, as no, then send the heap district and distribute instruction to distribute module to described heap district; In this way, then the transmitting system distribution instruction arrives described system assignment module;
Described heap district distributes module, link to each other with described the first judge module, be used for receiving the heap district distribution instruction that described the first judge module sends, and utilize hash algorithm to be hashing onto the heap district of mating with described Memory Allocation request, from the heap district distribution internal memory of described coupling;
Described system assignment module links to each other with described the first judge module, is used for receiving the system assignment instruction that described the first judge module sends, and from operating system free memory allocation of space internal memory;
Described memory device also comprises the label module; Described label module links to each other with the first request module with the described heap district module that presets, and the fixed memory sendout that is used for presetting according to the heap district is distributed sequential labeling according to incremental order to each heap district;
Wherein, described heap district distributes module to comprise to obtain the label unit, obtains heap unit, district and storage allocation unit; The described label unit that obtains links to each other with the described unit, heap district that obtains, thereby is used for the length of the required storage allocation of described Memory Allocation request is added sequential labeling equal difference coefficient gained and obtain again the heap district divided by described equal difference coefficient;
The described unit, heap district that obtains links to each other with the storage allocation unit with the described label unit that obtains, and is used for obtaining heap district corresponding to described sequential labeling according to described sequential labeling;
Described storage allocation unit links to each other with the described unit, heap district that obtains, and is used for from heap district distribution internal memory.
Described storage allocation unit comprises that the first judging unit, the first allocation units, the first updating block, the second judging unit, the second allocation units, the second updating block, memory block unit, the 3rd upgrade unit and the 3rd allocation units;
Described the first judging unit links to each other with the second judging unit with described the first allocation units, is used for judging whether the recovery chain list index corresponding to heap district of described coupling is empty, as no, then sends the first distribution instruction to described the first allocation units; In this way, then send the second decision instruction to described the second judging unit;
Described the first allocation units, link to each other with the first updating block with described the first judging unit, be used for receiving the first distribution instruction that described the first judging unit sends, and according to the internal memory of the address assignment fixed memory sendout in the first node that reclaims the chained list pointed, also be used for sending the first update instruction to described the first updating block;
Described the first updating block links to each other with described the first allocation units, is used for receiving the first update instruction that described the first allocation units send, and with the next node of described recovery chained list pointed list structure;
Described the second judging unit, link to each other with described the first judging unit, the second allocation units and memory block unit, be used for receiving the second decision instruction that described the first judging unit sends, and judge that described memory block remaining space is whether greater than " fixed memory sendout and internal memory head and ", in this way, then send the second distribution instruction to described the second allocation units; As no, then send the storage allocation block instruction to described memory block unit;
Described the second allocation units link to each other with the second updating block with described the second judging unit, are used for receiving the second distribution instruction that described the second judging unit sends, and the stored memory head, distribute simultaneously the internal memory that meets the fixed memory sendout;
Described the second updating block links to each other with described the second allocation units, is used for upgrading current pointer;
Described memory block unit, upgrading the unit with described the second judging unit and the 3rd links to each other, be used for receiving the storage allocation block instruction that described the second judging unit sends, and from the memory block of the unallocated memory headroom application of operating system " figure place of aliging fixed memory sendout and internal memory head and that take advantage of again memory address " length, then send the 3rd and upgrade instruction to described the 3rd renewal unit, send simultaneously the 3rd distribution instruction to described the 3rd allocation units;
The described the 3rd upgrades the unit, links to each other with the 3rd allocation units with described memory block unit, is used for receiving the 3rd renewal instruction that described memory block unit sends, and upgrades start pointer, end pointer and current pointer;
Described the 3rd allocation units upgrade the unit and link to each other with the described the 3rd, are used for receiving the 3rd distribution instruction of described memory block unit transmission, according to described the 3rd distribution instruction from described memory block storage allocation;
Present embodiment obtains the fixed memory sendout that meets arithmetic sequence by the equal difference coefficient that presets, then according to described fixed memory sendout each heap district is distributed sequential labeling, again according to its corresponding sequential labeling of Memory Allocation acquisition request, obtain the heap district according to described sequential labeling, at last come the storage allocation piece according to the fixed memory sendout in the described heap district, and from described memory block storage allocation.The present invention is based on the fixed memory sendout and can realize dynamic expansion to the heap district, when receiving the Memory Allocation request, application has reduced the quantity of memory fragmentation to the internal memory of appropriate length fast; Simultaneously, the internal memory that the list structure by directorial area has discharged in can priority allocation heap district has reduced time of search, has improved the utilization factor of memory headroom and the efficient of memory management.
Embodiment two
Fig. 4 is the process flow diagram of the memory release method of the specific embodiment of the invention.As shown in Figure 4, described method comprises step:
S401 obtains the internal memory releasing request;
S402 judges whether the required releasing memory length of described internal memory releasing request surpasses the maximal value of the fixed memory sendout that presets in described heap district, as no, then enters step S403, in this way, then enters step S405;
S403 obtains sequential labeling according to described length;
Described sequential labeling calculates according to following formula (1), makes the previous heap of the Length Ratio district fixed memory sendout of the releasing memory that calls request large, and less than current heap district fixed memory sendout,
i=(A+k)/k (1)
Wherein, i represents the sequential labeling in the heap district of mating with described internal memory releasing request; A represents to treat the length of releasing memory, and k represents the equal difference coefficient, and k is positive integer;
S404 obtains recovery chain list index according to described sequential labeling, and memory block corresponding to described internal memory releasing request is added to the last-of-chain of described recovery chain list index recovery chained list pointed;
S405 is from operating system free memory space releasing memory.
During from operating system free memory space releasing memory, generally discharge function from operating system free memory space releasing memory by invoke memory.
Described internal memory releasing request comprises the length that discharges address and releasing memory;
According to the release address in the described internal memory releasing request, the length from the directorial area of current releasing memory discharges described internal memory.
Fig. 5 is the structural representation of the internal memory releasing means of the specific embodiment of the invention.As shown in Figure 5, described device comprises the second request module, the second judge module, obtains the label module, upgrades chained list module and system's release module;
Described the second request module links to each other with described the second judge module, is used for obtaining the internal memory releasing request;
Described the second judge module, with described the second request module, obtain the label module and link to each other with the system release module, be used for judging described internal memory releasing request asks releasing memory length whether to surpass the maximal value of the fixed memory sendout that presets in described heap district, as no, then send and obtain the label instruction to the described label module of obtaining, in this way, the transmitting system described system release module that releases order then;
The described label module of obtaining, with described the second judge module with upgrade the chained list module and link to each other, what be used for receiving described the second judge module transmission obtains the label instruction, obtains the sequential labeling in heap district according to described request releasing memory length;
Described renewal chained list module links to each other with the described label module of obtaining, and is used for obtaining recovery chain list index according to described sequential labeling, and memory block corresponding to described internal memory releasing request is added to the last-of-chain of described recovery chain list index recovery chained list pointed;
Described system release module links to each other with described the second judge module, releases order for the system that receives described the second judge module transmission, and releases order invoke memory release function from operating system free memory space releasing memory according to described system;
Present embodiment obtains by equal difference coefficient, fixed memory sendout and sequential labeling and reclaims the chain list index, and the memory block that the internal memory releasing request is corresponding adds the last-of-chain of described recovery chain list index recovery chained list pointed to.After certain internal memory discharges, need not travel through whole list structure, and directly add the last-of-chain of described list structure to, reduced the time that traversal reclaims chained list.And guaranteed that the releasing memory piece is divided timing again, and need not to carry out the length coupling, reduced the time of search, improved the efficient of internal memory release efficiency and memory management.
Embodiment three
Described system comprises Memory Allocation device and internal memory releasing means; Described Memory Allocation device links to each other with the internal memory releasing means;
Described Memory Allocation device comprises that presetting heap distinguishes module, the first request module, the first judge module, heap district distribution module and system assignment module;
The described heap district module that presets links to each other with described the first request module, is used for request and distributes at least two heap districts of presetting the fixed memory sendout;
Described the first request module links to each other with the first judge module with the described heap district module that presets, and is used for obtaining the Memory Allocation request;
Described the first judge module, distribute module to link to each other with the system assignment module with described the first request module, heap district, be used for judging whether the length of described Memory Allocation storage allocation that request is asked surpasses the maximal value of described heap district fixed memory sendout, as no, then send the heap district and distribute instruction to distribute module to described heap district; In this way, then the transmitting system distribution instruction arrives described system assignment module;
Described heap district distributes module, link to each other with described the first judge module, be used for receiving the heap district distribution instruction that described the first judge module sends, and utilize hash algorithm to be hashing onto the heap district of mating with described Memory Allocation request, from the heap district distribution internal memory of described coupling;
Described system assignment module links to each other with described the first judge module, is used for receiving the system assignment instruction that described the first judge module sends, and from operating system free memory allocation of space internal memory;
Described internal memory releasing means comprises the second request module, the second judge module, obtains the label module, upgrades chained list module and system's release module;
Described the second request module links to each other with described the second judge module, is used for obtaining the internal memory releasing request;
Described the second judge module, with described the second request module, obtain the label module and link to each other with the system release module, be used for judging described internal memory releasing request asks releasing memory length whether to surpass the maximal value of the fixed memory sendout that presets in described heap district, as no, then send and obtain the label instruction to the described label module of obtaining, in this way, the transmitting system described system release module that releases order then;
The described label module of obtaining, with described the second judge module with upgrade the chained list module and link to each other, what be used for receiving described the second judge module transmission obtains the label instruction, obtains the sequential labeling in heap district according to described request releasing memory length;
Described renewal chained list module links to each other with the described label module of obtaining, and is used for obtaining recovery chain list index according to described sequential labeling, and memory block corresponding to described internal memory releasing request is added to the last-of-chain of described recovery chain list index recovery chained list pointed;
Described system release module links to each other with described the second judge module, releases order for the system that receives described the second judge module transmission, and releases order invoke memory release function from operating system free memory space releasing memory according to described system.
In the present embodiment, the Memory Allocation device obtains the fixed memory sendout that meets arithmetic sequence by the equal difference coefficient that presets, then according to described fixed memory sendout each heap district is distributed sequential labeling, again according to its corresponding sequential labeling of Memory Allocation acquisition request, obtain the heap district according to described sequential labeling, at last come the storage allocation piece according to the fixed memory sendout in the described heap district, and from described memory block storage allocation.The Memory Allocation device can be realized dynamic expansion to the heap district based on the fixed memory sendout, and when receiving the Memory Allocation request, application has reduced the quantity of memory fragmentation to the internal memory of appropriate length fast; Simultaneously, the internal memory that the list structure by directorial area has discharged in can priority allocation heap district has reduced time of search, has improved the utilization factor of memory headroom and the efficient of memory management.In addition, the internal memory releasing means obtains by equal difference coefficient, fixed memory sendout and sequential labeling and reclaims the chain list index, and the memory block that the internal memory releasing request is corresponding adds the last-of-chain of described recovery chain list index recovery chained list pointed to.The internal memory releasing means need not travel through whole list structure after getting access to the internal memory releasing request, and the address of the memory block that directly needs is discharged is added the last-of-chain of list structure to, has reduced the time that traversal reclaims chained list.And guaranteed that the releasing memory piece is divided timing again, and need not to carry out the length coupling, reduced the time of search, improved the efficient of internal memory release efficiency and memory management.
The renewal process of pointer of the present invention, Hash procedure are identical with prior art in the same area, repeat no more herein.
Random memory provided by the invention system need can be applied on the terminal device of random memory such as PC, PDA, mobile phone, server etc.
Those having ordinary skill in the art will appreciate that, all or part of step in realization above-described embodiment method can be finished by the programmed instruction related hardware, described program can be stored in the computer read/write memory medium, and described storage medium can be ROM, RAM, disk, CD etc.
Above-mentioned only is preferred embodiment of the present invention and institute's application technology principle, anyly is familiar with those skilled in the art in the technical scope that the present invention discloses, and the variation that can expect easily or replacement all should be encompassed in protection scope of the present invention.