Search

CN-121979670-A - Method for dynamically marking and multiplexing local memory in large-capacity storage in embedded system

CN121979670ACN 121979670 ACN121979670 ACN 121979670ACN-121979670-A

Abstract

A method for dynamically marking and multiplexing local memories in a large-capacity storage in an embedded system belongs to the technical field of software engineering. The invention can automatically identify and manage the existing fragmented memory through the dynamic marking memory technology, dynamically marks the newly opened memory block as idle or occupied according to the system requirement, does not generate memory fragments, and designs independent memory areas for the application of frequently applying and releasing the memory block by the upper layer. Meanwhile, the dynamic allocation method of the appointed idle memory can be reused in the system operation, so that unnecessary permanent memory occupation is avoided.

Inventors

  • XU YIHAN
  • WANG JING
  • PENG HANZHANG
  • YE YINGJIE
  • HU XUEMING

Assignees

  • 北京航天自动控制研究所

Dates

Publication Date
20260505
Application Date
20251229

Claims (10)

  1. 1. The method for dynamically marking and multiplexing the local memory in the mass storage in the embedded system is characterized by comprising the following steps: Opening up two independent and non-overlapping memory pools in the available memory or external memory space of the system, wherein the memory pools are respectively a linked list memory pool and a mark memory pool, and the linked list memory pool is used for storing a plurality of address segments which can be multiplexed and dynamically allocated, and the mark memory pool is used for marking states of the corresponding address space by taking bytes as units; the method comprises the steps of constructing two unidirectional circular linked lists, namely a space linked list and an occupied linked list, wherein the space linked list is used for managing all continuous address segments in idle states in a marked memory pool, and each node of the space linked list records the first address, the length and the state of the corresponding idle segment; Initializing the linked list memory pool and the marked memory pool, marking all address spaces of the marked memory pool as idle states, creating corresponding nodes in the idle linked list, and initializing the occupied linked list as empty; Responding to a memory application request of a user, traversing the idle linked list according to the byte length and the alignment mode of the request, selecting idle address segments meeting the conditions, marking corresponding parts of the idle address segments as occupied states, updating the idle linked list and the occupied linked list, and returning to an allocated head address; responding to a memory release request of a user, traversing the occupied linked list according to the released first address, finding out a corresponding occupied segment, marking the occupied segment as an idle state, and moving the occupied segment to the idle linked list through a corresponding node; after each memory application or release, ordering the nodes in the idle linked list according to the addresses, and merging adjacent idle address segments to reduce memory fragments; Counting the total number of bytes in the occupied state in the marked memory pool, starting warning when the number reaches a preset warning threshold, triggering system reset when the total size of the marked memory pool is exceeded, and emptying the two memory pools and reinitializing.
  2. 2. The method for dynamically marking and multiplexing local memory in embedded system according to claim 1, wherein the sizes of the linked list memory pool and the marked memory pool are in a preset proportional relationship, and the size of the linked list memory pool is smaller than the size of the marked memory pool.
  3. 3. The method for dynamically marking and multiplexing local memory in embedded system according to claim 2, wherein the predetermined proportional relationship is that the size of the linked list memory pool is 10 times of the size of the marked memory pool.
  4. 4. The method for dynamically marking and multiplexing local memories in embedded system according to claim 1, wherein the nodes of the idle linked list and the occupied linked list further comprise forward pointers and backward pointers pointing to neighboring nodes, so as to realize bidirectional traversal of the linked list and node maintenance.
  5. 5. The method for dynamically marking and multiplexing local memory in embedded system according to claim 1, wherein when the memory alignment mode requested by the user is not single byte alignment, after searching the nodes meeting the length requirement in the idle linked list, recalculating the head addresses after alignment, and dividing the chip space before alignment in the original nodes, wherein the chip space is inserted into the idle linked list as a new idle node.
  6. 6. The method for dynamically marking and multiplexing local memory in embedded system according to claim 1, wherein the recalculated aligned head address is MARKADDR _new= (MARKADDR + (UAlign-1))/UAlign × UAlign, wherein MARKADDR is the head address recorded by the original node, and UAlign is the number of aligned bytes specified by the user.
  7. 7. The method for dynamically marking and multiplexing local memory in an embedded system according to claim 1, wherein merging adjacent free address segments comprises: If the head addresses of the adjacent idle sections are the same, merging the adjacent idle sections into one section; If the end address of the previous idle segment is continuous with the head address of the next idle segment, the end addresses are combined into one segment.
  8. 8. The method for dynamically marking and multiplexing local memory in embedded system according to claim 1, wherein the warning threshold is the total size of the marked memory pool minus 4 bytes, the reset condition is the total number of occupied bytes greater than the total size of the marked memory pool, and when resetting, all data in the linked list memory pool and the marked memory pool are emptied and the initializing step is re-executed.
  9. 9. A computer readable storage medium storing a computer program, wherein the computer program when executed by a processor performs the steps of the method according to any one of claims 1 to 8.
  10. 10. An apparatus for dynamically marking and multiplexing local memory suitable for mass storage in an embedded system, comprising a memory, a processor and a computer program stored in said memory and executable on said processor, characterized in that the steps of the method according to any one of claims 1 to 8 are implemented when said computer program is executed by said processor.

Description

Method for dynamically marking and multiplexing local memory in large-capacity storage in embedded system Technical Field The invention relates to a method for dynamically marking and multiplexing local memories in a large-capacity storage in an embedded system, belonging to the technical field of software engineering. Background Based on the requirements of real-time performance and reliability of the embedded system, many embedded applications use their own memory management programs. Most of the existing dynamic application memory management schemes cannot solve the problem of memory fragmentation, and even if memory fragments can be avoided as much as possible, the management of a plurality of existing fragmented memories cannot be realized, so that the fusion and multiplexing of the fragmented memories are completed. Disclosure of Invention The invention solves the technical problems of overcoming the defects of the prior art, providing a method for dynamically marking and multiplexing local memory in large-capacity storage in an embedded system, realizing the management of the existing fragmented memory on the basis of meeting the dynamic use and release of the memory, and completing the fusion and multiplexing of the fragmented memory. The technical scheme of the invention is that the method for dynamically marking and multiplexing local memories in the mass storage in the embedded system comprises the following steps: Opening up two independent and non-overlapping memory pools in the available memory or external memory space of the system, wherein the memory pools are respectively a linked list memory pool and a mark memory pool, and the linked list memory pool is used for storing a plurality of address segments which can be multiplexed and dynamically allocated, and the mark memory pool is used for marking states of the corresponding address space by taking bytes as units; the method comprises the steps of constructing two unidirectional circular linked lists, namely a space linked list and an occupied linked list, wherein the space linked list is used for managing all continuous address segments in idle states in a marked memory pool, and each node of the space linked list records the first address, the length and the state of the corresponding idle segment; Initializing the linked list memory pool and the marked memory pool, marking all address spaces of the marked memory pool as idle states, creating corresponding nodes in the idle linked list, and initializing the occupied linked list as empty; Responding to a memory application request of a user, traversing the idle linked list according to the byte length and the alignment mode of the request, selecting idle address segments meeting the conditions, marking corresponding parts of the idle address segments as occupied states, updating the idle linked list and the occupied linked list, and returning to an allocated head address; responding to a memory release request of a user, traversing the occupied linked list according to the released first address, finding out a corresponding occupied segment, marking the occupied segment as an idle state, and moving the occupied segment to the idle linked list through a corresponding node; after each memory application or release, ordering the nodes in the idle linked list according to the addresses, and merging adjacent idle address segments to reduce memory fragments; Counting the total number of bytes in the occupied state in the marked memory pool, starting warning when the number reaches a preset warning threshold, triggering system reset when the total size of the marked memory pool is exceeded, and emptying the two memory pools and reinitializing. Further, the sizes of the linked list memory pool and the tag memory pool are in a preset proportional relationship, and the size of the linked list memory pool is smaller than that of the tag memory pool. Further, the preset proportion relation is that the size of the linked list memory pool is 10 times of that of the marked memory pool. Further, the nodes of the idle linked list and the occupied linked list further comprise forward pointers and backward pointers pointing to adjacent nodes, and the forward pointers and the backward pointers are used for realizing bidirectional traversal of the linked list and node maintenance. Further, when the memory alignment mode requested by the user is not single byte alignment, after searching the nodes meeting the length requirement in the idle linked list, recalculating the head addresses after alignment, and dividing the fragment space before alignment in the original nodes, wherein the fragment space is used as a new idle node to be inserted into the idle linked list. Further, the recalculated head address after alignment is MARKADDR _new= (MARKADDR + (UAlign-1))/UAlign × UAlign, wherein MARKADDR is the head address recorded by the original node, and UAlign is the number of aligned bytes specified by the user. F