CN105302733B - A kind of method and device of Memory Allocation - Google Patents

A kind of method and device of Memory Allocation Download PDF

Info

Publication number
CN105302733B
CN105302733B CN201410314664.5A CN201410314664A CN105302733B CN 105302733 B CN105302733 B CN 105302733B CN 201410314664 A CN201410314664 A CN 201410314664A CN 105302733 B CN105302733 B CN 105302733B
Authority
CN
China
Prior art keywords
memory block
memory
demand
block
another
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
CN201410314664.5A
Other languages
Chinese (zh)
Other versions
CN105302733A (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.)
Shenzhen Tencent Computer Systems Co Ltd
Original Assignee
Shenzhen Tencent Computer Systems Co 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 Shenzhen Tencent Computer Systems Co Ltd filed Critical Shenzhen Tencent Computer Systems Co Ltd
Priority to CN201410314664.5A priority Critical patent/CN105302733B/en
Publication of CN105302733A publication Critical patent/CN105302733A/en
Application granted granted Critical
Publication of CN105302733B publication Critical patent/CN105302733B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a kind of methods of Memory Allocation, comprising: obtains first memory block from total memory, includes the second memory block of multiple and different sizes in one first memory block;According to business to the demand of memory, second memory block for meeting the demand is determined from one first memory block, alternatively, obtaining another first memory block for meeting the demand from total memory;By one second memory block or another described first memory block, the business is distributed to.The method of Memory Allocation provided in an embodiment of the present invention, it can apply for suitable second memory block from first memory block of total memory, in this way according to business to the demand of memory, the parallel distribution that can realize memory, can be improved Memory Allocation efficiency and memory usage.

Description

A kind of method and device of Memory Allocation
Technical field
The present invention relates to field of computer technology, and in particular to a kind of method and device of Memory Allocation.
Background technique
Memory in operating system is directly allocated from operating system when in use, is not deposited internally and is managed substantially, Some will do it simple management, but be only limited to serially distribute, i.e., the same time can only give a request storage allocation.
Memory Allocation in the prior art, Memory Allocation low efficiency, and also the utilization rate for also reducing memory is low.
Summary of the invention
The embodiment of the present invention provides a kind of method of Memory Allocation, and Memory Allocation efficiency and memory usage can be improved. The embodiment of the present invention also provides corresponding devices.
First aspect present invention provides a kind of method of Memory Allocation, comprising:
First memory block is obtained from total memory, in one first memory block comprising multiple and different sizes the Two memory blocks;
According to business to the demand of memory, one for meeting the demand is determined from one first memory block Second memory block, alternatively, obtaining another first memory block for meeting the demand from total memory;
By one second memory block or another described first memory block, the business is distributed to.
Second aspect of the present invention provides a kind of device of Memory Allocation, comprising:
Acquiring unit includes more in one first memory block for obtaining first memory block from total memory A different size of second memory block;
Determination unit, for the demand according to business to memory, one first obtained from the acquiring unit Second memory block for meeting the demand is determined in memory block, meets the need alternatively, obtaining from total memory Another first memory block for the amount of asking;
Allocation unit, for by the determination unit determine one second memory block or it is described another first Memory block distributes to the business.
The embodiment of the present invention uses and obtains first memory block from total memory, includes in one first memory block Second memory block of multiple and different sizes;According to business to the demand of memory, determined from one first memory block full One the second memory block of the foot demand, alternatively, obtained from total memory meet the demand another the One memory block;By one second memory block or another described first memory block, the business is distributed to.With existing skill It can only apply for memory block in art from total memory, and can only apply for that a memory block is compared every time, the embodiment of the present invention provides Memory Allocation method, can apply closing from first memory block of total memory according to business to the demand of memory The second suitable memory block, this way it is possible to realize the parallel distribution of memory, can be improved Memory Allocation efficiency and memory uses Rate.
Detailed description of the invention
To describe the technical solutions in the embodiments of the present invention more clearly, make required in being described below to embodiment Attached drawing is briefly described, it should be apparent that, drawings in the following description are only some embodiments of the invention, for For those skilled in the art, without creative efforts, it can also be obtained according to these attached drawings other attached Figure.
Fig. 1 is an embodiment schematic diagram of the method for Memory Allocation in the embodiment of the present invention;
Fig. 2 is another embodiment schematic diagram of the method for Memory Allocation in the embodiment of the present invention;
Fig. 3 is another embodiment schematic diagram of the method for Memory Allocation in the embodiment of the present invention;
Fig. 4 is another embodiment schematic diagram of the method for Memory Allocation in the embodiment of the present invention;
Fig. 5 is another embodiment schematic diagram of the method for Memory Allocation in the embodiment of the present invention;
Fig. 6 is another embodiment schematic diagram of the method for Memory Allocation in the embodiment of the present invention;
Fig. 7 is an embodiment schematic diagram of the device of Memory Allocation in the embodiment of the present invention;
Fig. 8 is another embodiment schematic diagram of the device of Memory Allocation in the embodiment of the present invention;
Fig. 9 is another embodiment schematic diagram of the device of Memory Allocation in the embodiment of the present invention;
Figure 10 is another embodiment schematic diagram of the device of Memory Allocation in the embodiment of the present invention;
Figure 11 is another embodiment schematic diagram of the device of Memory Allocation in the embodiment of the present invention;
Figure 12 is another embodiment schematic diagram of the device of Memory Allocation in the embodiment of the present invention;
Figure 13 is another embodiment schematic diagram of terminal in the embodiment of the present invention.
Specific embodiment
The embodiment of the present invention provides a kind of method of Memory Allocation, and Memory Allocation efficiency and memory usage can be improved. The embodiment of the present invention also provides corresponding devices.It is described in detail separately below.
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 description, 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, those skilled in the art's every other implementation obtained without creative efforts Example, shall fall within the protection scope of the present invention.
One embodiment of the method for Memory Allocation provided in an embodiment of the present invention includes:
Refering to fig. 1, in the embodiment of the present invention, the first memory block obtained from total memory indicates that Block is with Block Biggish memory block, total memory can be the memory of operating system, and the second memory block for including in the first memory block Block is used Chunk is indicated.It may include the chunk of multiple and different sizes in Block, it is possible to understand that are as follows: the smallest chunk in Block Size is Base, and other chunk sizes are incremented by according to 2 exponent.Certainly, the size of chunk can also be according to other Strategy divides.
The Block obtained from total memory can be got up by Block structures in series, be carried out with the form of Blocklist Management.Blocklist is the first memory block chained list in the embodiment of the present invention.The memory of each Block can be carried out independently It manages, includes pointer Next, pointer Free and pointer End in a Block.Pointer Next is directed toward next Block, pointer Free is directed toward the idle chunk of current Block, and pointer End is directed toward the end position of Block.It can be according to Block when initialization Minimal size initialize a Block.The Block obtained every time below is twice of the last size for obtaining Block, But it is no more than the limitation of maximum Block.
Referring to Fig.2, include three parts: the size Size and information bit Info of pointer next, chunk in chunk, When chunk is not occupied by business, idle chunk sets in corresponding idle chain epitope according to size and is connected by individual event chained list Get up.After Chunk is assigned, it is also by this pointer when releasing memory that pointer next, which is directed toward affiliated distributor, Come oneself being put back into corresponding distributor.Size is the byte-sized of this Chunk, including business datum and Chunk head The length of three units in portion.Information is Info, mainly stores some check informations, the verification etc. including memory write-overflow. It is the position of the storage of the business datum of user after Info, pointer is calculated by following method when returning to user Position: chunk+sizeof (Next)+sizeof (Size)+sizeof (Info), by such as lower section when releasing memory Formula finds the head of Chunk: Ptr-sizeof (Next)-sizeof (Size)-sizeof (Info).
Chunk can be managed by idle chained list freelist, and freelist is the in the embodiment of the present invention Two memory block chained lists.Record has the pointer and size information of each second memory block in first memory block in freelist, most Basic power exponent Base can be arranged in small chunk according to the needs of business, and subsequent chunk size is incremented by according to 2 power.
As shown in Figures 1 and 2, the embodiment of the present invention describes the method for Memory Allocation, and it is preparatory can internally to deposit into row It divides, the block or chunk that are suitble to business is selected when use to use, so that the allocative efficiency core service efficiency of memory is improved, And independent lock can be set in each Block and each Chunk, avoid the interference between business.
Refering to Fig. 3, Fig. 3 is the process schematic of the internal memory initialization provided in the embodiment of the present invention:
S100, initialization start.
S105, initial block size, the ginseng such as maximum block size, minimum Chunk size, freelist length are obtained Number.
The size of namely first block of initial block size, can be first according to initial block acquiring size block.Maximum block size is upper limit when obtaining block, and the block size maximum of acquisition is no more than maximum block The limitation of size.Minimum Chunk size is basic power exponent Base, freelist length i.e. the number of Chunk.
Refering to Fig. 4, another embodiment of the method for Memory Allocation provided in an embodiment of the present invention includes:
S200, initialization start.
Initialization procedure can be understood refering to the description of the part Fig. 3.
S201, business demand amount is obtained.
S202, judge the maximum whether business is greater than the demand of memory in the block applied when initialization Chunk is to execute S203, no, executes S207.
S203, when business is greater than the maximum chunk in a block to the demand of memory, then from total memory again Application one is suitable for another block of the business.
S204, blocklist is locked, and another described block is added in blocklist, blocklist is solved Lock.
S205, will newly apply described in another block distribute to the business, and in service operation to described another A block is locked, in case traffic affecting is run.
After S206, service operation, another described block is unlocked, and another described block is discharged into always Apply for the position of another block in memory.
S207, free time chained list freelist corresponding to the block applied when initializing are locked.
S208, it determines whether freelist is sky, when being not empty, executes step S209, execute step when for sky S212。
S209, the pointer that chunk suitable for the business is found from freelist, according to the finger of the chunk Needle finds corresponding chunk.
S210, freelist unlock, and the corresponding chunk is distributed into the business and is used, to institute when service operation Corresponding chunk is stated to lock.
After S211, service ending, the corresponding chunk is unlocked, the corresponding chunk is discharged into original position It sets.
S212, when freelist is empty, freelist is unlocked, and the demand is divided from one block Measure a chunk of size.
S213, freelist is added in the pointer of newly divide chunk and size information.
S214, a chunk of the new division is distributed into the business, and is locked in service operation.
After S215, service operation, a chunk of the new division is unlocked, and one chunk is discharged To position when original division.
The process that the embodiment of the present invention describes Memory Allocation, uses and discharge can internally deposit into row and divide in advance, make Used time selects the block or chunk that are suitble to business to use, to improve the allocative efficiency core service efficiency of memory, Er Qie Independent lock can be set in each Block and each Chunk, avoid the interference between business.
Refering to Fig. 5, Fig. 5 is the schematic diagram that memory discharges process in the embodiment of the present invention:
After S300, service operation, when memory will discharge, according to the Memory Allocation of the head memory block chunk or block storage The information of device finds corresponding memory allocator.
Whether the size of S305, the judgement memory to be discharged is greater than the capacity of maximum chunk in freelist, holds when being Row step S310 executes step S315 when no.
S310, blocklist is locked, finds the position for wanting releasing memory in total memory, discharges the memory, Blocklist unlock.
S315, freelist is locked, the memory that will be discharged is discharged into corresponding position, and unlocks to freelist.
Refering to Fig. 6, an embodiment of the method for Memory Allocation provided in an embodiment of the present invention includes:
301, first memory block is obtained from total memory, includes multiple and different sizes in one first memory block The second memory block.
302, according to business to the demand of memory, determination meets the demand from one first memory block One the second memory block, alternatively, obtaining another first memory block for meeting the demand from total memory.
303, by one second memory block or another described first memory block, the business is distributed to.
The embodiment of the present invention uses and obtains first memory block from total memory, includes in one first memory block Second memory block of multiple and different sizes;According to business to the demand of memory, determined from one first memory block full One the second memory block of the foot demand, alternatively, obtained from total memory meet the demand another the One memory block;By one second memory block or another described first memory block, the business is distributed to.With existing skill It can only apply for memory block in art from total memory, and can only apply for that a memory block is compared every time, the embodiment of the present invention provides Memory Allocation method, can apply closing from first memory block of total memory according to business to the demand of memory The second suitable memory block, this way it is possible to realize the parallel distribution of memory, can be improved Memory Allocation efficiency and memory uses Rate.
Optionally, on the basis of above-mentioned Fig. 6 corresponding embodiment, the method for Memory Allocation provided in an embodiment of the present invention Another embodiment in, it is described according to business to the demand of memory, determined from one first memory block described in meeting One the second memory block of demand, alternatively, obtaining another first memory for meeting the demand from total memory Block may include:
Whether according to business to the demand of memory, determining in one first memory block has memory to meet the demand One second memory block of amount;
When the second memory block for thering is memory to meet the demand in one first memory block, it is determined that one full One second memory block of the foot demand;
When the second memory block for not having memory to meet the demand, then one is obtained from total memory and meet institute State another described first memory block of demand.
Optionally, provided in an embodiment of the present invention interior on the basis of the corresponding embodiment of above-mentioned Fig. 6 or alternative embodiment It deposits in another embodiment of the method for distribution, one for meeting the demand determining from one first memory block Second memory block may include:
The second pre-generated memory block chained list is searched, record has first memory block in the second memory block chained list In each second memory block pointer and size information;
According to the business to the demand and the size information of memory, the finger of one second memory block is determined Needle;
According to the pointer of one second memory block, one second memory block is found.
Optionally, on the basis of above-mentioned Fig. 6 corresponding alternative embodiment, Memory Allocation provided in an embodiment of the present invention In another embodiment of method, the method can also include:
Described in being unsatisfactory for when the size information of each second memory block recorded in the second memory block chained list When demand, and when not divided amount of ram is greater than the demand in one first memory block, from one the One second memory block for meeting the demand is marked off in one memory block in not divided amount of ram.
Optionally, provided in an embodiment of the present invention interior on the basis of the corresponding embodiment of above-mentioned Fig. 6 or alternative embodiment Deposit in another embodiment of the method for distribution, it is described from obtained in total memory meet the demand another in first When counterfoil, the method can also include:
The pointer of another first memory block is added in the first memory block chained list, the first memory block chained list Middle record has a pointer for each of having obtained the first memory block, the pointer of each first memory block be used for discharge it is corresponding Position when the first memory block, when corresponding first memory block is discharged into acquisition when corresponding first memory block.
Optionally, on the basis of above-mentioned Fig. 6 corresponding alternative embodiment, Memory Allocation provided in an embodiment of the present invention In another embodiment of method, the method can also include:
When discharging one second memory block, according to the pointer of one second memory block, by one Two memory blocks are discharged into position when obtaining one second memory block.
Optionally, provided in an embodiment of the present invention interior on the basis of the corresponding embodiment of above-mentioned Fig. 6 or alternative embodiment It deposits in another embodiment of the method for distribution, it is described by one second memory block or another described first memory block, When distributing to the business, the method can also include:
For one second memory block or another described first memory block setting lock, make one second memory Block or another described first memory block are served only for the business.
Optionally, on the basis of above-mentioned Fig. 6 corresponding alternative embodiment, Memory Allocation provided in an embodiment of the present invention In another embodiment of method, the method can also include:
When discharging the memory of one second memory block or another first memory block, release one Lock in second memory block or another described first memory block.
The method of Memory Allocation provided in an embodiment of the present invention can the process refering to fig. 1 into Fig. 5 understood, this place It does not do and excessively repeats.
Refering to Fig. 7, an embodiment of the device of Memory Allocation provided in an embodiment of the present invention includes:
Acquiring unit 401 is used to obtain first memory block from total memory, includes in one first memory block Second memory block of multiple and different sizes;
Determination unit 402, for the demand according to business to memory, described one obtained from the acquiring unit 401 Second memory block for meeting the demand is determined in a first memory block, is met alternatively, obtaining from total memory Another first memory block of the demand;
Allocation unit 403, one second memory block or described another for determining the determination unit 402 A first memory block, distributes to the business.
In the embodiment of the present invention, acquiring unit 401 obtains first memory block from total memory, in one first It include the second memory block of multiple and different sizes in counterfoil;Determination unit 402, to the demand of memory, is obtained according to business from described Second memory block for meeting the demand is determined in one first memory block for taking unit 401 to obtain, alternatively, from Another first memory block for meeting the demand is obtained in total memory;Allocation unit 403 is by the determination unit 402 Determining one second memory block or another described first memory block, distributes to the business.With in the prior art It can only apply for memory block from total memory, and can only apply for that a memory block is compared every time, it is provided in an embodiment of the present invention interior Assigned unit is deposited, can be according to business to the demand of memory, it is suitable to apply from first memory block of total memory Second memory block, this way it is possible to realize the parallel distribution of memory, can be improved Memory Allocation efficiency and memory usage.
Optionally, on the basis of above-mentioned Fig. 7 corresponding embodiment, the device of Memory Allocation provided in an embodiment of the present invention Another embodiment in,
The determination unit 402, for the demand according to business to memory, determining in one first memory block is No one second memory block for thering is memory to meet the demand;When thering is memory to meet institute in one first memory block When stating the second memory block of demand, it is determined that one meets one second memory block of the demand;In not When being filled with the second memory block of the foot demand, then one is obtained from total memory and meets the described another of the demand One the first memory block.
Optionally, on the basis of the corresponding embodiment of above-mentioned Fig. 7 or alternative embodiment, refering to Fig. 8, the embodiment of the present invention In another embodiment of the device of the Memory Allocation of offer, the determination unit 402 includes:
Subelement 4021 is searched, for searching the second pre-generated memory block chained list, in the second memory block chained list Record has the pointer and size information of each second memory block in first memory block;
Subelement 4022 is determined, for searching according to the business the demand of memory and the lookup subelement 4021 The size information, determine the pointer of one second memory block;
The lookup subelement 4021, one second memory block for being determined according to the determining subelement 4022 Pointer, find one second memory block.
Optionally, provided in an embodiment of the present invention interior on the basis of the corresponding embodiment of above-mentioned Fig. 8 or alternative embodiment It deposits in another embodiment of assigned unit,
The determining subelement 4022, for when each second memory block recorded in the second memory block chained list Size information when being all unsatisfactory for the demand, and in one first memory block not divided amount of ram be greater than it is described When demand, is marked off from amount of ram not divided in one first memory block and meet described the one of the demand A second memory block.
Optionally, on the basis of the corresponding embodiment of above-mentioned Fig. 7 or alternative embodiment, refering to Fig. 9, the embodiment of the present invention In another embodiment of the device of the Memory Allocation of offer, described device 40 further include:
Linked list maintenance unit 404, for by the determination unit 402 determine described in another the first memory block pointer It is added in the first memory block chained list, record has the finger for each of having obtained the first memory block in the first memory block chained list The pointer of needle, each first memory block is used for when discharging corresponding first memory block, by corresponding first memory Position when block is discharged into acquisition when corresponding first memory block.
Optionally, on the basis of the corresponding embodiment of above-mentioned Fig. 8 or alternative embodiment, refering to fig. 10, the present invention is implemented In another embodiment of the device for the Memory Allocation that example provides, the determination unit 402 further include:
Subelement 4023 is discharged, is used for when discharging one second memory block, according to the lookup subelement 4021 One second memory block is discharged into and obtains one second memory by the pointer for one second memory block searched Position when block.
Optionally, on the basis of the corresponding embodiment of above-mentioned Fig. 7 or alternative embodiment, refering to fig. 11, the present invention is implemented In another embodiment of the device for the Memory Allocation that example provides, described device 40 further include:
Setting unit 405, for when the allocation unit 403 distributes the business, being one second memory block Perhaps another first memory block setting lock makes one second memory block or another described first memory block only For the business.
Optionally, on the basis of the corresponding embodiment of above-mentioned Figure 11 or alternative embodiment, refering to fig. 12, the present invention is implemented In another embodiment of the device for the Memory Allocation that example provides, described device 40 further include:
Lifting unit 406 is locked, for discharging one second memory block or another first memory block When memory, release in one second memory block or another described first memory block that the setting unit 405 is arranged Lock.
The process of the Memory Allocation of the device of Memory Allocation provided in an embodiment of the present invention can be refering to fig. 1 into Fig. 5 Process is understood that this place, which is not done, excessively to be repeated.
The method of Memory Allocation provided in an embodiment of the present invention can be applied to any one and be related to setting for Memory Allocation It is standby, such as: immobile terminals and the mobile terminal such as PC (Personal Computer, PC).
By taking mobile terminal as an example, Figure 13 is please referred to, it illustrates the structural representations of terminal involved in the embodiment of the present invention Figure, the terminal can be used for implementing the method for the Memory Allocation provided in above-described embodiment.Specifically:
Terminal 1200 may include RF (Radio Frequency, radio frequency) circuit 110, include one or more The memory 120 of computer readable storage medium, input unit 130, display unit 140, sensor 150, voicefrequency circuit 160, WiFi (wireless fidelity, Wireless Fidelity) module 170, the processing for including one or more than one processing core The components such as device 180 and power supply 190.It will be understood by those skilled in the art that terminal structure shown in Figure 13 is not constituted pair The restriction of terminal may include perhaps combining certain components or different component cloth than illustrating more or fewer components It sets.Wherein:
RF circuit 110 can be used for receiving and sending messages or communication process in, signal sends and receivees, particularly, by base station After downlink information receives, one or the processing of more than one processor 180 are transferred to;In addition, the data for being related to uplink are sent to Base station.In general, RF circuit 110 includes but is not limited to antenna, at least one amplifier, tuner, one or more oscillators, uses Family identity module (SIM) card, transceiver, coupler, LNA (Low Noise Amplifier, low-noise amplifier), duplex Device etc..In addition, RF circuit 110 can also be communicated with network and other equipment by wireless communication.The wireless communication can make With any communication standard or agreement, and including but not limited to GSM (Global System of Mobile communication, entirely Ball mobile communcations system), GPRS (General Packet Radio Service, general packet radio service), CDMA (Code Division Multiple Access, CDMA), WCDMA (Wideband Code Division Multiple Access, wideband code division multiple access), LTE (Long Term Evolution, long term evolution), Email, SMS (Short Messaging Service, short message service) etc..
Memory 120 can be used for storing software program and module, and processor 180 is stored in memory 120 by operation Software program and module, thereby executing various function application and data processing.Memory 120 can mainly include storage journey Sequence area and storage data area, wherein storing program area can the (ratio of application program needed for storage program area, at least one function Such as sound-playing function, image player function) etc.;Storage data area, which can be stored, uses created number according to terminal 1200 According to (such as audio data, phone directory etc.) etc..In addition, memory 120 may include high-speed random access memory, can also wrap Include nonvolatile memory, a for example, at least disk memory, flush memory device or other volatile solid-state parts. Correspondingly, memory 120 can also include Memory Controller, to provide processor 180 and input unit 130 to memory 120 access.
Input unit 130 can be used for receiving the number or character information of input, and generate and user setting and function Control related keyboard, mouse, operating stick, optics or trackball signal input.Specifically, input unit 130 may include touching Sensitive surfaces 131 and other input equipments 132.Touch sensitive surface 131, also referred to as touch display screen or Trackpad are collected and are used Family on it or nearby touch operation (such as user using any suitable object or attachment such as finger, stylus in touch-sensitive table Operation on face 131 or near touch sensitive surface 131), and corresponding attachment device is driven according to preset formula.It is optional , touch sensitive surface 131 may include both touch detecting apparatus and touch controller.Wherein, touch detecting apparatus detection is used The touch orientation at family, and touch operation bring signal is detected, transmit a signal to touch controller;Touch controller is from touch Touch information is received in detection device, and is converted into contact coordinate, then gives processor 180, and can receive processor 180 The order sent simultaneously is executed.Furthermore, it is possible to using multiple types such as resistance-type, condenser type, infrared ray and surface acoustic waves Realize touch sensitive surface 131.In addition to touch sensitive surface 131, input unit 130 can also include other input equipments 132.Specifically, Other input equipments 132 can include but is not limited to physical keyboard, function key (such as volume control button, switch key etc.), One of trace ball, mouse, operating stick etc. are a variety of.
Display unit 140 can be used for showing information input by user or the information and terminal 1200 that are supplied to user Various graphical user interface, these graphical user interface can be made of figure, text, icon, video and any combination thereof. Display unit 140 may include display panel 141, optionally, can use LCD (Liquid Crystal Display, liquid crystal Show device), the forms such as OLED (Organic Light-Emitting Diode, Organic Light Emitting Diode) configure display panel 141.Further, touch sensitive surface 131 can cover display panel 141, when touch sensitive surface 131 detects touching on it or nearby After touching operation, processor 180 is sent to determine the type of touch event, is followed by subsequent processing device 180 according to the type of touch event Corresponding visual output is provided on display panel 141.Although touch sensitive surface 131 and display panel 141 are conducts in Figure 13 Two independent components realize input and input function, but in some embodiments it is possible to by touch sensitive surface 131 and display Panel 141 is integrated and realizes and outputs and inputs function.
Terminal 1200 may also include at least one sensor 150, such as optical sensor, motion sensor and other sensings Device.Specifically, optical sensor may include ambient light sensor and proximity sensor, wherein ambient light sensor can be according to environment The light and shade of light adjusts the brightness of display panel 141, and proximity sensor can close display when terminal 1200 is moved in one's ear Panel 141 and/or backlight.As a kind of motion sensor, gravity accelerometer can detect in all directions (generally Three axis) acceleration size, can detect that size and the direction of gravity when static, can be used to identify mobile phone posture application (ratio Such as horizontal/vertical screen switching, dependent game, magnetometer pose calibrating), Vibration identification correlation function (such as pedometer, tap);Extremely In other sensors such as gyroscope, barometer, hygrometer, thermometer, the infrared sensors that terminal 1200 can also configure, herein It repeats no more.
Voicefrequency circuit 160, loudspeaker 161, microphone 162 can provide the audio interface between user and terminal 1200.Sound Electric signal after the audio data received conversion can be transferred to loudspeaker 161, be converted to by loudspeaker 161 by frequency circuit 160 Voice signal output;On the other hand, the voice signal of collection is converted to electric signal by microphone 162, is received by voicefrequency circuit 160 After be converted to audio data, then by after the processing of audio data output processor 180, be sent to through RF circuit 110 such as another Terminal, or audio data is exported to memory 120 to be further processed.Voicefrequency circuit 160 is also possible that earplug is inserted Hole, to provide the communication of peripheral hardware earphone Yu terminal 1200.
WiFi belongs to short range wireless transmission technology, and terminal 1200 can help user to receive and dispatch electricity by WiFi module 170 Sub- mail, browsing webpage and access streaming video etc., it provides wireless broadband internet access for user.Although Figure 13 shows Go out WiFi module 170, but it is understood that, and it is not belonging to must be configured into for terminal 1200, it completely can be according to need It to omit within the scope of not changing the essence of the invention.
Processor 180 is the control centre of terminal 1200, utilizes each portion of various interfaces and connection whole mobile phone Point, by running or execute the software program and/or module that are stored in memory 120, and calls and be stored in memory 120 Interior data execute the various functions and processing data of terminal 1200, to carry out integral monitoring to mobile phone.Optionally, it handles Device 180 may include one or more processing cores;Preferably, processor 180 can integrate application processor and modulation /demodulation processing Device, wherein the main processing operation system of application processor, user interface and application program etc., modem processor is mainly located Reason wireless communication.It is understood that above-mentioned modem processor can not also be integrated into processor 180.
Terminal 1200 further includes the power supply 190 (such as battery) powered to all parts, it is preferred that power supply can pass through electricity Management system and processor 180 are logically contiguous, to realize management charging, electric discharge and power consumption by power-supply management system The functions such as management.Power supply 190 can also include one or more direct current or AC power source, recharging system, power supply event Hinder the random components such as detection circuit, power adapter or inverter, power supply status indicator.
Although being not shown, terminal 1200 can also include camera, bluetooth module etc., and details are not described herein.Specifically at this In embodiment, the display unit of terminal is touch-screen display, terminal further include have memory and one or more than one Program, one of them perhaps more than one program be stored in memory and be configured to by one or more than one Reason device execution states one or more than one program includes the instruction for performing the following operation:
First memory block is obtained from total memory, in one first memory block comprising multiple and different sizes the Two memory blocks;
According to business to the demand of memory, one for meeting the demand is determined from one first memory block Second memory block, alternatively, obtaining another first memory block for meeting the demand from total memory;
By one second memory block or another described first memory block, the business is distributed to.
Assuming that above-mentioned is the first possible embodiment, then provided based on the first possible embodiment Second of possible embodiment in, in the memory of the terminal, also include instructions for performing the following operations:
Whether according to business to the demand of memory, determining in one first memory block has memory to meet the demand One second memory block of amount;
When the second memory block for thering is memory to meet the demand in one first memory block, it is determined that one full One second memory block of the foot demand;
When the second memory block for not having memory to meet the demand, then one is obtained from total memory and meet institute State another described first memory block of demand.
In the third the possible embodiment provided based on the first or second of possible embodiment, Also include instructions for performing the following operations in the memory of the terminal:
The second pre-generated memory block chained list is searched, record has first memory block in the second memory block chained list In each second memory block pointer and size information;
According to the business to the demand and the size information of memory, the finger of one second memory block is determined Needle;
According to the pointer of one second memory block, one second memory block is found.
In the 4th kind of possible embodiment provided based on the third possible embodiment, the terminal Memory in, also include instructions for performing the following operations:
Described in being unsatisfactory for when the size information of each second memory block recorded in the second memory block chained list When demand, and when not divided amount of ram is greater than the demand in one first memory block, from one the One second memory block for meeting the demand is marked off in one memory block in not divided amount of ram.
In the 5th kind of possible embodiment provided based on first or second kind possible embodiment, institute It states in the memory of terminal, also includes instructions for performing the following operations:
The pointer of another first memory block is added in the first memory block chained list, the first memory block chained list Middle record has a pointer for each of having obtained the first memory block, the pointer of each first memory block be used for discharge it is corresponding Position when the first memory block, when corresponding first memory block is discharged into acquisition when corresponding first memory block.
In the 6th kind of possible embodiment provided based on the third possible embodiment, the terminal Memory in, also include instructions for performing the following operations:
When discharging one second memory block, according to the pointer of one second memory block, by one Two memory blocks are discharged into position when obtaining one second memory block.
In the 7th kind of possible embodiment provided based on first or second kind possible embodiment, institute It states in the memory of terminal, also includes instructions for performing the following operations:
For one second memory block or another described first memory block setting lock, make one second memory Block or another described first memory block are served only for the business.
In the 8th kind of possible embodiment provided based on the 7th kind of possible embodiment, in release institute When stating the memory of second memory block or another first memory block, in the memory of the terminal, also comprising using In the instruction for executing following operation:
Release the lock in one second memory block or another described first memory block.
In conclusion terminal provided in this embodiment, one the first memory block of acquisition from total memory, one first It include the second memory block of multiple and different sizes in memory block;According to business to the demand of memory, out of one first Second memory block for meeting the demand is determined in counterfoil, meets the demand alternatively, obtaining from total memory Another first memory block of amount;By one second memory block or another described first memory block, distribute to described Business.With can only apply for memory block from total memory in the prior art, and can only apply for that a memory block is compared every time, this hair The terminal that bright embodiment provides, can apply from first memory block of total memory according to business to the demand of memory Suitable second memory block, this way it is possible to realize the parallel distribution of memory, can be improved Memory Allocation efficiency and memory uses Rate.
As on the other hand, yet another embodiment of the invention additionally provides a kind of computer readable storage medium, the computer Readable storage medium storing program for executing can be computer readable storage medium included in the memory in above-described embodiment;It is also possible to list Solely exist, without the computer readable storage medium in supplying terminal.The computer-readable recording medium storage have one or More than one program of person, the one or more programs are used to execute one by one or more than one processor The method of Memory Allocation, which comprises
First memory block is obtained from total memory, in one first memory block comprising multiple and different sizes the Two memory blocks;
According to business to the demand of memory, one for meeting the demand is determined from one first memory block Second memory block, alternatively, obtaining another first memory block for meeting the demand from total memory;
By one second memory block or another described first memory block, the business is distributed to.
Assuming that above-mentioned is the first possible embodiment, then provided based on the first possible embodiment Second of possible embodiment in, it is described according to business to the demand of memory, from one first memory block really Surely meet second memory block of the demand, meet the another of the demand alternatively, obtaining from total memory A first memory block, comprising:
Whether according to business to the demand of memory, determining in one first memory block has memory to meet the demand One second memory block of amount;
When the second memory block for thering is memory to meet the demand in one first memory block, it is determined that one full One second memory block of the foot demand;
When the second memory block for not having memory to meet the demand, then one is obtained from total memory and meet institute State another described first memory block of demand.
In the third the possible embodiment provided based on the first or second of possible embodiment, It is described that second memory block for meeting the demand is determined from one first memory block, comprising:
The second pre-generated memory block chained list is searched, record has first memory block in the second memory block chained list In each second memory block pointer and size information;
According to the business to the demand and the size information of memory, the finger of one second memory block is determined Needle;
According to the pointer of one second memory block, one second memory block is found.
In the 4th kind of possible embodiment provided based on the third possible embodiment, the method Further include:
Described in being unsatisfactory for when the size information of each second memory block recorded in the second memory block chained list When demand, and when not divided amount of ram is greater than the demand in one first memory block, from one the One second memory block for meeting the demand is marked off in one memory block in not divided amount of ram.
In the 5th kind of possible embodiment provided based on first, second kind of possible embodiment, institute It states and is obtained when meeting another first memory block of the demand from total memory, the method also includes:
The pointer of another first memory block is added in the first memory block chained list, the first memory block chained list Middle record has a pointer for each of having obtained the first memory block, the pointer of each first memory block be used for discharge it is corresponding Position when the first memory block, when corresponding first memory block is discharged into acquisition when corresponding first memory block.
In the 6th kind of possible embodiment provided based on the third possible embodiment, the method Further include:
When discharging one second memory block, according to the pointer of one second memory block, by one Two memory blocks are discharged into position when obtaining one second memory block.
In the 7th kind of possible embodiment provided based on first or second kind possible embodiment, institute It states one second memory block or another described first memory block, when distributing to the business, the method is also wrapped It includes:
For one second memory block or another described first memory block setting lock, make one second memory Block or another described first memory block are served only for the business.
In the 8th kind of possible embodiment provided based on the 7th kind of possible embodiment, the method Further include:
When discharging the memory of one second memory block or another first memory block, release one Lock in second memory block or another described first memory block.
Those of ordinary skill in the art will appreciate that all or part of the steps in the various methods of above-described embodiment is can It is completed with instructing relevant hardware by program, which can be stored in a computer readable storage medium, storage Medium may include: ROM, RAM, disk or CD etc..
The method and device for being provided for the embodiments of the invention Memory Allocation above are described in detail, herein Apply that a specific example illustrates the principle and implementation of the invention, the explanation of above example is only intended to help Understand method and its core concept of the invention;At the same time, for those skilled in the art, according to the thought of the present invention, There will be changes in the specific implementation manner and application range, in conclusion the content of the present specification should not be construed as to this The limitation of invention.

Claims (17)

1. a kind of method of Memory Allocation characterized by comprising
Total memory is divided into the first memory block of multiple and different sizes, and each first memory block is divided into multiple and different big The second small memory block;
Ready-portioned first memory block in advance is obtained from total memory, includes multiple and different in one first memory block Second memory block of size;
According to business to the demand of memory, idle chained list corresponding to ready-portioned first memory block in advance is locked, from Preparatory ready-portioned second memory for meeting the demand is determined in ready-portioned first memory block in advance Block unlocks the idle chained list, and one ready-portioned second memory block in advance is distributed to the business;
Alternatively,
According to business to the demand of memory, is obtained from total memory and meet another of the demand and divide in advance The first memory block, the first memory block chained list is locked, by another, the first memory is added in ready-portioned first memory block in advance In block chained list, the first memory block chained list is unlocked, another described preparatory ready-portioned first memory block is distributed into the industry Business.
2. the method according to claim 1, wherein it is described according to business to the demand of memory, from described one Second memory block for meeting the demand is determined in a first memory block, is met alternatively, obtaining from total memory Another first memory block of the demand, comprising:
Whether according to business to the demand of memory, determining in one first memory block has memory to meet the demand One second memory block;
When the second memory block for thering is memory to meet the demand in one first memory block, it is determined that one meets institute State one second memory block of demand;
When the second memory block for not having memory to meet the demand, then one is obtained from total memory and meet the need Another described first memory block for the amount of asking.
3. method according to claim 1 or 2, which is characterized in that described to be determined completely from one first memory block One the second memory block of the foot demand, comprising:
The second pre-generated memory block chained list is searched, record has every in first memory block in the second memory block chained list The pointer and size information of a second memory block;
According to the business to the demand and the size information of memory, the pointer of one second memory block is determined;
According to the pointer of one second memory block, one second memory block is found.
4. according to the method described in claim 3, it is characterized in that, the method also includes:
When the size information of each second memory block recorded in the second memory block chained list is unsatisfactory for the demand When amount, and in one first memory block not divided amount of ram be greater than the demand when, out of one first One second memory block for meeting the demand is marked off in counterfoil in not divided amount of ram.
5. method according to claim 1 or 2, which is characterized in that described obtain from total memory meets the need When another first memory block for the amount of asking, the method also includes:
The pointer of another first memory block is added in the first memory block chained list, is remembered in the first memory block chained list Record has the pointer for each of having obtained the first memory block, and the pointer of each first memory block is used in release corresponding first Position when memory block, when corresponding first memory block is discharged into acquisition when corresponding first memory block.
6. according to the method described in claim 3, it is characterized in that, the method also includes:
When discharging one second memory block, according to the pointer of one second memory block, in one second Counterfoil is discharged into position when obtaining one second memory block.
7. method according to claim 1 or 2, which is characterized in that described by one second memory block or described Another first memory block, when distributing to the business, the method also includes:
For one second memory block or another described first memory block setting lock, make one second memory block or Another first memory block described in person is served only for the business.
8. the method according to the description of claim 7 is characterized in that the method also includes:
When discharging the memory of one second memory block or another first memory block, one second is released Lock in memory block or another described first memory block.
9. a kind of device of Memory Allocation, which is characterized in that
The device of the Memory Allocation is specifically used for for total memory being divided into the first memory block of multiple and different sizes, and will be each First memory block is divided into the second memory block of multiple and different sizes;
The device of the Memory Allocation further include:
Acquiring unit, for obtaining ready-portioned first memory block in advance, one first memory block from total memory In include multiple and different sizes the second memory block;
Determination unit, for the demand according to business to memory, to the corresponding sky of ready-portioned first memory block in advance Not busy chained list locks, and determines one that meets the demand from ready-portioned first memory block in advance and divides in advance The second good memory block unlocks the idle chained list;
Alternatively,
According to business to the demand of memory, is obtained from total memory and meet another of the demand and divide in advance The first memory block, the first memory block chained list is locked, by another, the first memory is added in ready-portioned first memory block in advance In block chained list, the first memory block chained list is unlocked;
Allocation unit, one ready-portioned second memory block in advance or described another for determining the determination unit One preparatory ready-portioned first memory block, distributes to the business.
10. device according to claim 9, which is characterized in that
Whether the determination unit determines in having in one first memory block for the demand according to business to memory It is filled with one second memory block of the foot demand;When thering is memory to meet the demand in one first memory block When the second memory block of amount, it is determined that one meets one second memory block of the demand;When there is no memory satisfaction When the second memory block of the demand, then obtained from total memory one meet described in the demand another the One memory block.
11. device according to claim 9 or 10, which is characterized in that the determination unit includes:
Subelement is searched to record in the second memory block chained list for searching the second pre-generated memory block chained list State the pointer and size information of each second memory block in the first memory block;
Subelement is determined, for believing according to the business the demand of memory and the size for searching subelement lookup Breath, determines the pointer of one second memory block;
The lookup subelement, the pointer of one second memory block for being determined according to the determining subelement, is searched To one second memory block.
12. device according to claim 11, which is characterized in that
The determining subelement, for the size letter when each second memory block recorded in the second memory block chained list When breath is all unsatisfactory for the demand, and not divided amount of ram is greater than the demand in one first memory block When, it is marked off from amount of ram not divided in one first memory block and meets one the second of the demand Memory block.
13. device according to claim 9 or 10, which is characterized in that described device further include:
Linked list maintenance unit, for the pointer of another the first memory block described in the determination unit 402 determination to be added to In first memory block chained list, record has the pointer for each of having obtained the first memory block in the first memory block chained list, described The pointer of each first memory block is used for when discharging corresponding first memory block, and corresponding first memory block is discharged into Position when acquisition when corresponding first memory block.
14. device according to claim 11, which is characterized in that the determination unit further include:
Subelement is discharged, described one for being searched according to the lookup subelement when discharging one second memory block One second memory block is discharged into position when obtaining one second memory block by the pointer of a second memory block.
15. device according to claim 9 or 10, which is characterized in that described device further include:
Setting unit is one second memory block or described another for when the allocation unit distributes the business One the first memory block setting lock, makes one second memory block or another described first memory block be served only for the industry Business.
16. device according to claim 15, which is characterized in that described device further include:
Lifting unit is locked, for when discharging the memory of one second memory block or another first memory block, Release the lock in one second memory block or another described first memory block of the setting unit setting.
17. a kind of storage medium, which is characterized in that be stored with computer executable instructions, the calculating in the storage medium When machine executable instruction is loaded and executed by processor, the side of the described in any item Memory Allocations of claim 1 to 8 as above is realized Method.
CN201410314664.5A 2014-07-03 2014-07-03 A kind of method and device of Memory Allocation Active CN105302733B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410314664.5A CN105302733B (en) 2014-07-03 2014-07-03 A kind of method and device of Memory Allocation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410314664.5A CN105302733B (en) 2014-07-03 2014-07-03 A kind of method and device of Memory Allocation

Publications (2)

Publication Number Publication Date
CN105302733A CN105302733A (en) 2016-02-03
CN105302733B true CN105302733B (en) 2019-05-31

Family

ID=55200022

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410314664.5A Active CN105302733B (en) 2014-07-03 2014-07-03 A kind of method and device of Memory Allocation

Country Status (1)

Country Link
CN (1) CN105302733B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109815005A (en) * 2017-11-22 2019-05-28 华为技术有限公司 A kind of method, apparatus and storage system of managing internal memory
CN110888822B (en) * 2019-12-03 2022-09-16 北京小米智能科技有限公司 Memory processing method, device and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101414281A (en) * 2007-10-19 2009-04-22 大唐移动通信设备有限公司 Internal memory management method and system
CN101630992A (en) * 2008-07-14 2010-01-20 中兴通讯股份有限公司 Method for managing shared memory
CN101984417A (en) * 2010-11-01 2011-03-09 中兴通讯股份有限公司 Memory management method and device
CN102446139A (en) * 2011-11-14 2012-05-09 奇智软件(北京)有限公司 Method and device for data storage

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101414281A (en) * 2007-10-19 2009-04-22 大唐移动通信设备有限公司 Internal memory management method and system
CN101630992A (en) * 2008-07-14 2010-01-20 中兴通讯股份有限公司 Method for managing shared memory
CN101984417A (en) * 2010-11-01 2011-03-09 中兴通讯股份有限公司 Memory management method and device
CN102446139A (en) * 2011-11-14 2012-05-09 奇智软件(北京)有限公司 Method and device for data storage

Also Published As

Publication number Publication date
CN105302733A (en) 2016-02-03

Similar Documents

Publication Publication Date Title
CN104965721B (en) The method and device that a kind of pair of application program is updated
CN103500002B (en) The method of application program management, device and terminal unit
CN106357897B (en) The acquisition methods and device of drop information
CN104142868B (en) Establish the method and device of connection
CN105245496B (en) A kind of method and apparatus of playing audio-fequency data
CN105278937B (en) A kind of method and device showing pop-up box message
CN104636047B (en) The method, apparatus and touch screen terminal operated to the object in list
CN106708554B (en) Program operating method and device
CN104077184B (en) A kind of course control method and computer system of application program
CN106294168B (en) A kind of method and system carrying out Application testing
CN104021129B (en) Show the method and terminal of group picture
CN105530239B (en) Multi-medium data acquisition methods and device
CN103294442B (en) A kind of method of playing alert tones, device and terminal device
US20150043312A1 (en) Sound playing method and device thereof
CN105739839B (en) The selection method and device of multimedia menu item
CN105278925B (en) The method and device of rubbish removing is carried out to the software of unloading
CN106210838B (en) Caption presentation method and device
CN104753672B (en) The method, apparatus and terminal of account authorization
CN104102560B (en) The method and device of system performance testing
CN105302733B (en) A kind of method and device of Memory Allocation
CN104965825B (en) A kind of method and terminal of data processing
CN106708500B (en) Unload the display methods and device at interface
CN104346128B (en) The execution method and apparatus of sound event
CN106919458B (en) Method and device for Hook target kernel function
CN105302589B (en) A kind of method and device obtaining unloading information

Legal Events

Date Code Title Description
C06 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