WO2016082591A1 - Method and device for embedded system to count memory - Google Patents

Method and device for embedded system to count memory Download PDF

Info

Publication number
WO2016082591A1
WO2016082591A1 PCT/CN2015/087709 CN2015087709W WO2016082591A1 WO 2016082591 A1 WO2016082591 A1 WO 2016082591A1 CN 2015087709 W CN2015087709 W CN 2015087709W WO 2016082591 A1 WO2016082591 A1 WO 2016082591A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
embedded system
identification number
usage status
status information
Prior art date
Application number
PCT/CN2015/087709
Other languages
French (fr)
Chinese (zh)
Inventor
刘东栋
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016082591A1 publication Critical patent/WO2016082591A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]

Definitions

  • the present invention relates to the field of embedded system technologies, and in particular, to an embedded system memory statistical method and apparatus.
  • Memory is the main place for applications running in embedded systems. Real-time control of embedded memory usage is critical to the operational efficiency of embedded systems. The key to detecting memory leaks is the ability to get a distribution of memory usage online, that is, to get the programs that are currently occupied.
  • the prior art generally records the memory usage by recording the file, line number, and stack information of each memory application, but the memory used to record the file, line number, and stack information of the memory application is large, resulting in a large memory. The available memory of the application in the embedded system is too small.
  • the embodiment of the invention provides an embedded system memory statistics method and device, which aims to solve at least the technical problem that the data occupied by the recording memory occupation has a large memory space.
  • an embodiment of the present invention provides an embedded system memory statistics method, where the embedded system memory statistics method includes the following steps:
  • the preset identification number corresponding to the memory requested by the application is obtained, and the usage status information corresponding to the identification number is set to the used state;
  • the preset identification number corresponding to the memory released by the application is obtained, and the usage status information corresponding to the identification number is set to an unused state;
  • obtaining the preset identification number corresponding to the memory released by the application, and setting the usage status information corresponding to the identification number to the unused state before the step further includes:
  • the identification number is set for each piece of memory of the embedded system according to a preset definition rule.
  • the step of setting an identification number for each piece of memory of the embedded system according to the preset definition rule further includes:
  • the step of acquiring the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage state information currently set to the used state includes:
  • the method further includes:
  • the corresponding identification number and the memory information are obtained in the corresponding relationship according to the usage status information obtained by the current search;
  • the usage status information obtained by the current search and the identification number and the memory information obtained according to the usage status information obtained by the search are sent to the preset storage module.
  • the embodiment of the present invention further provides an embedded system memory statistics device, where the embedded system memory statistics device includes:
  • the first processing module is configured to: when the application applies for the memory, obtain the preset identification number corresponding to the memory requested by the application, and set the usage status information corresponding to the identification number to the used state;
  • the second processing module is configured to: when the application releases the memory, acquire a preset identification number corresponding to the memory released by the application, and set the usage status information corresponding to the identification number to an unused state;
  • the statistic module is configured to acquire the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage status information currently set to the used state.
  • the embedded system memory statistics device further includes:
  • the setting module is set to set an identification number for each piece of memory of the embedded system according to a preset definition rule.
  • the embedded system memory statistics device further includes:
  • a creating a module configured to create a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, where The initial values of the usage status information corresponding to each of the identification numbers are all unused.
  • the statistics module includes:
  • a searching unit configured to search, in the correspondence relationship, usage status information that is currently in a used state
  • An obtaining unit configured to obtain corresponding memory information in the correspondence relationship according to the usage state information obtained by the searching;
  • the statistic unit is configured to obtain, according to the obtained memory information, a memory occupied by an application currently running by the embedded system.
  • the embedded system memory statistics device further includes:
  • Obtaining a module configured to obtain a corresponding identification number and memory information in the corresponding relationship according to usage state information obtained by the current search after each preset time;
  • the sending module is configured to send the usage status information obtained by the current search, and the identification number and the memory information obtained according to the usage status information obtained by the searching to the preset storage module.
  • the embedded system memory statistics method and device acquires a preset identification number corresponding to the memory applied by the application when the application applies for the memory, and sets the usage status information corresponding to the identification number.
  • the used state when the application releases the memory, obtains the preset identification number corresponding to the memory released by the application, and sets the usage status information corresponding to the identification number to an unused state; according to the current setting, Obtaining the memory occupied by the application currently running by the embedded system by using the flag number corresponding to the usage status information of the state, and the identification number may be an integer type data, and the module level information of the memory can be recorded by the identification number, effectively Reduces the memory space occupied by data set to record memory occupancy, reducing the overhead of memory space, thereby increasing the available memory of applications in embedded systems.
  • FIG. 1 is a schematic flow chart of a first embodiment of an embedded system memory statistical method according to the present invention
  • FIG. 2 is a schematic flow chart of a second embodiment of an embedded system memory statistical method according to the present invention.
  • FIG. 3 is a schematic flowchart of a third embodiment of an embedded system memory statistical method according to the present invention.
  • FIG. 4 is a schematic diagram of a refinement process of step S30 in FIG. 1;
  • FIG. 5 is a schematic flowchart of a fourth embodiment of an embedded memory statistics method according to the present invention.
  • FIG. 6 is a schematic diagram of functional modules of a first embodiment of an embedded system memory statistical device according to the present invention.
  • FIG. 7 is a schematic diagram of functional modules of a second embodiment of an embedded system memory statistics apparatus according to the present invention.
  • FIG. 8 is a schematic diagram of functional modules of a third embodiment of an embedded system memory statistical device according to the present invention.
  • FIG. 9 is a schematic diagram of a refinement function module of the statistical module in FIG. 6;
  • FIG. 10 is a schematic diagram of functional modules of a fourth embodiment of an embedded system memory statistics apparatus according to the present invention.
  • Embodiments of the present invention provide an embedded system memory statistics method.
  • FIG. 1 is a schematic flowchart diagram of a first embodiment of an embedded system memory statistical method according to the present invention.
  • the embedded system memory statistical method comprises the following steps:
  • step S10 when the application applies for the memory, the preset identification number corresponding to the memory requested by the application is obtained, and the usage status information corresponding to the identification number is set to the used state;
  • step S20 when the application releases the memory, the preset identification number corresponding to the memory released by the application is obtained, and the usage status information corresponding to the identification number is set to an unused state;
  • the identification number can be set according to actual needs, as long as each identification number can be made to represent a piece of memory.
  • the identification number can be set using an integer type of data.
  • the memory management header structure (or the memory management header structure in the operating system is used), and the memory management header structure includes an identification number field set to record each of the identification numbers. And a memory information field configured to record memory information corresponding to each of the identification numbers and a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and then recording each of the identification numbers to the location In the identifier number field, the memory information corresponding to each of the identifier numbers is recorded in the memory information field, and the usage status information of each block of the memory corresponding to the identifier number is recorded in the usage status field, where And forming a one-to-one correspondence between each of the identification number recorded in the memory management header structure, the memory information corresponding to the identification number, and the usage status information of the memory corresponding to the identification number.
  • the memory information can represent the size and location of the memory.
  • the identification number corresponding to the requested memory is obtained, and then the usage status information corresponding to the identification number is set to the used state. Therefore, by querying the usage status field in the memory management header structure, the current corresponding memory occupied identification number can be obtained.
  • the identification number corresponding to the released memory is obtained, and then the usage status information corresponding to the identification number is set to the unused state. Therefore, by querying the usage status field in the memory management header structure, the identification number of the current corresponding memory that is not occupied can be obtained.
  • Step S30 Acquire a memory occupied by an application currently running by the embedded system according to a flag number corresponding to the usage state information currently set to the used state.
  • the embedded system memory statistics method obtains a preset identification number corresponding to the memory applied by the application when the application applies for the memory, and sets the usage status information corresponding to the identification number to The usage status; when the application releases the memory, obtains the preset identification number corresponding to the memory released by the application, and sets the usage status information corresponding to the identification number to an unused state; according to the current setting, the used state
  • the identifier corresponding to the usage status information acquires the memory occupied by the application currently running by the embedded system, and the identification number can adopt integer data, and the module level information of the memory can be recorded by the identification number, which effectively reduces the The memory space set by the data set to record the memory occupancy reduces the overhead of the memory space, thereby increasing the available memory of the application in the embedded system.
  • FIG. 2 is a schematic flowchart of a second embodiment of the method for calculating the memory of the embedded system according to the present invention.
  • the method before step S10 and step S20, the method further includes:
  • Step S40 setting an identification number for each piece of memory of the embedded system according to a preset definition rule.
  • the preset definition rules may be set according to actual needs, as long as each identification number can represent one piece of memory.
  • the identification number adopts unsigned integer data, and each identification number represents a piece of memory of the embedded system.
  • the 32-bit integer number is used as an example, and the identification number can be divided into three segments. The first 8 bits from the high-order byte are the first segment, indicating one of the memory user or the releaser.
  • Level module indicating a range of 0 to 255, 0 value reserved; the second segment is 12 bits, indicating the secondary module of the memory user or releaser, indicating the range is 1 to 4095; the remaining 12 in the low byte
  • the bit is the third segment, which represents the three-level module of the memory user or the releaser.
  • the third-level module can be further divided into two segments, indicating a more refined module memory usage position.
  • the third segment can be divided into 4 segments.
  • the bits and the two bits of the two bits represent the sub-module number and the offset within the sub-module, respectively, ranging from 1 to 255 and 1 to 15.
  • FIG. 3 is a schematic flowchart of a third embodiment of the method for calculating the memory of the embedded system according to the present invention.
  • the method further includes:
  • Step S50 creating a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, wherein The initial values of the usage status information corresponding to the identification number are all unused.
  • the memory information of the memory block represented by the identification number, and the identification number The usage status information of the memory block establishes a one-to-one correspondence, so that the system can query the corresponding identification number and memory information according to the usage status information.
  • the foregoing correspondence relationship is represented by the foregoing memory management header structure, where the memory management header structure includes an identification number field configured to record each of the identification numbers, and a memory information field configured to record memory information corresponding to each of the identification numbers. And a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and recording the memory information corresponding to each of the identification numbers by recording each of the identification numbers into the identification number field In the memory information field, the usage status information of each block of memory corresponding to each of the identification numbers is recorded into the usage status field, wherein each of the identification numbers recorded in the memory management header structure Forming a one-to-one correspondence between the memory information corresponding to the identification number and the usage status information of the memory corresponding to the identification number, so that the system can obtain the application of the embedded system by querying the memory management header structure. Occupied memory, thus further effectively reducing the memory space occupied by data set to record memory occupancy Reducing the overhead of memory space, thereby increasing the memory available to applications in
  • FIG. 4 is a schematic diagram of a refinement process of step S30 in FIG. 1.
  • step S30 includes:
  • Step S31 searching for the usage status information that is currently in the used state in the corresponding relationship
  • the usage status information currently set to the used status is searched for.
  • Step S32 Obtain corresponding memory information in the correspondence relationship according to the usage state information obtained by the searching;
  • the current usage state is obtained.
  • Memory information for the usage state information of the currently used state obtained by searching in step S31, by searching for the memory information corresponding to the usage state information in the memory management header structure, the current usage state is obtained.
  • Step S33 Acquire, according to the acquired memory information, a memory occupied by an application currently running by the embedded system.
  • the memory information obtained in step S32 is counted. Since the memory information includes the memory size, the current running application program of the embedded system can be obtained by superimposing the memory size represented by each memory information. Occupied memory.
  • FIG. 5 is embedded in the present invention.
  • the flowchart of the fourth embodiment of the method for calculating the memory, in one or all of the embodiments of the present invention, after step S30, the method further includes:
  • Step S60 After the preset time, obtain the corresponding identification number and memory information in the corresponding relationship according to the usage state information obtained by the current search.
  • step S70 the usage status information obtained by the current search and the identification number and the memory information obtained according to the usage status information obtained by the search are sent to the preset storage module.
  • the preset time can be set according to actual needs.
  • the preset storage module can be a piece of memory in the embedded system or an external storage device, and can be set according to actual needs.
  • the usage status information in the used state obtained by the current search, the identification number corresponding to the usage status information, and the memory information are all sent to the preset storage module.
  • the embedded system may be considered to have a memory leak and needs to be processed in time.
  • the statistical information of the memory in the used state is periodically sent to the preset storage module, so that the user can obtain the current memory usage of the embedded system by viewing the statistical information in the preset storage module, and Determine if there is a memory leak in the current embedded system.
  • the embodiment of the invention further provides an embedded system memory statistics device.
  • FIG. 6 is a schematic diagram of functional modules of a first embodiment of an embedded system memory statistical device according to the present invention.
  • the embedded system memory statistics device comprises:
  • the first processing module 10 is configured to: when the application applies for the memory, obtain the preset identification number corresponding to the memory requested by the application, and set the usage status information corresponding to the identification number to the used state;
  • the second processing module 20 is configured to: when the application releases the memory, acquire an preset identification number corresponding to the memory released by the application, and set the usage status information corresponding to the identification number to an unused state;
  • the identification number can be set according to actual needs, as long as each identification number can be made to represent a piece of memory.
  • the identification number can be set using an integer type of data.
  • the memory management header structure (or the memory management header structure in the operating system is used), and the memory management header structure includes an identification number field set to record each of the identification numbers. And a memory information field configured to record memory information corresponding to each of the identification numbers and a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and then recording each of the identification numbers to the location In the identifier number field, the memory information corresponding to each of the identifier numbers is recorded in the memory information field, and the usage status information of each block of the memory corresponding to the identifier number is recorded in the usage status field, where And forming a one-to-one correspondence between each of the identification number recorded in the memory management header structure, the memory information corresponding to the identification number, and the usage status information of the memory corresponding to the identification number.
  • the memory information can represent the size and location of the memory.
  • the identification number corresponding to the requested memory is obtained, and then the usage status information corresponding to the identification number is set to the used state. Therefore, by querying the usage status field in the memory management header structure, the current corresponding memory occupied identification number can be obtained.
  • the identification number corresponding to the released memory is obtained, and then the usage status information corresponding to the identification number is set to the unused state. Therefore, by querying the usage status field in the memory management header structure, the identification number of the current corresponding memory that is not occupied can be obtained.
  • the statistic module 30 is configured to obtain the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage status information currently set to the used state.
  • the identification number obtained by the query can obtain the memory occupied by the application currently running by the embedded system; or the usage status information obtained according to the query.
  • the corresponding memory information is searched. Since the memory information directly represents the memory address and the memory size, the memory occupied by the application currently running by the embedded system can be obtained by searching the obtained memory information.
  • the embedded system memory statistics device obtains a preset identification number corresponding to the memory requested by the application when the application applies for the memory, and sets the usage status information corresponding to the identification number to The usage status; when the application releases the memory, obtains the preset identification number corresponding to the memory released by the application, and sets the usage status information corresponding to the identification number to an unused state; according to the current setting, the used state
  • the identifier corresponding to the usage status information acquires the memory occupied by the application currently running by the embedded system, and the identification number can adopt integer data, and the module level information of the memory can be recorded by the identification number, which effectively reduces the The memory space set by the data set to record the memory occupancy reduces the overhead of the memory space, thereby increasing the available memory of the application in the embedded system.
  • FIG. 7 is a schematic diagram of a functional module of a second embodiment of an embedded system memory statistic apparatus according to the present invention.
  • the embedded system memory statistic apparatus further includes:
  • the setting module 40 is configured to set an identification number for each piece of memory of the embedded system according to a preset definition rule.
  • the preset definition rules may be set according to actual needs, as long as each identification number can represent one piece of memory.
  • the identification number adopts unsigned integer data, and each identification number represents a piece of memory of the embedded system.
  • the 32-bit integer number is used as an example, and the identification number can be divided into three segments. The first 8 bits from the high-order byte are the first segment, indicating one of the memory user or the releaser.
  • Level module indicating a range of 0 to 255, 0 value reserved; the second segment is 12 bits, indicating the secondary module of the memory user or releaser, indicating the range is 1 to 4095; the remaining 12 in the low byte
  • the bit is the third segment, which represents the three-level module of the memory user or the releaser.
  • the third-level module can be further divided into two segments, indicating a more refined module memory usage position.
  • the third segment can be divided into 4 segments.
  • the bits and the two bits of the two bits represent the sub-module number and the offset within the sub-module, respectively, ranging from 1 to 255 and 1 to 15.
  • FIG. 8 is a schematic diagram of a functional module of a third embodiment of an embedded system memory statistic apparatus according to the present invention.
  • the embedded system memory statistic apparatus further includes:
  • the creating module 50 is configured to create a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, where The initial values of the use status information corresponding to each of the identification numbers are all unused.
  • a one-to-one correspondence is established between the identification number, the memory information of the memory block represented by the identification number, and the usage status information of the memory block represented by the identification number, so that the system according to the usage status information The corresponding identification number and memory information can be queried.
  • the foregoing correspondence relationship is represented by the foregoing memory management header structure, where the memory management header structure includes an identification number field configured to record each of the identification numbers, and a memory information field configured to record memory information corresponding to each of the identification numbers. And a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and recording the memory information corresponding to each of the identification numbers by recording each of the identification numbers into the identification number field In the memory information field, the usage status information of each block of memory corresponding to each of the identification numbers is recorded into the usage status field, wherein each of the identification numbers recorded in the memory management header structure Forming a one-to-one correspondence between the memory information corresponding to the identification number and the usage status information of the memory corresponding to the identification number, so that the system can obtain the application of the embedded system by querying the memory management header structure. Occupied memory, thus further effectively reducing the memory space occupied by data set to record memory occupancy Reducing the overhead of memory space, thereby increasing the memory available to applications in
  • FIG. 9 is a schematic diagram of a refinement function module of the statistic module of FIG. 6.
  • the statistic module 30 includes:
  • the searching unit 31 is configured to search, in the correspondence relationship, usage status information that is currently in a used state;
  • the usage status information currently set to the used status is searched for.
  • the obtaining unit 32 is configured to acquire corresponding memory information in the correspondence relationship according to the usage state information obtained by the searching;
  • the memory status information corresponding to the usage status information is searched in the memory management header structure, that is, the current usage status is obtained. State memory information.
  • the statistic unit 33 is configured to acquire, according to the acquired memory information, a memory occupied by an application currently running by the embedded system.
  • the memory information obtained in the obtaining unit 32 is counted, and since the memory information includes the memory size, Therefore, by superimposing the memory size represented by each memory information, the memory occupied by the currently running application of the embedded system can be obtained.
  • FIG. 10 is the embedding of the present invention.
  • the function module of the fourth embodiment of the system memory statistics device in one or all embodiments of the present invention, the embedded system memory statistics device further includes:
  • the obtaining module 60 is configured to obtain the corresponding identification number and memory information in the corresponding relationship according to the usage state information obtained by the current search after every preset time;
  • the sending module 70 is configured to send the usage status information obtained by the current search and the identification number and the memory information obtained according to the usage status information obtained by the searching to the preset storage module.
  • the preset time can be set according to actual needs.
  • the preset storage module can be a piece of memory in the embedded system or an external storage device, and can be set according to actual needs.
  • the usage status information in the used state obtained by the current search, the identification number corresponding to the usage status information, and the memory information are all sent to the preset storage module.
  • the embedded system may be considered to have a memory leak and needs to be processed in time.
  • the statistical information of the memory in the used state is periodically sent to the preset storage module, so that the user can obtain the current memory usage of the embedded system by viewing the statistical information in the preset storage module, and Determine if there is a memory leak in the current embedded system.
  • the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware, but in many cases, the former is A better implementation.
  • the technical solution of the present invention which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a storage medium (such as ROM/RAM, disk,
  • the optical disc includes a number of instructions for causing a terminal device (which may be a cell phone, a computer, a server, or a network device, etc.) to perform the methods described in various embodiments of the present invention.
  • Embodiments of the present invention also provide a storage medium.
  • the foregoing storage medium may include, but not limited to, a USB flash drive, a Read-Only Memory (ROM), a Random Access Memory (RAM), a mobile hard disk, and a magnetic memory.
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • a mobile hard disk a magnetic memory.
  • modules or steps of the present invention described above can be implemented by a general-purpose computing device that can be centralized on a single computing device or distributed across a network of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein. Perform the steps shown or described Alternatively, each of them may be fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof may be fabricated into a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software.
  • an embedded system memory statistics method and apparatus provided by an embodiment of the present invention have the following beneficial effects: when an application applies for a memory, it acquires a preset identification number corresponding to the memory requested by the application, and Setting the usage status information corresponding to the identification number to the used state; when the application releases the memory, acquiring the preset identification number corresponding to the memory released by the application, and using the usage status information corresponding to the identification number Set to an unused state; obtain the memory occupied by the application currently running by the embedded system according to the flag number corresponding to the usage state information currently set to the used state, and the identification number may adopt integer data, and the identification number is adopted.
  • the module-level information that can be recorded to the memory effectively reduces the memory space occupied by the data set to record the memory occupancy, which reduces the overhead of the memory space, thereby increasing the available memory of the application in the embedded system.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Disclosed is a method for an embedded system to count a memory. The method for an embedded system to count a memory comprises the steps of: when an application program applies for a memory, acquiring a preset identification number corresponding to the memory applied for by the application program, and setting use state information corresponding to the identification number as a used state; when the application program releases the memory, acquiring a preset identification number corresponding to the memory released by the application program, and setting use state information corresponding to the identification number as an unused state; and according to the identification number corresponding to the use state information currently set as the unused state, acquiring a memory occupied by the currently operating application program of the embedded system. Also disclosed is a device for an embedded system to count a memory. The present invention effectively reduces the memory space occupied by data set to record a memory occupation situation, and reduces the additional overhead of the memory space, thereby increasing the available memory of the application program in the embedded system.

Description

嵌入式系统内存统计方法及装置Embedded system memory statistical method and device 技术领域Technical field
本发明涉及嵌入式系统技术领域,尤其涉及一种嵌入式系统内存统计方法及装置。The present invention relates to the field of embedded system technologies, and in particular, to an embedded system memory statistical method and apparatus.
背景技术Background technique
目前,由于嵌入式系统具有可靠性和实时性等优点,嵌入式系统已广泛应用于各个领域。At present, embedded systems have been widely used in various fields due to their reliability and real-time performance.
内存是嵌入式系统的应用程序运行的主要场所,实时掌握嵌入式内存的使用情况对于嵌入式系统的运行效率是至关重要的。检测内存泄漏问题的关键在于能够在线获取内存使用的分布情况,即能够获取当前已使用内存被哪些程序占用。现有技术一般通过记录每一块内存申请的文件、行号和堆栈信息等来记录内存的使用情况,但是设置为记录内存申请的文件、行号和堆栈信息的数据所占用的内存较大,造成嵌入式系统中应用程序的可用内存过小。Memory is the main place for applications running in embedded systems. Real-time control of embedded memory usage is critical to the operational efficiency of embedded systems. The key to detecting memory leaks is the ability to get a distribution of memory usage online, that is, to get the programs that are currently occupied. The prior art generally records the memory usage by recording the file, line number, and stack information of each memory application, but the memory used to record the file, line number, and stack information of the memory application is large, resulting in a large memory. The available memory of the application in the embedded system is too small.
发明内容Summary of the invention
本发明实施例提供了一种嵌入式系统内存统计方法及装置,旨在至少解决设置为记录内存占用情况的数据占用内存空间较大的技术问题。The embodiment of the invention provides an embedded system memory statistics method and device, which aims to solve at least the technical problem that the data occupied by the recording memory occupation has a large memory space.
为了至少实现上述目的,本发明实施例提供了一种嵌入式系统内存统计方法,所述嵌入式系统内存统计方法包括以下步骤:In order to achieve at least the above object, an embodiment of the present invention provides an embedded system memory statistics method, where the embedded system memory statistics method includes the following steps:
在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;When the application applies for the memory, the preset identification number corresponding to the memory requested by the application is obtained, and the usage status information corresponding to the identification number is set to the used state;
在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;When the application releases the memory, the preset identification number corresponding to the memory released by the application is obtained, and the usage status information corresponding to the identification number is set to an unused state;
根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存。Obtaining the memory occupied by the currently running application of the embedded system according to the flag number corresponding to the usage status information currently set to the used state.
所述在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态的步骤以及所述在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态的步骤之前还包括:When the application applies for the memory, acquiring a preset identification number corresponding to the memory requested by the application, and setting the usage status information corresponding to the identification number to the used state, and releasing the in the application In the case of the memory, obtaining the preset identification number corresponding to the memory released by the application, and setting the usage status information corresponding to the identification number to the unused state before the step further includes:
根据预设定义规则对嵌入式系统的每块内存设置标识号。The identification number is set for each piece of memory of the embedded system according to a preset definition rule.
所述根据预设定义规则对嵌入式系统的每块内存设置标识号的步骤之后还包括:The step of setting an identification number for each piece of memory of the embedded system according to the preset definition rule further includes:
创建各所述标识号、与各所述标识号对应的内存信息、以及与各所述标识号对应的各块 内存的使用状态信息之间的一一对应关系,其中,与各所述标识号对应的使用状态信息的初始值均为未使用状态。Creating each of the identification numbers, memory information corresponding to each of the identification numbers, and each block corresponding to each of the identification numbers A one-to-one correspondence between the usage status information of the memory, wherein the initial values of the usage status information corresponding to each of the identification numbers are all unused.
所述根据当前设置为已使用状态的使用状态信息所对应的标识号获取所述嵌入式系统当前运行的应用程序所占用的内存的步骤包括:The step of acquiring the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage state information currently set to the used state includes:
在所述对应关系中查找当前处于已使用状态的使用状态信息;Finding the usage status information that is currently in the used state in the correspondence relationship;
根据查找获得的使用状态信息在所述对应关系中获取对应的内存信息;Acquiring corresponding memory information in the correspondence according to the usage status information obtained by the searching;
根据获取的内存信息获取所述嵌入式系统当前运行的应用程序所占用的内存。Obtaining memory occupied by an application currently running by the embedded system according to the obtained memory information.
所述根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存的步骤之后还包括:After the step of acquiring the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage status information currently set to the used state, the method further includes:
每隔预设时间后,根据当前查找获得的使用状态信息在所述对应关系中获取对应的标识号和内存信息;After the preset time, the corresponding identification number and the memory information are obtained in the corresponding relationship according to the usage status information obtained by the current search;
将当前查找获得的使用状态信息,以及根据所述查找获得的使用状态信息获取的标识号和内存信息发送至预设存储模块中。The usage status information obtained by the current search and the identification number and the memory information obtained according to the usage status information obtained by the search are sent to the preset storage module.
此外,为了至少实现上述目的,本发明实施例还提供一种嵌入式系统内存统计装置,所述嵌入式系统内存统计装置包括:In addition, in order to achieve at least the foregoing, the embodiment of the present invention further provides an embedded system memory statistics device, where the embedded system memory statistics device includes:
第一处理模块,设置为在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;The first processing module is configured to: when the application applies for the memory, obtain the preset identification number corresponding to the memory requested by the application, and set the usage status information corresponding to the identification number to the used state;
第二处理模块,设置为在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;The second processing module is configured to: when the application releases the memory, acquire a preset identification number corresponding to the memory released by the application, and set the usage status information corresponding to the identification number to an unused state;
统计模块,设置为根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存。The statistic module is configured to acquire the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage status information currently set to the used state.
所述嵌入式系统内存统计装置还包括:The embedded system memory statistics device further includes:
设置模块,设置为根据预设定义规则对嵌入式系统的每块内存设置标识号。The setting module is set to set an identification number for each piece of memory of the embedded system according to a preset definition rule.
所述嵌入式系统内存统计装置还包括:The embedded system memory statistics device further includes:
创建模块,设置为创建各所述标识号、与各所述标识号对应的内存信息、以及与各所述标识号对应的各块内存的使用状态信息之间的一一对应关系,其中,与各所述标识号对应的使用状态信息的初始值均为未使用状态。a creating a module, configured to create a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, where The initial values of the usage status information corresponding to each of the identification numbers are all unused.
所统计模块包括:The statistics module includes:
查找单元,设置为在所述对应关系中查找当前处于已使用状态的使用状态信息; a searching unit, configured to search, in the correspondence relationship, usage status information that is currently in a used state;
获取单元,设置为根据查找获得的使用状态信息在所述对应关系中获取对应的内存信息;An obtaining unit, configured to obtain corresponding memory information in the correspondence relationship according to the usage state information obtained by the searching;
统计单元,设置为根据获取的内存信息获取所述嵌入式系统当前运行的应用程序所占用的内存。The statistic unit is configured to obtain, according to the obtained memory information, a memory occupied by an application currently running by the embedded system.
所述嵌入式系统内存统计装置还包括:The embedded system memory statistics device further includes:
获取模块,设置为在每隔预设时间后,根据当前查找获得的使用状态信息在所述对应关系中获取对应的标识号和内存信息;Obtaining a module, configured to obtain a corresponding identification number and memory information in the corresponding relationship according to usage state information obtained by the current search after each preset time;
发送模块,设置为将当前查找获得的使用状态信息,以及根据所述查找获得的使用状态信息获取的标识号和内存信息发送至预设存储模块中。The sending module is configured to send the usage status information obtained by the current search, and the identification number and the memory information obtained according to the usage status information obtained by the searching to the preset storage module.
本发明实施例提供的嵌入式系统内存统计方法及装置,在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存,标识号可采用整型数据,通过标识号就能够记录到内存的模块级别信息,有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。The embedded system memory statistics method and device provided by the embodiment of the present invention acquires a preset identification number corresponding to the memory applied by the application when the application applies for the memory, and sets the usage status information corresponding to the identification number. The used state; when the application releases the memory, obtains the preset identification number corresponding to the memory released by the application, and sets the usage status information corresponding to the identification number to an unused state; according to the current setting, Obtaining the memory occupied by the application currently running by the embedded system by using the flag number corresponding to the usage status information of the state, and the identification number may be an integer type data, and the module level information of the memory can be recorded by the identification number, effectively Reduces the memory space occupied by data set to record memory occupancy, reducing the overhead of memory space, thereby increasing the available memory of applications in embedded systems.
附图说明DRAWINGS
图1为本发明嵌入式系统内存统计方法第一实施例的流程示意图;1 is a schematic flow chart of a first embodiment of an embedded system memory statistical method according to the present invention;
图2为本发明嵌入式系统内存统计方法第二实施例的流程示意图;2 is a schematic flow chart of a second embodiment of an embedded system memory statistical method according to the present invention;
图3为本发明嵌入式系统内存统计方法第三实施例的流程示意图;3 is a schematic flowchart of a third embodiment of an embedded system memory statistical method according to the present invention;
图4为图1中步骤S30的细化流程示意图;4 is a schematic diagram of a refinement process of step S30 in FIG. 1;
图5为本发明嵌入式内存统计方法第四实施例的流程示意图;5 is a schematic flowchart of a fourth embodiment of an embedded memory statistics method according to the present invention;
图6为本发明嵌入式系统内存统计装置第一实施例的功能模块示意图;6 is a schematic diagram of functional modules of a first embodiment of an embedded system memory statistical device according to the present invention;
图7为本发明嵌入式系统内存统计装置第二实施例的功能模块示意图;7 is a schematic diagram of functional modules of a second embodiment of an embedded system memory statistics apparatus according to the present invention;
图8为本发明嵌入式系统内存统计装置第三实施例的功能模块示意图;8 is a schematic diagram of functional modules of a third embodiment of an embedded system memory statistical device according to the present invention;
图9为图6中统计模块的细化功能模块示意图;9 is a schematic diagram of a refinement function module of the statistical module in FIG. 6;
图10为本发明嵌入式系统内存统计装置第四实施例的功能模块示意图。 FIG. 10 is a schematic diagram of functional modules of a fourth embodiment of an embedded system memory statistics apparatus according to the present invention.
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The implementation, functional features, and advantages of the present invention will be further described in conjunction with the embodiments.
具体实施方式detailed description
应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。It is understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
本发明实施例提供一种嵌入式系统内存统计方法。Embodiments of the present invention provide an embedded system memory statistics method.
参照图1,图1为本发明嵌入式系统内存统计方法第一实施例的流程示意图。Referring to FIG. 1, FIG. 1 is a schematic flowchart diagram of a first embodiment of an embedded system memory statistical method according to the present invention.
在一实施例中,该嵌入式系统内存统计方法包括以下步骤:In an embodiment, the embedded system memory statistical method comprises the following steps:
步骤S10,在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;In step S10, when the application applies for the memory, the preset identification number corresponding to the memory requested by the application is obtained, and the usage status information corresponding to the identification number is set to the used state;
步骤S20,在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;In step S20, when the application releases the memory, the preset identification number corresponding to the memory released by the application is obtained, and the usage status information corresponding to the identification number is set to an unused state;
在本实施例中,标识号可以根据实际需要进行设置,只要能够使得每一标识号能够表示一块内存即可。例如,标识号可以采用一整型数据来设置。In this embodiment, the identification number can be set according to actual needs, as long as each identification number can be made to represent a piece of memory. For example, the identification number can be set using an integer type of data.
优选地,在应用程序申请或释放内存之前,先创建内存管理头结构(或采用操作系统中的内存管理头结构),所述内存管理头结构包括设置为记录各所述标识号的标识号字段、设置为记录各所述标识号对应的内存信息的内存信息字段和设置为记录各所述标识号对应的各块内存的使用状态信息的使用状态字段;然后将各所述标识号记录到所述标识号字段中,将各所述标识号对应的内存信息记录到所述内存信息字段中,将各所述标识号对应的各块内存的使用状态信息记录到所述使用状态字段中,其中,在所述内存管理头结构中记录的每一所述标识号、与该标识号对应的内存信息、以及与该标识号对应的内存的使用状态信息之间形成一一对应关系。其中,内存信息可以表示内存的大小和位置。Preferably, before the application requests or releases the memory, the memory management header structure (or the memory management header structure in the operating system is used), and the memory management header structure includes an identification number field set to record each of the identification numbers. And a memory information field configured to record memory information corresponding to each of the identification numbers and a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and then recording each of the identification numbers to the location In the identifier number field, the memory information corresponding to each of the identifier numbers is recorded in the memory information field, and the usage status information of each block of the memory corresponding to the identifier number is recorded in the usage status field, where And forming a one-to-one correspondence between each of the identification number recorded in the memory management header structure, the memory information corresponding to the identification number, and the usage status information of the memory corresponding to the identification number. Among them, the memory information can represent the size and location of the memory.
在应用程序申请内存时,根据该应用程序所申请的内存,获取与申请的内存对应的标识号,然后再将与该标识号对应的使用状态信息设置为已使用状态。从而通过查询内存管理头结构中的使用状态字段即可获得当前对应的内存被占用的标识号。When the application applies for memory, according to the memory requested by the application, the identification number corresponding to the requested memory is obtained, and then the usage status information corresponding to the identification number is set to the used state. Therefore, by querying the usage status field in the memory management header structure, the current corresponding memory occupied identification number can be obtained.
在应用程序释放内存时,根据该应用程序所释放的内存,获取与释放的内存对应的标识号,然后再将与该标识号对应的使用状态信息设置为未使用状态。从而通过查询内存管理头结构中的使用状态字段即可获得当前对应的内存未被占用的标识号。When the application releases the memory, according to the memory released by the application, the identification number corresponding to the released memory is obtained, and then the usage status information corresponding to the identification number is set to the unused state. Therefore, by querying the usage status field in the memory management header structure, the identification number of the current corresponding memory that is not occupied can be obtained.
步骤S30,根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存。Step S30: Acquire a memory occupied by an application currently running by the embedded system according to a flag number corresponding to the usage state information currently set to the used state.
当需要统计嵌入式系统当前运行的应用程序所占有的内存时,首先查询上述内存管理头结构中所有当前设置为已使用状态的使用状态信息,然后根据查询获得的使用状态信息在上述内存管理头结构中查找其对应的标识号,由于每一标识号可以代表一块内存,因此通过查 询获得的标识号即可获得嵌入式系统当前运行的应用程序所占有的内存;或者根据查询获得的使用状态信息在上述内存管理头结构中查找对应的内存信息,由于内存信息直接代表了内存地址和内存大小,因此通过查找获得的内存信息即可获得嵌入式系统当前运行的应用程序所占有的内存。When it is necessary to count the memory occupied by the currently running application of the embedded system, first query all the usage state information currently set to the used state in the memory management header structure, and then use the usage state information obtained according to the query in the above memory management header. Find the corresponding identification number in the structure, because each identification number can represent a piece of memory, so check The obtained identification number can obtain the memory occupied by the currently running application of the embedded system; or find the corresponding memory information in the above memory management header structure according to the usage status information obtained by the query, since the memory information directly represents the memory address And the size of the memory, so by looking up the obtained memory information, you can get the memory occupied by the application currently running by the embedded system.
本发明实施例提供的嵌入式系统内存统计方法,在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存,标识号可采用整型数据,通过标识号就能够记录到内存的模块级别信息,有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。The embedded system memory statistics method provided by the embodiment of the present invention obtains a preset identification number corresponding to the memory applied by the application when the application applies for the memory, and sets the usage status information corresponding to the identification number to The usage status; when the application releases the memory, obtains the preset identification number corresponding to the memory released by the application, and sets the usage status information corresponding to the identification number to an unused state; according to the current setting, the used state The identifier corresponding to the usage status information acquires the memory occupied by the application currently running by the embedded system, and the identification number can adopt integer data, and the module level information of the memory can be recorded by the identification number, which effectively reduces the The memory space set by the data set to record the memory occupancy reduces the overhead of the memory space, thereby increasing the available memory of the application in the embedded system.
进一步的,参照图2,图2为本发明嵌入式系统内存统计方法第二实施例的流程示意图,在本发明某一或所有实施例中,步骤S10和步骤S20之前还包括:Further, referring to FIG. 2, FIG. 2 is a schematic flowchart of a second embodiment of the method for calculating the memory of the embedded system according to the present invention. In some or all embodiments of the present invention, before step S10 and step S20, the method further includes:
步骤S40,根据预设定义规则对嵌入式系统的每块内存设置标识号。Step S40, setting an identification number for each piece of memory of the embedded system according to a preset definition rule.
在本实施例中,预设定义规则可以根据实际需要进行设置,只要能够使得每一标识号代表一块内存即可。优选地,所述标识号采用无符号整型数据,每一标识号可代表嵌入式系统的一块内存。具体地,本实施例以标识号采用32位整型数为例说明,标识号可分为三段,从高位字节开始前8个比特为第一段,表示内存使用者或释放者的一级模块,表示范围为0至255,0值保留;第二段为12个比特,表示内存使用者或释放者的二级模块,表示范围为1至4095;剩余的位于低字节的12个比特为第三段,表示内存使用者或释放者的三级模块,其中,三级模块还可以再分为两段,表示更加细化的模块内存使用位置,例如,第三段可以划分为4个比特和8个比特两段,分别表示子模块号和子模块内偏移,范围分别为1至255和1至15。通过采用整型数据来设置标识号,因此进一步有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。In this embodiment, the preset definition rules may be set according to actual needs, as long as each identification number can represent one piece of memory. Preferably, the identification number adopts unsigned integer data, and each identification number represents a piece of memory of the embedded system. Specifically, in this embodiment, the 32-bit integer number is used as an example, and the identification number can be divided into three segments. The first 8 bits from the high-order byte are the first segment, indicating one of the memory user or the releaser. Level module, indicating a range of 0 to 255, 0 value reserved; the second segment is 12 bits, indicating the secondary module of the memory user or releaser, indicating the range is 1 to 4095; the remaining 12 in the low byte The bit is the third segment, which represents the three-level module of the memory user or the releaser. The third-level module can be further divided into two segments, indicating a more refined module memory usage position. For example, the third segment can be divided into 4 segments. The bits and the two bits of the two bits represent the sub-module number and the offset within the sub-module, respectively, ranging from 1 to 255 and 1 to 15. By using integer data to set the identification number, the memory space occupied by the data set to record the memory occupancy is further effectively reduced, and the overhead of the memory space is reduced, thereby increasing the availability of applications in the embedded system. RAM.
进一步的,参照图3,图3为本发明嵌入式系统内存统计方法第三实施例的流程示意图,在本发明某一或所以实施例中,步骤S40之后还包括:Further, referring to FIG. 3, FIG. 3 is a schematic flowchart of a third embodiment of the method for calculating the memory of the embedded system according to the present invention. In a certain embodiment of the present invention, after step S40, the method further includes:
步骤S50,创建各所述标识号、与各所述标识号对应的内存信息、以及与各所述标识号对应的各块内存的使用状态信息之间的一一对应关系,其中,与各所述标识号对应的使用状态信息的初始值均为未使用状态。Step S50, creating a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, wherein The initial values of the usage status information corresponding to the identification number are all unused.
在本实施例中,通过将标识号、该标识号所代表的内存块的内存信息、该标识号所代表 的内存块的使用状态信息建立起一一对应关系,从而使得系统根据使用状态信息即可查询对应的标识号和内存信息。In this embodiment, by using the identification number, the memory information of the memory block represented by the identification number, and the identification number The usage status information of the memory block establishes a one-to-one correspondence, so that the system can query the corresponding identification number and memory information according to the usage status information.
优选地,可通过上述内存管理头结构来表示上述对应关系,内存管理头结构包括设置为记录各所述标识号的标识号字段、设置为记录各所述标识号对应的内存信息的内存信息字段和设置为记录各所述标识号对应的各块内存的使用状态信息的使用状态字段;通过将各所述标识号记录到所述标识号字段中,将各所述标识号对应的内存信息记录到所述内存信息字段中,将各所述标识号对应的各块内存的使用状态信息记录到所述使用状态字段中,其中,在所述内存管理头结构中记录的每一所述标识号、与该标识号对应的内存信息、以及与该标识号对应的内存的使用状态信息之间形成一一对应关系,从而系统通过查询该内存管理头结构即可获得该嵌入式系统的应用程序所占用的内存,因此进一步有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。Preferably, the foregoing correspondence relationship is represented by the foregoing memory management header structure, where the memory management header structure includes an identification number field configured to record each of the identification numbers, and a memory information field configured to record memory information corresponding to each of the identification numbers. And a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and recording the memory information corresponding to each of the identification numbers by recording each of the identification numbers into the identification number field In the memory information field, the usage status information of each block of memory corresponding to each of the identification numbers is recorded into the usage status field, wherein each of the identification numbers recorded in the memory management header structure Forming a one-to-one correspondence between the memory information corresponding to the identification number and the usage status information of the memory corresponding to the identification number, so that the system can obtain the application of the embedded system by querying the memory management header structure. Occupied memory, thus further effectively reducing the memory space occupied by data set to record memory occupancy Reducing the overhead of memory space, thereby increasing the memory available to applications in embedded systems.
进一步的,参照图4,图4为图1中步骤S30的细化流程示意图,在本发明实施例某一或所有实施例中,步骤S30包括:Further, referring to FIG. 4, FIG. 4 is a schematic diagram of a refinement process of step S30 in FIG. 1. In some or all embodiments of the embodiment of the present invention, step S30 includes:
步骤S31,在所述对应关系中查找当前处于已使用状态的使用状态信息;Step S31, searching for the usage status information that is currently in the used state in the corresponding relationship;
在本实施例中,通过查询上述内存管理头结构中的使用状态字段,即查找当前设置为已使用状态的使用状态信息。In this embodiment, by using the usage status field in the memory management header structure, the usage status information currently set to the used status is searched for.
步骤S32,根据查找获得的使用状态信息在所述对应关系中获取对应的内存信息;Step S32: Obtain corresponding memory information in the correspondence relationship according to the usage state information obtained by the searching;
在本实施例中,对于在步骤S31中查找获得的当前为已使用状态的使用状态信息,通过在上述内存管理头结构中查找与该使用状态信息对应的内存信息,即获得当前处于已使用状态的内存信息。In this embodiment, for the usage state information of the currently used state obtained by searching in step S31, by searching for the memory information corresponding to the usage state information in the memory management header structure, the current usage state is obtained. Memory information.
步骤S33,根据获取的内存信息获取所述嵌入式系统当前运行的应用程序所占用的内存。Step S33: Acquire, according to the acquired memory information, a memory occupied by an application currently running by the embedded system.
在本实施例中,对步骤S32中获得的内存信息进行统计,由于内存信息包括内存大小,因此通过将各个内存信息所代表的内存大小进行叠加,即可获得嵌入式系统当前运行的应用程序所占用的内存。In this embodiment, the memory information obtained in step S32 is counted. Since the memory information includes the memory size, the current running application program of the embedded system can be obtained by superimposing the memory size represented by each memory information. Occupied memory.
进一步的,为了进一步降低设置为记录内存占有情况的数据所占用的内存空间,降低内存空间的额外开销,从而增加嵌入式系统中的应用程序的可用内存,参照图5,图5为本发明嵌入式内存统计方法第四实施例的流程示意图,在本发明某一或所有实施例中,步骤S30之后还包括:Further, in order to further reduce the memory space occupied by the data set to record the memory occupation, the overhead of the memory space is reduced, thereby increasing the available memory of the application in the embedded system. Referring to FIG. 5, FIG. 5 is embedded in the present invention. The flowchart of the fourth embodiment of the method for calculating the memory, in one or all of the embodiments of the present invention, after step S30, the method further includes:
步骤S60,每隔预设时间后,根据当前查找获得的使用状态信息在所述对应关系中获取对应的标识号和内存信息; Step S60: After the preset time, obtain the corresponding identification number and memory information in the corresponding relationship according to the usage state information obtained by the current search.
步骤S70,将当前查找获得的使用状态信息,以及根据所述查找获得的使用状态信息获取的标识号和内存信息发送至预设存储模块中。In step S70, the usage status information obtained by the current search and the identification number and the memory information obtained according to the usage status information obtained by the search are sent to the preset storage module.
在本实施例中,预设时间可以根据实际需要进行设置。预设存储模块可以为嵌入式系统内的一块内存,也可以为外部存储设备,具体可以根据实际需要进行设置。In this embodiment, the preset time can be set according to actual needs. The preset storage module can be a piece of memory in the embedded system or an external storage device, and can be set according to actual needs.
每隔预设时间时,则将当前查找获得的处于已使用状态的使用状态信息、与该使用状态信息对应的标识号和内存信息均发送至上述预设存储模块中。At the preset time, the usage status information in the used state obtained by the current search, the identification number corresponding to the usage status information, and the memory information are all sent to the preset storage module.
若预设存储设备持续接收到某一标识号的次数持续增加,或者大于某一预设数值时,则可认为所述嵌入式系统出现了内存泄漏情况,需要及时处理。If the number of times that the preset storage device continues to receive an identification number continues to increase, or is greater than a certain preset value, the embedded system may be considered to have a memory leak and needs to be processed in time.
本实施例通过定期地将处于已使用状态的内存的统计信息发送至预设存储模块中,从而用户可以通过查看预设存储模块中的统计信息即可获得嵌入式系统当前内存占用情况,并可判断当前嵌入式系统是否出现了内存泄漏情况。In this embodiment, the statistical information of the memory in the used state is periodically sent to the preset storage module, so that the user can obtain the current memory usage of the embedded system by viewing the statistical information in the preset storage module, and Determine if there is a memory leak in the current embedded system.
本发明实施例进一步提供一种嵌入式系统内存统计装置。The embodiment of the invention further provides an embedded system memory statistics device.
参照图6,图6为本发明嵌入式系统内存统计装置第一实施例的功能模块示意图,6 is a schematic diagram of functional modules of a first embodiment of an embedded system memory statistical device according to the present invention.
在一实施例中,该嵌入式系统内存统计装置包括:In an embodiment, the embedded system memory statistics device comprises:
第一处理模块10,设置为在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;The first processing module 10 is configured to: when the application applies for the memory, obtain the preset identification number corresponding to the memory requested by the application, and set the usage status information corresponding to the identification number to the used state;
第二处理模块20,设置为在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;The second processing module 20 is configured to: when the application releases the memory, acquire an preset identification number corresponding to the memory released by the application, and set the usage status information corresponding to the identification number to an unused state;
在本实施例中,标识号可以根据实际需要进行设置,只要能够使得每一标识号能够表示一块内存即可。例如,标识号可以采用一整型数据来设置。In this embodiment, the identification number can be set according to actual needs, as long as each identification number can be made to represent a piece of memory. For example, the identification number can be set using an integer type of data.
优选地,在应用程序申请或释放内存之前,先创建内存管理头结构(或采用操作系统中的内存管理头结构),所述内存管理头结构包括设置为记录各所述标识号的标识号字段、设置为记录各所述标识号对应的内存信息的内存信息字段和设置为记录各所述标识号对应的各块内存的使用状态信息的使用状态字段;然后将各所述标识号记录到所述标识号字段中,将各所述标识号对应的内存信息记录到所述内存信息字段中,将各所述标识号对应的各块内存的使用状态信息记录到所述使用状态字段中,其中,在所述内存管理头结构中记录的每一所述标识号、与该标识号对应的内存信息、以及与该标识号对应的内存的使用状态信息之间形成一一对应关系。其中,内存信息可以表示内存的大小和位置。Preferably, before the application requests or releases the memory, the memory management header structure (or the memory management header structure in the operating system is used), and the memory management header structure includes an identification number field set to record each of the identification numbers. And a memory information field configured to record memory information corresponding to each of the identification numbers and a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and then recording each of the identification numbers to the location In the identifier number field, the memory information corresponding to each of the identifier numbers is recorded in the memory information field, and the usage status information of each block of the memory corresponding to the identifier number is recorded in the usage status field, where And forming a one-to-one correspondence between each of the identification number recorded in the memory management header structure, the memory information corresponding to the identification number, and the usage status information of the memory corresponding to the identification number. Among them, the memory information can represent the size and location of the memory.
在应用程序申请内存时,根据该应用程序所申请的内存,获取与申请的内存对应的标识号,然后再将与该标识号对应的使用状态信息设置为已使用状态。从而通过查询内存管理头结构中的使用状态字段即可获得当前对应的内存被占用的标识号。 When the application applies for memory, according to the memory requested by the application, the identification number corresponding to the requested memory is obtained, and then the usage status information corresponding to the identification number is set to the used state. Therefore, by querying the usage status field in the memory management header structure, the current corresponding memory occupied identification number can be obtained.
在应用程序释放内存时,根据该应用程序所释放的内存,获取与释放的内存对应的标识号,然后再将与该标识号对应的使用状态信息设置为未使用状态。从而通过查询内存管理头结构中的使用状态字段即可获得当前对应的内存未被占用的标识号。When the application releases the memory, according to the memory released by the application, the identification number corresponding to the released memory is obtained, and then the usage status information corresponding to the identification number is set to the unused state. Therefore, by querying the usage status field in the memory management header structure, the identification number of the current corresponding memory that is not occupied can be obtained.
统计模块30,设置为根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存。The statistic module 30 is configured to obtain the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage status information currently set to the used state.
当需要统计嵌入式系统当前运行的应用程序所占有的内存时,首先查询上述内存管理头结构中所有当前设置为已使用状态的使用状态信息,然后根据查询获得的使用状态信息在上述内存管理头结构中查找其对应的标识号,由于每一标识号可以代表一块内存,因此通过查询获得的标识号即可获得嵌入式系统当前运行的应用程序所占有的内存;或者根据查询获得的使用状态信息在上述内存管理头结构中查找对应的内存信息,由于内存信息直接代表了内存地址和内存大小,因此通过查找获得的内存信息即可获得嵌入式系统当前运行的应用程序所占有的内存。When it is necessary to count the memory occupied by the currently running application of the embedded system, first query all the usage state information currently set to the used state in the memory management header structure, and then use the usage state information obtained according to the query in the above memory management header. Find the corresponding identification number in the structure. Since each identification number can represent a piece of memory, the identification number obtained by the query can obtain the memory occupied by the application currently running by the embedded system; or the usage status information obtained according to the query. In the above memory management header structure, the corresponding memory information is searched. Since the memory information directly represents the memory address and the memory size, the memory occupied by the application currently running by the embedded system can be obtained by searching the obtained memory information.
本发明实施例提供的嵌入式系统内存统计装置,在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存,标识号可采用整型数据,通过标识号就能够记录到内存的模块级别信息,有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。The embedded system memory statistics device provided by the embodiment of the present invention obtains a preset identification number corresponding to the memory requested by the application when the application applies for the memory, and sets the usage status information corresponding to the identification number to The usage status; when the application releases the memory, obtains the preset identification number corresponding to the memory released by the application, and sets the usage status information corresponding to the identification number to an unused state; according to the current setting, the used state The identifier corresponding to the usage status information acquires the memory occupied by the application currently running by the embedded system, and the identification number can adopt integer data, and the module level information of the memory can be recorded by the identification number, which effectively reduces the The memory space set by the data set to record the memory occupancy reduces the overhead of the memory space, thereby increasing the available memory of the application in the embedded system.
进一步的,参照图7,图7为本发明嵌入式系统内存统计装置第二实施例的功能模块示意图,在本发明某一或所有实施例中,所述嵌入式系统内存统计装置还包括:Further, referring to FIG. 7, FIG. 7 is a schematic diagram of a functional module of a second embodiment of an embedded system memory statistic apparatus according to the present invention. In one or all embodiments of the present invention, the embedded system memory statistic apparatus further includes:
设置模块40,设置为根据预设定义规则对嵌入式系统的每块内存设置标识号。The setting module 40 is configured to set an identification number for each piece of memory of the embedded system according to a preset definition rule.
在本实施例中,预设定义规则可以根据实际需要进行设置,只要能够使得每一标识号代表一块内存即可。优选地,所述标识号采用无符号整型数据,每一标识号可代表嵌入式系统的一块内存。具体地,本实施例以标识号采用32位整型数为例说明,标识号可分为三段,从高位字节开始前8个比特为第一段,表示内存使用者或释放者的一级模块,表示范围为0至255,0值保留;第二段为12个比特,表示内存使用者或释放者的二级模块,表示范围为1至4095;剩余的位于低字节的12个比特为第三段,表示内存使用者或释放者的三级模块,其中,三级模块还可以再分为两段,表示更加细化的模块内存使用位置,例如,第三段可以划分为4个比特和8个比特两段,分别表示子模块号和子模块内偏移,范围分别为1至255和1至15。通过采用整型数据来设置标识号,因此进一步有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。 In this embodiment, the preset definition rules may be set according to actual needs, as long as each identification number can represent one piece of memory. Preferably, the identification number adopts unsigned integer data, and each identification number represents a piece of memory of the embedded system. Specifically, in this embodiment, the 32-bit integer number is used as an example, and the identification number can be divided into three segments. The first 8 bits from the high-order byte are the first segment, indicating one of the memory user or the releaser. Level module, indicating a range of 0 to 255, 0 value reserved; the second segment is 12 bits, indicating the secondary module of the memory user or releaser, indicating the range is 1 to 4095; the remaining 12 in the low byte The bit is the third segment, which represents the three-level module of the memory user or the releaser. The third-level module can be further divided into two segments, indicating a more refined module memory usage position. For example, the third segment can be divided into 4 segments. The bits and the two bits of the two bits represent the sub-module number and the offset within the sub-module, respectively, ranging from 1 to 255 and 1 to 15. By using integer data to set the identification number, the memory space occupied by the data set to record the memory occupancy is further effectively reduced, and the overhead of the memory space is reduced, thereby increasing the availability of applications in the embedded system. RAM.
进一步的,参照图8,图8为本发明嵌入式系统内存统计装置第三实施例的功能模块示意图,在本发明某一或所以实施例中,所述嵌入式系统内存统计装置还包括:Further, referring to FIG. 8, FIG. 8 is a schematic diagram of a functional module of a third embodiment of an embedded system memory statistic apparatus according to the present invention. In an embodiment of the present invention, the embedded system memory statistic apparatus further includes:
创建模块50,设置为创建各所述标识号、与各所述标识号对应的内存信息、以及与各所述标识号对应的各块内存的使用状态信息之间的一一对应关系,其中,与各所述标识号对应的使用状态信息的初始值均为未使用状态。The creating module 50 is configured to create a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, where The initial values of the use status information corresponding to each of the identification numbers are all unused.
在本实施例中,通过将标识号、该标识号所代表的内存块的内存信息、该标识号所代表的内存块的使用状态信息建立起一一对应关系,从而使得系统根据使用状态信息即可查询对应的标识号和内存信息。In this embodiment, a one-to-one correspondence is established between the identification number, the memory information of the memory block represented by the identification number, and the usage status information of the memory block represented by the identification number, so that the system according to the usage status information The corresponding identification number and memory information can be queried.
优选地,可通过上述内存管理头结构来表示上述对应关系,内存管理头结构包括设置为记录各所述标识号的标识号字段、设置为记录各所述标识号对应的内存信息的内存信息字段和设置为记录各所述标识号对应的各块内存的使用状态信息的使用状态字段;通过将各所述标识号记录到所述标识号字段中,将各所述标识号对应的内存信息记录到所述内存信息字段中,将各所述标识号对应的各块内存的使用状态信息记录到所述使用状态字段中,其中,在所述内存管理头结构中记录的每一所述标识号、与该标识号对应的内存信息、以及与该标识号对应的内存的使用状态信息之间形成一一对应关系,从而系统通过查询该内存管理头结构即可获得该嵌入式系统的应用程序所占用的内存,因此进一步有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。Preferably, the foregoing correspondence relationship is represented by the foregoing memory management header structure, where the memory management header structure includes an identification number field configured to record each of the identification numbers, and a memory information field configured to record memory information corresponding to each of the identification numbers. And a usage status field configured to record usage status information of each block of memory corresponding to each of the identification numbers; and recording the memory information corresponding to each of the identification numbers by recording each of the identification numbers into the identification number field In the memory information field, the usage status information of each block of memory corresponding to each of the identification numbers is recorded into the usage status field, wherein each of the identification numbers recorded in the memory management header structure Forming a one-to-one correspondence between the memory information corresponding to the identification number and the usage status information of the memory corresponding to the identification number, so that the system can obtain the application of the embedded system by querying the memory management header structure. Occupied memory, thus further effectively reducing the memory space occupied by data set to record memory occupancy Reducing the overhead of memory space, thereby increasing the memory available to applications in embedded systems.
进一步的,参照图9,图9为图6中统计模块的细化功能模块示意图,在本发明某一或所有实施例中,所统计模块30包括:Further, referring to FIG. 9, FIG. 9 is a schematic diagram of a refinement function module of the statistic module of FIG. 6. In some or all embodiments of the present invention, the statistic module 30 includes:
查找单元31,设置为在所述对应关系中查找当前处于已使用状态的使用状态信息;The searching unit 31 is configured to search, in the correspondence relationship, usage status information that is currently in a used state;
在本实施例中,通过查询上述内存管理头结构中的使用状态字段,即查找当前设置为已使用状态的使用状态信息。In this embodiment, by using the usage status field in the memory management header structure, the usage status information currently set to the used status is searched for.
获取单元32,设置为根据查找获得的使用状态信息在所述对应关系中获取对应的内存信息;The obtaining unit 32 is configured to acquire corresponding memory information in the correspondence relationship according to the usage state information obtained by the searching;
在本实施例中,对于在查找单元31中查找获得的当前为已使用状态的使用状态信息,通过在上述内存管理头结构中查找与该使用状态信息对应的内存信息,即获得当前处于已使用状态的内存信息。In this embodiment, for the usage status information that is currently used in the search unit 31, the memory status information corresponding to the usage status information is searched in the memory management header structure, that is, the current usage status is obtained. State memory information.
统计单元33,设置为根据获取的内存信息获取所述嵌入式系统当前运行的应用程序所占用的内存。The statistic unit 33 is configured to acquire, according to the acquired memory information, a memory occupied by an application currently running by the embedded system.
在本实施例中,对获取单元32中获得的内存信息进行统计,由于内存信息包括内存大小, 因此通过将各个内存信息所代表的内存大小进行叠加,即可获得嵌入式系统当前运行的应用程序所占用的内存。In this embodiment, the memory information obtained in the obtaining unit 32 is counted, and since the memory information includes the memory size, Therefore, by superimposing the memory size represented by each memory information, the memory occupied by the currently running application of the embedded system can be obtained.
进一步的,为了进一步降低设置为记录内存占有情况的数据所占用的内存空间,降低内存空间的额外开销,从而增加嵌入式系统中的应用程序的可用内存,参照图10,图10为本发明嵌入式系统内存统计装置第四实施例的功能模块示意图,在本发明某一或所有实施例中,所述嵌入式系统内存统计装置还包括:Further, in order to further reduce the memory space occupied by the data set to record the memory occupation, the overhead of the memory space is reduced, thereby increasing the available memory of the application in the embedded system. Referring to FIG. 10, FIG. 10 is the embedding of the present invention. The function module of the fourth embodiment of the system memory statistics device, in one or all embodiments of the present invention, the embedded system memory statistics device further includes:
获取模块60,设置为在每隔预设时间后,根据当前查找获得的使用状态信息在所述对应关系中获取对应的标识号和内存信息;The obtaining module 60 is configured to obtain the corresponding identification number and memory information in the corresponding relationship according to the usage state information obtained by the current search after every preset time;
发送模块70,设置为将当前查找获得的使用状态信息,以及根据所述查找获得的使用状态信息获取的标识号和内存信息发送至预设存储模块中。The sending module 70 is configured to send the usage status information obtained by the current search and the identification number and the memory information obtained according to the usage status information obtained by the searching to the preset storage module.
在本实施例中,预设时间可以根据实际需要进行设置。预设存储模块可以为嵌入式系统内的一块内存,也可以为外部存储设备,具体可以根据实际需要进行设置。In this embodiment, the preset time can be set according to actual needs. The preset storage module can be a piece of memory in the embedded system or an external storage device, and can be set according to actual needs.
每隔预设时间时,则将当前查找获得的处于已使用状态的使用状态信息、与该使用状态信息对应的标识号和内存信息均发送至上述预设存储模块中。At the preset time, the usage status information in the used state obtained by the current search, the identification number corresponding to the usage status information, and the memory information are all sent to the preset storage module.
若预设存储设备持续接收到某一标识号的次数持续增加,或者大于某一预设数值时,则可认为所述嵌入式系统出现了内存泄漏情况,需要及时处理。If the number of times that the preset storage device continues to receive an identification number continues to increase, or is greater than a certain preset value, the embedded system may be considered to have a memory leak and needs to be processed in time.
本实施例通过定期地将处于已使用状态的内存的统计信息发送至预设存储模块中,从而用户可以通过查看预设存储模块中的统计信息即可获得嵌入式系统当前内存占用情况,并可判断当前嵌入式系统是否出现了内存泄漏情况。In this embodiment, the statistical information of the memory in the used state is periodically sent to the preset storage module, so that the user can obtain the current memory usage of the embedded system by viewing the statistical information in the preset storage module, and Determine if there is a memory leak in the current embedded system.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware, but in many cases, the former is A better implementation. Based on such understanding, the technical solution of the present invention, which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a storage medium (such as ROM/RAM, disk, The optical disc includes a number of instructions for causing a terminal device (which may be a cell phone, a computer, a server, or a network device, etc.) to perform the methods described in various embodiments of the present invention.
本发明的实施例还提供了一种存储介质。可选地,在本实施例中,上述存储介质可以包括但不限于:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。Embodiments of the present invention also provide a storage medium. Optionally, in this embodiment, the foregoing storage medium may include, but not limited to, a USB flash drive, a Read-Only Memory (ROM), a Random Access Memory (RAM), a mobile hard disk, and a magnetic memory. A variety of media that can store program code, such as a disc or a disc.
显然,本领域的技术人员应该明白,上述的本发明的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步 骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。It will be apparent to those skilled in the art that the various modules or steps of the present invention described above can be implemented by a general-purpose computing device that can be centralized on a single computing device or distributed across a network of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein. Perform the steps shown or described Alternatively, each of them may be fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof may be fabricated into a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software.
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only the preferred embodiments of the present invention, and are not intended to limit the scope of the invention, and the equivalent structure or equivalent process transformations made by the description of the present invention and the drawings are directly or indirectly applied to other related technical fields. The same is included in the scope of patent protection of the present invention.
工业实用性Industrial applicability
如上所述,本发明实施例提供的一种嵌入式系统内存统计方法及装置,具有以下有益效果:在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存,标识号可采用整型数据,通过标识号就能够记录到内存的模块级别信息,有效地降低了设置为记录内存占有情况的数据所占用的内存空间,降低了内存空间的额外开销,从而增加了嵌入式系统中的应用程序的可用内存。 As described above, an embedded system memory statistics method and apparatus provided by an embodiment of the present invention have the following beneficial effects: when an application applies for a memory, it acquires a preset identification number corresponding to the memory requested by the application, and Setting the usage status information corresponding to the identification number to the used state; when the application releases the memory, acquiring the preset identification number corresponding to the memory released by the application, and using the usage status information corresponding to the identification number Set to an unused state; obtain the memory occupied by the application currently running by the embedded system according to the flag number corresponding to the usage state information currently set to the used state, and the identification number may adopt integer data, and the identification number is adopted. The module-level information that can be recorded to the memory effectively reduces the memory space occupied by the data set to record the memory occupancy, which reduces the overhead of the memory space, thereby increasing the available memory of the application in the embedded system.

Claims (10)

  1. 一种嵌入式系统内存统计方法,所述嵌入式系统内存统计方法包括以下步骤:An embedded system memory statistical method, the embedded system memory statistical method comprising the following steps:
    在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;When the application applies for the memory, the preset identification number corresponding to the memory requested by the application is obtained, and the usage status information corresponding to the identification number is set to the used state;
    在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;When the application releases the memory, the preset identification number corresponding to the memory released by the application is obtained, and the usage status information corresponding to the identification number is set to an unused state;
    根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存。Obtaining the memory occupied by the currently running application of the embedded system according to the flag number corresponding to the usage status information currently set to the used state.
  2. 如权利要求1所述的嵌入式系统内存统计方法,其中,所述在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态的步骤以及所述在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态的步骤之前还包括:The embedded system memory statistical method according to claim 1, wherein when the application applies for the memory, the preset identification number corresponding to the memory requested by the application is obtained, and the use corresponding to the identification number is used. The step of setting the status information to the used state and the obtaining the preset identification number corresponding to the memory released by the application when the application releases the memory, and setting the usage status information corresponding to the identification number to unused The steps of the status also include:
    根据预设定义规则对嵌入式系统的每块内存设置标识号。The identification number is set for each piece of memory of the embedded system according to a preset definition rule.
  3. 如权利要求2所述的嵌入式系统内存统计方法,其中,所述根据预设定义规则对嵌入式系统的每块内存设置标识号的步骤之后还包括:The embedded system memory statistical method according to claim 2, wherein the step of setting an identification number for each block of the embedded system according to the preset definition rule further comprises:
    创建各所述标识号、与各所述标识号对应的内存信息、以及与各所述标识号对应的各块内存的使用状态信息之间的一一对应关系,其中,与各所述标识号对应的使用状态信息的初始值均为未使用状态。Creating a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, wherein each of the identification numbers The initial values of the corresponding usage status information are all unused.
  4. 如权利要求3所述的嵌入式系统内存统计方法,其中,所述根据当前设置为已使用状态的使用状态信息所对应的标识号获取所述嵌入式系统当前运行的应用程序所占用的内存的步骤包括:The embedded system memory statistical method according to claim 3, wherein the acquiring the memory occupied by the currently running application of the embedded system according to the identification number corresponding to the usage state information currently set to the used state The steps include:
    在所述对应关系中查找当前处于已使用状态的使用状态信息;Finding the usage status information that is currently in the used state in the correspondence relationship;
    根据查找获得的使用状态信息在所述对应关系中获取对应的内存信息;Acquiring corresponding memory information in the correspondence according to the usage status information obtained by the searching;
    根据获取的内存信息获取所述嵌入式系统当前运行的应用程序所占用的内存。Obtaining memory occupied by an application currently running by the embedded system according to the obtained memory information.
  5. 如权利要求4所述的嵌入式系统内存统计方法,其中,所述根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存的步骤之后还包括: The embedded system memory statistical method according to claim 4, wherein the acquiring the memory occupied by the application currently running by the embedded system according to the flag number corresponding to the usage state information currently set to the used state After the step, it also includes:
    每隔预设时间后,根据当前查找获得的使用状态信息在所述对应关系中获取对应的标识号和内存信息;After the preset time, the corresponding identification number and the memory information are obtained in the corresponding relationship according to the usage status information obtained by the current search;
    将当前查找获得的使用状态信息,以及根据所述查找获得的使用状态信息获取的标识号和内存信息发送至预设存储模块中。The usage status information obtained by the current search and the identification number and the memory information obtained according to the usage status information obtained by the search are sent to the preset storage module.
  6. 一种嵌入式系统内存统计装置,所述嵌入式系统内存统计装置包括:An embedded system memory statistical device, the embedded system memory statistical device includes:
    第一处理模块,设置为在应用程序申请内存时,获取与该应用程序申请的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为已使用状态;The first processing module is configured to: when the application applies for the memory, obtain the preset identification number corresponding to the memory requested by the application, and set the usage status information corresponding to the identification number to the used state;
    第二处理模块,设置为在应用程序释放内存时,获取与该应用程序释放的内存所对应预设的标识号,并将与该标识号对应的使用状态信息设置为未使用状态;The second processing module is configured to: when the application releases the memory, acquire a preset identification number corresponding to the memory released by the application, and set the usage status information corresponding to the identification number to an unused state;
    统计模块,设置为根据当前设置为已使用状态的使用状态信息所对应的标志号获取所述嵌入式系统当前运行的应用程序所占用的内存。The statistic module is configured to acquire the memory occupied by the application currently running by the embedded system according to the identifier corresponding to the usage status information currently set to the used state.
  7. 如权利要求6所述的嵌入式系统内存统计装置,其中,所述嵌入式系统内存统计装置还包括:The embedded system memory statistics device of claim 6, wherein the embedded system memory statistics device further comprises:
    设置模块,设置为根据预设定义规则对嵌入式系统的每块内存设置标识号。The setting module is set to set an identification number for each piece of memory of the embedded system according to a preset definition rule.
  8. 如权利要求7所述的嵌入式系统内存统计装置,其中,所述嵌入式系统内存统计装置还包括:The embedded system memory statistics device of claim 7, wherein the embedded system memory statistics device further comprises:
    创建模块,设置为创建各所述标识号、与各所述标识号对应的内存信息、以及与各所述标识号对应的各块内存的使用状态信息之间的一一对应关系,其中,与各所述标识号对应的使用状态信息的初始值均为未使用状态。a creating a module, configured to create a one-to-one correspondence between each of the identification numbers, memory information corresponding to each of the identification numbers, and usage status information of each block of memory corresponding to each of the identification numbers, where The initial values of the usage status information corresponding to each of the identification numbers are all unused.
  9. 如权利要求8所述的嵌入式系统内存统计装置,其中,所统计模块包括:The embedded system memory statistics device of claim 8, wherein the statistical module comprises:
    查找单元,设置为在所述对应关系中查找当前处于已使用状态的使用状态信息;a searching unit, configured to search, in the correspondence relationship, usage status information that is currently in a used state;
    获取单元,设置为根据查找获得的使用状态信息在所述对应关系中获取对应的内存信息;An obtaining unit, configured to obtain corresponding memory information in the correspondence relationship according to the usage state information obtained by the searching;
    统计单元,设置为根据获取的内存信息获取所述嵌入式系统当前运行的应用程序所占用的内存。 The statistic unit is configured to obtain, according to the obtained memory information, a memory occupied by an application currently running by the embedded system.
  10. 如权利要求9所述的嵌入式系统内存统计装置,其中,所述嵌入式系统内存统计装置还包括:The embedded system memory statistics device of claim 9, wherein the embedded system memory statistics device further comprises:
    获取模块,设置为在每隔预设时间后,根据当前查找获得的使用状态信息在所述对应关系中获取对应的标识号和内存信息;Obtaining a module, configured to obtain a corresponding identification number and memory information in the corresponding relationship according to usage state information obtained by the current search after each preset time;
    发送模块,设置为将当前查找获得的使用状态信息,以及根据所述查找获得的使用状态信息获取的标识号和内存信息发送至预设存储模块中。 The sending module is configured to send the usage status information obtained by the current search, and the identification number and the memory information obtained according to the usage status information obtained by the searching to the preset storage module.
PCT/CN2015/087709 2014-11-26 2015-08-20 Method and device for embedded system to count memory WO2016082591A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410693337.5 2014-11-26
CN201410693337.5A CN105700952A (en) 2014-11-26 2014-11-26 Embedded system memory statistics method and apparatus

Publications (1)

Publication Number Publication Date
WO2016082591A1 true WO2016082591A1 (en) 2016-06-02

Family

ID=56073548

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/087709 WO2016082591A1 (en) 2014-11-26 2015-08-20 Method and device for embedded system to count memory

Country Status (2)

Country Link
CN (1) CN105700952A (en)
WO (1) WO2016082591A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111562986A (en) * 2020-05-11 2020-08-21 上海加糖科技有限公司 Memory allocation method and device, electronic equipment and computer readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1979428A (en) * 2005-12-08 2007-06-13 中兴通讯股份有限公司 System for automatically releasing applied programe module leaked memory in inlaid system
CN103176911A (en) * 2011-12-20 2013-06-26 陕西银河网电科技有限公司 Embedded type software security memory management method
US20130246732A1 (en) * 2012-03-14 2013-09-19 Phison Electronics Corp. Method of programming memory cells and reading data, memory controller and memory storage apparatus using the same

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5809558A (en) * 1994-09-29 1998-09-15 Intel Corporation Method and data storage system for storing data in blocks without file reallocation before erasure
US7260815B1 (en) * 2003-06-30 2007-08-21 Vmware, Inc. Method and apparatus for managing registers in a binary translator
CN1287290C (en) * 2003-07-15 2006-11-29 中兴通讯股份有限公司 Dynamic allocation method for non-buffering memory in embedded real-time operating system
CN101382916B (en) * 2007-09-06 2010-12-08 大唐移动通信设备有限公司 Method for managing embedded system memory
CN102495788B (en) * 2011-11-04 2015-02-25 北京星网锐捷网络技术有限公司 Internal storage counting method and device of embedded system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1979428A (en) * 2005-12-08 2007-06-13 中兴通讯股份有限公司 System for automatically releasing applied programe module leaked memory in inlaid system
CN103176911A (en) * 2011-12-20 2013-06-26 陕西银河网电科技有限公司 Embedded type software security memory management method
US20130246732A1 (en) * 2012-03-14 2013-09-19 Phison Electronics Corp. Method of programming memory cells and reading data, memory controller and memory storage apparatus using the same

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111562986A (en) * 2020-05-11 2020-08-21 上海加糖科技有限公司 Memory allocation method and device, electronic equipment and computer readable storage medium
CN111562986B (en) * 2020-05-11 2023-05-16 上海加糖科技有限公司 Memory allocation method, memory allocation device, electronic equipment and computer readable storage medium

Also Published As

Publication number Publication date
CN105700952A (en) 2016-06-22

Similar Documents

Publication Publication Date Title
CN109064345B (en) Message processing method, system and computer readable storage medium
US10331642B2 (en) Data storage method and apparatus
KR102099544B1 (en) Method and device for processing distribution of streaming data
WO2019144553A1 (en) Data storage method and apparatus, and storage medium
US20160142369A1 (en) Service addressing in distributed environment
CN109756528B (en) Frequency control method and device, equipment, storage medium and server
CN110232010A (en) A kind of alarm method, alarm server and monitoring server
US10474799B2 (en) Method and system for identifying a unique mobile device based on mobile device attribute changes over time
CN104765749A (en) Data storage method and device
EP2899649A1 (en) Data indexing method and device
SG11201707304RA (en) Data check method and storage system
EP3310093A1 (en) Traffic control method and apparatus
CN112328363B (en) Cloud hard disk mounting method and device
CN107515807B (en) Method and device for storing monitoring data
CN108399175B (en) Data storage and query method and device
JP2019504415A (en) Data storage service processing method and apparatus
CN111338888A (en) Data statistical method and device, electronic equipment and storage medium
CN108920326B (en) Method and device for determining time-consuming abnormity of system and electronic equipment
CN104778252A (en) Index storage method and index storage device
CN104391654A (en) Shared disk management method and system
JP5766346B2 (en) Method and apparatus for moving a software object in the background
WO2016082591A1 (en) Method and device for embedded system to count memory
CN106998436B (en) Video backup method and device
US20130247063A1 (en) Computing device and method for managing memory of virtual machines
CN104239307A (en) User information storage method and system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15863074

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15863074

Country of ref document: EP

Kind code of ref document: A1