CN1171152C - Method for quick memory allocation and release in real-time system - Google Patents

Method for quick memory allocation and release in real-time system Download PDF

Info

Publication number
CN1171152C
CN1171152C CNB001080903A CN00108090A CN1171152C CN 1171152 C CN1171152 C CN 1171152C CN B001080903 A CNB001080903 A CN B001080903A CN 00108090 A CN00108090 A CN 00108090A CN 1171152 C CN1171152 C CN 1171152C
Authority
CN
China
Prior art keywords
memory
memory block
real
pointer
unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CNB001080903A
Other languages
Chinese (zh)
Other versions
CN1320863A (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.)
CHINA TECHNOLOGY EXCHANGE CO., LTD.
State Grid Beijing Electric Power Co Ltd
State Grid Economic and Technological Research Institute
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CNB001080903A priority Critical patent/CN1171152C/en
Publication of CN1320863A publication Critical patent/CN1320863A/en
Application granted granted Critical
Publication of CN1171152C publication Critical patent/CN1171152C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Memory System (AREA)

Abstract

The present invention relates to a method for quickly allocating and releasing memories in a real-time system. When a memory is applied to be allocated, the significance digits of a memory control unit n (n = size-1) and the size (bsize=2<n> bytes) of a memory block in a corresponding memory region of the unit n are obtained according to the size of the input applied memory block so as to quickly position to a required memory block. When the memory block is released, the attributive memory region of the memory block is obtained according to pointer parameters of the memory block and by utilizing the pointing of the memory control unit in a pointer space preserved at the head of the memory block so as to quickly release the memory block. The method of the present invention is used for chips, wherein the instructions of which are operated in a streamline mode. The present invention notably enhances efficiency.

Description

Internal memory distributes and the method that discharges fast in a kind of real-time system
The present invention relates to a kind of calculator memory administrative skill, be specifically related to a kind of method that in real-time system, realizes memory management fast.
Real-time system requires to execute the task of defined in the time that limits.At present, this system has a wide range of applications, as process control, data acquisition, communication, multimedia messages processing etc. to the more sensitive occasion of time ratio.Weighing a real-time weak index of real-time system is that this real-time system executes the function of regulation and the length of response external asynchronous event required time, so some outstanding real-time systems all try hard to accomplish minimum on system overheads such as task context switching, system call, interrupt response, memory management.Memory management is one of most important component of real-time system, and one of them important goal of design real-time system is exactly to improve the efficient of memory management, and then improves the utilization factor of CPU.
A kind of general Memory Allocation strategy is a variable length Memory Allocation strategy, but makes in this way real-time system through after the long period operation, can produce a large amount of memory fragmentations, causes a large amount of wastes of internal memory, even causes system crash; The shortcoming that also has of this method is the extremely uncertainty of internal memory application and release, thus in the real-time system of reality general this method of less use.
In fact, in real-time system, adopt a kind of Memory Allocation strategy of regular length usually.This method is earlier internal memory to be divided into several districts, each district is divided into the identical memory block of size again then, memory block size between the different districts is unequal, and the size of general memory piece is 2 power power, i.e. 16 bytes, 32 bytes, 64 bytes ... 1024 bytes ... or the like; When each application size is the memory block of size, each district of scanning earlier always, find the district at the minimum memory block place that is not less than size, taking out a memory block then from this district returns, if the memory block in this district uses up, just return sky, rather than from other district, get bigger memory block and return, during each releasing memory, according to the pointer that is released memory block, scan each district once more, seek this memory block and belong to which district, and then after having found this district, just memory block is returned in this district.This method no longer causes memory fragmentation, but because each application all needs to scan each memory field with releasing memory, this scanning is all relatively reached jump instruction and is formed by many in realization, and memory management module is one of module that usage frequency is the highest in the real-time system, the efficient of memory management module will badly influence the efficient of whole real-time system, so just cause a large amount of wastes of cpu resource; In addition, the memory management expense of this method is also relevant with the quantity of memory field in the real-time system, particularly when the internal memory of a real-time system was divided into by 4 bytes to many different memory field that the memory block of 64K byte is formed, it will badly influence memory management module so that the efficient of whole real-time system.
Purpose of the present invention just is to provide a kind of quick EMS memory management process that solves problem in the above-mentioned EMS memory management process, this method has significantly improved the speed of internal memory application and release in the real-time system, it can be located the size of this memory block when each application and releasing memory piece fast, and do not need to scan several memory fields at every turn, carry out several times and obtain a result after relatively, thereby greatly improved the speed and the efficient of memory management in the real-time system.
Internal memory distributes and the method that discharges fast in a kind of real-time system provided by the invention, and its technical scheme is achieved in that
The method of the applied Memory Allocation of a kind of real-time system, the memory field of this real-time system, an all corresponding memory control unit, the size of this unit record memory block, pointer and quantity, wherein, make this all memory control unit form an array, label is carried out with call number n in the address of this each unit; And to set pairing this memory block size in this unit be 2 nByte the method is characterized in that,
A) reserve a pointer space at the head of this memory block, point to the address of this memory control unit;
B) with the parameter input real-time system of the size of required memory piece;
C) judge the legitimacy of this parameter;
D) if legal, seek the call number n of this address, determine pairing this control module according to this parameter.
Described memory allocation method, wherein, described step d) comprises
E) after being deducted 1, the pairing byte number in this unit converts binary number to;
F) figure place with this binary number is defined as address n.
Described memory allocation method wherein, also comprises the following steps
G) memory block of one free time of taking-up in this control module of looking for.
Described memory allocation method, wherein, the address of described control module is 16 to the maximum.
The applied internal memory releasing method of a kind of real-time system, the all corresponding memory control unit in the memory field of this real-time system, this unit record is size, pointer and the quantity of memory block wherein, wherein, this all memory control unit is formed an array, and label is carried out with call number n in the address of this each unit; And to set pairing this memory block size in this unit be 2 nByte the method is characterized in that,
H) this memory block is carried out initialization;
I) reserve a pointer space at the head of this each memory block.
Described internal memory method for releasing is wherein, at execution in step i) also comprise following processing afterwards
J) in the pointer space of this reservation, deposit and point to the pairing internal memory control of this memory block
The pointer of system unit.
Described internal memory method for releasing wherein, also comprises
K), judge the legitimacy of this memory block pointer according to the fixed offset value of depositing in this headspace;
L) if legal, the memory block of this memory block pointer indication is returned to according in the stored numerical value of this headspace this memory control unit pointed.
Because EMS memory management process provided by the invention has been saved a large amount of jump instructions that relatively reach on memory management module, in various real-time systems, not only can reduce expense, the efficient of raising system when internal memory application and release of memory management, and the quantity configuration-independent of memory management expense and memory field, therefore this real-time system can not lower efficiency because of the variation of concrete application program and load, thereby has improved the stability of system high efficiency rate work.Method provided by the invention is for the CPU of instruction with pipelining, and the raising of its performance is particularly evident.
Below in conjunction with accompanying drawing, by preferred embodiment of the present invention is described in detail, will make above-mentioned purpose of the present invention and other advantages apparent, wherein,
Fig. 1 is the data structure synoptic diagram of memory management module in the real-time system;
Fig. 2 is the process flow diagram of internal memory fast distribution method of the present invention;
Fig. 3 is the process flow diagram of internal memory snap-out release method of the present invention.
Fig. 1 has described the data structure synoptic diagram of memory management module in the real-time system.The 101st, the array that memory control unit is formed, each unit record the information such as pointer of the size of the memory block in its pairing memory field, quantity, free memory block.There is following relation: bsize=2 in memory block size bsize in control module call number n (being the unit number of control module array) the inherence district corresponding with this unit nByte; Each memory block is also reserved a pointer space at its head, shown in 102,103 etc.; This pointed the address of its pairing memory control unit, as the pointed in memory block 102 headspaces control module 0, and the pointed in memory block 103 headspaces control module 1, and the like, as shown in Figure 1.
Fig. 2 has described the quick allocation flow figure of internal memory that utilizes the inventive method design.Beginning from step 201, internal memory application service routine is called.In step 202 the parameter imported into, i.e. the memory size that need apply for, assignment is given size.In step 203, judge the legitimacy of size, just return sky, finish to step 206 if size is an illegal value; Just forward in the step 204 if size is a legal value, in step 204, calculate the call number n of memory control unit according to the value of size, according to the number of significant digit that concerns n=binary number (size-1), this corresponding relation can be finished by a command adapted thereto in the existing cpu instruction system.In step 205, can navigate to control module according to the unit number n that previous step obtains, if the pairing memory block of this control module is not empty, then taking out a free memory block returns, otherwise just return sky, enter into step 206 end, thereby can navigate to the position of the actual memory block of obtaining fast.
Fig. 3 has described the internal memory snap-out release process flow diagram that utilizes the inventive method design.Beginning from step 301, internal memory discharge service routine and are called.In step 302,, be about to d/d memory block pointer assignment and give p1 the parameter of importing into.In step 303, oppositely pointed to the pointer p2 of memory control unit according to the fixed offset value of headspace in the memory block.In step 304, can judge the legitimacy of memory block pointer p1 according to the information of memory control unit, just jump to step 306 end if p1 is an illegal value; Just forward in the step 305 if p1 is a legal value, in step 305, be returned to p1 memory block pointed in the p2 memory control unit pointed after, finish in the step 306.
What deserves to be explained is, utilize method of the present invention, can on various platforms, develop memory management module at an easy rate, and use the memory management module flow process basically identical of the inventive method design, be on specific implementation, the instruction type difference that may use; If the compiler of higher level lanquage can't generate this instruction, just need in higher level lanquage, embed assembly language and realize.
For example, with the memory management module that method of the present invention realizes on this risc chip of Motorola PowerPC860 (hereinafter to be referred as MPC860), the raising of its efficient is just apparent in view.Because the instruction of risc chip relatively reaches jump instruction with pipelining and significantly reduced in the inventive method.On MPC860, when needing to calculate the number of bits of a number, use instruction cntlzw rA rS, the number of leading 0 among the register rS is at first taken out in this instruction, and assignment gives register rA, and then just obtained the number of bits of register rS Central Plains number with 32 values that deduct rA.Test on the MPC860 of 50MHz shows that the average operating time to internal memory application and release in the prior art is 12us, and uses the time of this method to be 2us.Compare with memory allocation method in the past, the speed of Memory Allocation of the present invention and release is significantly increased, and the raising of this efficient can finally cause the raising of the performance of whole real-time system.
Should be understood that the one of ordinary skilled in the art can make various suitable changes or replacement under the premise of not departing from the present invention, but these changes or replacement all should belong to protection scope of the present invention.

Claims (7)

1, the method for the applied Memory Allocation of a kind of real-time system, the memory field of this real-time system, an all corresponding memory control unit, the size of this unit record memory block, pointer and quantity, wherein, make this all memory control unit form an array, label is carried out with call number n in the address of this each unit; And to set pairing this memory block size in this unit be 2 nByte the method is characterized in that:
A) reserve a pointer space at the head of this memory block, point to the address of this memory control unit;
B) with the parameter input real-time system of the size of required memory piece;
C) judge the legitimacy of this parameter;
D) if legal, seek the call number n of this address, determine pairing this control module according to this parameter.
2, method according to claim 1 is characterized in that: described step d) comprises
E) after being deducted 1, the pairing byte number in this unit converts binary number to;
F) figure place with this binary number is defined as address n.
3, method according to claim 1 is characterized in that: also comprise the following steps
G) memory block of one free time of taking-up in this control module of looking for.
4, method according to claim 1 is characterized in that: the address of described control module is 16 to the maximum.
5, the applied internal memory releasing method of a kind of real-time system, the all corresponding memory control unit in the memory field of this real-time system, this unit record is size, pointer and the quantity of memory block wherein, wherein, this all memory control unit is formed an array, and label is carried out with call number n in the address of this each unit; And to set pairing this memory block size in this unit be 2 nByte the method is characterized in that:
H) this memory block is carried out initialization;
I) reserve a pointer space at the head of this each memory block.
6, method according to claim 5 is characterized in that: at execution in step i) also comprise following processing afterwards
J) in the pointer space of this reservation, deposit the pointer that points to the pairing memory control unit of this memory block.
7, according to claim 5 or 6 described methods, it is characterized in that: also comprise
K), judge the legitimacy of this memory block pointer according to the fixed offset value of depositing in this headspace;
L) if legal, the memory block of this memory block pointer indication is returned to according in the stored numerical value of this headspace this memory control unit pointed.
CNB001080903A 2000-06-13 2000-06-13 Method for quick memory allocation and release in real-time system Expired - Fee Related CN1171152C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB001080903A CN1171152C (en) 2000-06-13 2000-06-13 Method for quick memory allocation and release in real-time system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB001080903A CN1171152C (en) 2000-06-13 2000-06-13 Method for quick memory allocation and release in real-time system

Publications (2)

Publication Number Publication Date
CN1320863A CN1320863A (en) 2001-11-07
CN1171152C true CN1171152C (en) 2004-10-13

Family

ID=4579127

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB001080903A Expired - Fee Related CN1171152C (en) 2000-06-13 2000-06-13 Method for quick memory allocation and release in real-time system

Country Status (1)

Country Link
CN (1) CN1171152C (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1307558C (en) * 2001-12-29 2007-03-28 中兴通讯股份有限公司 Virtual internal storage allocating and managing method of subsystem in communication system
CN1303534C (en) * 2003-03-03 2007-03-07 华为技术有限公司 Memory pool managing method
CN100478916C (en) * 2004-09-24 2009-04-15 上海贝尔阿尔卡特股份有限公司 Internal storage management system and method
US10241715B2 (en) 2014-01-31 2019-03-26 Hewlett Packard Enterprise Development Lp Rendering data invalid in a memory array
CN108108307A (en) * 2016-11-24 2018-06-01 中移(杭州)信息技术有限公司 A kind of method for processing resource and terminal

Also Published As

Publication number Publication date
CN1320863A (en) 2001-11-07

Similar Documents

Publication Publication Date Title
CN1266590C (en) Progress pole/linear procedure pole management method of construction member oriented backbone system internal core
CN1271524C (en) Static internal storage management method
CN1132112C (en) Method for reserving resources
US7325118B2 (en) Method and apparatus for executing dynamic memory management with object-oriented program
US20060218557A1 (en) Method and apparatus for switching between per-thread and per-processor resource pools in multi-threaded programs
US20100088675A1 (en) System and method of using pooled thread-local character arrays
CN102968378B (en) A kind of method of random memory, Apparatus and system
US20070156997A1 (en) Memory allocation
CN102063385A (en) Memory management method and system
US20090006502A1 (en) Application-Specific Heap Management
CN103186469A (en) Memory allocation method and device, and memory recovery method
CN1171152C (en) Method for quick memory allocation and release in real-time system
US20040128463A1 (en) Apparatus and method for controlling memory allocation for variable size packets
US5963982A (en) Defragmentation of stored data without pointer indirection
US6219772B1 (en) Method for efficient memory allocation of small data blocks
CN101546292A (en) Memory access method and device
KR100349958B1 (en) Method and apparatus for memory management
CN104536773B (en) Embedded software dynamic memory recovery method based on internal memory scanning
US6976021B2 (en) Method, system, and computer program product for managing a re-usable resource with linked list groups
CN1650525A (en) Sigma-delta analog-to-digital converter and method
EP0844564B1 (en) Memory manager system and method therefor
CA2768956A1 (en) Method for managing physical memory of a data storage and data storage management system
CN103257936B (en) EMS memory mappings method and memory-mapped module
CN1393780A (en) Adaptive dynamic memory management method
CN115658561A (en) Power distribution terminal memory management method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
ASS Succession or assignment of patent right

Owner name: BEIJING POWER ECONOMIC RESEARCH INSTITUTE

Free format text: FORMER OWNER: ZTE CORPORATION

Effective date: 20140129

Owner name: STATE GRID BEIJING ELECTRIC POWER COMPANY CHINA TE

Effective date: 20140129

COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 518057 SHENZHEN, GUANGDONG PROVINCE TO: 100055 XICHENG, BEIJING

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20140129

Address after: 100055 No. 15 West Street, Guanganmen station, Beijing, Xicheng District

Patentee after: State Power Economic Research Institute

Patentee after: State Grid Beijing Electric Power Company

Patentee after: CHINA TECHNOLOGY EXCHANGE CO., LTD.

Address before: 518057 Department of law, Zhongxing building, South Science and technology road, Shenzhen hi tech Industrial Park, Guangdong

Patentee before: ZTE Corporation

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

Granted publication date: 20041013

Termination date: 20150613

EXPY Termination of patent right or utility model