[go: up one dir, main page]

CN1320863A - 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
CN1320863A
CN1320863A CN00108090A CN00108090A CN1320863A CN 1320863 A CN1320863 A CN 1320863A CN 00108090 A CN00108090 A CN 00108090A CN 00108090 A CN00108090 A CN 00108090A CN 1320863 A CN1320863 A CN 1320863A
Authority
CN
China
Prior art keywords
memory
memory block
control unit
real
pointer
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.)
Granted
Application number
CN00108090A
Other languages
Chinese (zh)
Other versions
CN1171152C (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

本发明的一种实时系统中内存快速分配与释放的方法,申请内存分配时,根据输入的申请内存块大小size,得到内存控制单元序号n=二进制数(size-1)的有效位数,该单元n对应内存区内的内存块大小bsize=2n字节,由此快速定位到所需内存块;释放内存块时,根据内存块指针参数,利用该内存块头部预留指针空间中的内存控制单元的指向,得到该内存块所属内存区,快速释放该内存块。本发明方法用于指令以流水线作业的芯片,效率提高尤其显著。A method for fast allocation and release of memory in a real-time system of the present invention, when applying for memory allocation, according to the input application memory block size size, the effective number of bits of the memory control unit serial number n=binary number (size-1) is obtained, the Unit n corresponds to the size of the memory block in the memory area bsize=2 n bytes, so that the required memory block can be quickly located; when the memory block is released, according to the memory block pointer parameter, use the reserved pointer space in the head of the memory block The pointer of the memory control unit obtains the memory area to which the memory block belongs, and quickly releases the memory block. The method of the present invention is used for chips whose instructions are operated in a pipeline, and the efficiency is particularly improved significantly.

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 the control module array) memory field 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、一种实时系统所应用的内存分配的方法,该实时系统的内存区,均对应一内存控制单元,该单元记录内存块的大小、指针及数量,其中,令该所有的内存控制单元组成一数组,该每一单元的地址以索引号n进行标号;以及设定该单元所对应的该内存块大小为2n字节,该方法的特征在于:1. A method for allocating memory used in a real-time system. The memory areas of the real-time system all correspond to a memory control unit, and the unit records the size, pointer and quantity of memory blocks, wherein all the memory control units are composed of An array, the address of each unit is labeled with the index number n; and the memory block size corresponding to the unit is set to be 2 n bytes, the method is characterized in that: a)在该内存块的头部预留一个指针空间,指向该内存控制单元的地址;a) Reserve a pointer space at the head of the memory block, pointing to the address of the memory control unit; b)将所需内存块的大小的参数输入实时系统;b) input the parameters of the size of the required memory block into the real-time system; c)判断该参数的合法性;c) judging the legitimacy of the parameter; d)如果合法,根据该参数寻找该地址的索引号n,确定所对应的该控制单元。d) If it is valid, search for the index number n of the address according to the parameter, and determine the corresponding control unit. 2、根据权利要求1所述的方法,其特征在于:所述步骤d)包括2. The method according to claim 1, characterized in that said step d) comprises e)将该单元所对应的字节数减去1后转换成二进制数;e) convert the byte number corresponding to the unit into a binary number after subtracting 1; f)将该二进制数的位数定义为地址n。f) Define the number of bits of the binary number as address n. 3、根据权利要求1所述的方法,其特征在于:还包括下列步骤3. The method according to claim 1, further comprising the following steps g)在该所找寻的控制单元中取出一空闲的内存块。g) Fetching a free memory block in the sought-after control unit. 4、根据权利要求1所述的方法,其特征在于:所述控制单元的地址最大为16。4. The method according to claim 1, characterized in that: the maximum address of the control unit is 16. 5、一种实时系统所应用的内存释放的方法,该实时系统的内存区均对应一内存控制单元,该单元记录其中内存块的大小、指针及数量,其中,该所有的内存控制单元组成一数组,该每一单元的地址以索引号n进行标号;以及设定该单元所对应的该内存块大小为2n字节,该方法的特征在于:5. A method for releasing memory used in a real-time system. The memory area of the real-time system corresponds to a memory control unit, which records the size, pointer and quantity of the memory block, wherein all the memory control units form a memory control unit. In an array, the address of each unit is labeled with an index number n; and the size of the memory block corresponding to the unit is set to be 2n bytes, the method is characterized in that: h)对该内存块进行初始化;h) initialize the memory block; i)在该每一内存块的头部预留一个指针空间。i) Reserve a pointer space at the head of each memory block. 6、根据权利要求5所述的方法,其特征在于:在执行步骤i)之后还包括下列处理6. The method according to claim 5, characterized in that: after step i) is performed, the following processing is also included j)在该预留的指针空间内,存放指向该内存块所对应的内存控j) In the reserved pointer space, store the memory control corresponding to the memory block 制单元的指针。Pointer to control unit. 7、根据权利要求5或6所述的方法,其特征在于:还包括7. The method according to claim 5 or 6, further comprising: k)根据该预留空间内存放的固定偏移值,判断该内存块指针的合法性;k) judging the legitimacy of the memory block pointer according to the fixed offset value stored in the reserved space; l)如果合法,将该内存块指针所指的内存块归还到依据该预留空间所存放的数值所指向的该内存控制单元中。l) If legal, return the memory block pointed by the memory block pointer to the memory control unit pointed to by the value stored in the reserved space.
CNB001080903A 2000-06-13 2000-06-13 A Method of Fast 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 A Method of Fast 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 A Method of Fast Memory Allocation and Release in Real-time System

Publications (2)

Publication Number Publication Date
CN1320863A true CN1320863A (en) 2001-11-07
CN1171152C 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 A Method of Fast Memory Allocation and Release in Real-time System

Country Status (1)

Country Link
CN (1) CN1171152C (en)

Cited By (5)

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

Cited By (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
CN1171152C (en) 2004-10-13

Similar Documents

Publication Publication Date Title
CN1266590C (en) Progress pole/linear procedure pole management method of construction member oriented backbone system internal core
Larson et al. Memory allocation for long-running server applications
US6119214A (en) Method for allocation of address space in a virtual memory system
CN1183453C (en) Internal storage management system and its distribution method
US8510710B2 (en) System and method of using pooled thread-local character arrays
CN1271524C (en) Static internal storage management method
US5021946A (en) Mostly contiguous file allocation technique involving file extension
CA2556083A1 (en) Memory allocation
US6874062B1 (en) System and method for utilizing a hierarchical bitmap structure for locating a set of contiguous ordered search items having a common attribute
US20090006502A1 (en) Application-Specific Heap Management
US7882505B2 (en) Method and apparatus for switching between per-thread and per-processor resource pools in multi-threaded programs
CN103186469A (en) Memory allocation method and device, and memory recovery method
US20040128463A1 (en) Apparatus and method for controlling memory allocation for variable size packets
US5963982A (en) Defragmentation of stored data without pointer indirection
CN101950273A (en) Dynamic management method of DSP data area
US6219772B1 (en) Method for efficient memory allocation of small data blocks
CN1320863A (en) Method for quick memory allocation and release in real-time system
US20020091904A1 (en) Methods, systems, and computer program products for memory pool management using variable size sub-pools
CN102968378A (en) Method, device and system for allocating and releasing memory
CN101546292A (en) Memory access method and device
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
CN1181434C (en) Adaptive Dynamic Memory Management Method
CN1627262A (en) Memory updating system for field device
CN1321377C (en) Control method of smart card storage environment

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

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

TR01 Transfer of patent right
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