Stack dynamic allocation method

By dynamically adjusting the stack space, problems caused by insufficient and oversized stack allocation are solved, enabling efficient use of stack resources and smooth operation of the device.

CN118819820APending Publication Date: 2024-10-22上海星宇智行技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410736549.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-10-22

AI Technical Summary

Technical Problem

The existing technology cannot effectively solve the problem of insufficient stack space allocation that causes the device to be unable to operate. At the same time, excessive stack space allocation also leads to a waste of resources.

Method used

Through a stack dynamic allocation method, including configuring the initial stack space, real-time release of redundant space and expansion of insufficient space, the efficient use of stack resources is ensured. This method obtains stack usage in real time while the device is running, and dynamically adjusts it based on historical statistics and set thresholds to avoid resource waste and device crashes.

Benefits of technology

It achieves efficient use of stack resources, avoids device crashes and waste of resources due to insufficient allocation, and ensures smooth operation of the device and optimal allocation of resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118819820A_ABST
    Figure CN118819820A_ABST
Patent Text Reader

Abstract

The invention discloses a dynamic stack allocation method. The method comprises the following steps: S1, configuring an initial stack space; s2, releasing stack space resources; and S3, expanding stack space resources. According to the method and the device, the use condition of the event stack can be acquired in real time, when the stack is insufficient, the idle space is allocated for the event to use, and when the stack is redundant, the redundant space is released, so that equipment cannot run due to insufficient stack allocation and resource waste due to overlarge stack allocation can be avoided, the dynamic adjustment of the stack is realized, and the efficiency is improved. And stable operation of equipment and efficient use of stack resources are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a stack dynamic allocation method. Background Art

[0002] In recent years, with the rapid development of chip technology and the advent of the intelligent era, the performance of chips has become stronger and stronger, and the complexity of products has become higher and higher. As code tool generation is more common, the depth of generated code is getting higher and higher. Due to poor readability, the evaluation of stack resources is becoming more and more difficult. At present, the use of the stack is obtained through testing, and then optimized. Finally, during product operation, the use of the stack is statically monitored. When the stack is about to overflow or overflows, a reset is triggered, or a dynamic stack is used to release unused stack resources. Such operations cannot avoid the problem caused by the stack space overflowing. Summary of the invention

[0003] The technical problem to be solved by the present invention is: in order to solve the technical problem that insufficient allocation of existing stack space causes the device to be non-functional all the time or excessive allocation of stack space causes waste of resources, the present invention provides a stack dynamic allocation method, which can realize dynamic adjustment of the stack, ensure the smooth operation of the device and the efficient use of stack resources.

[0004] The technical solution adopted by the present invention to solve the technical problem is: a stack dynamic allocation method, comprising the following steps:

[0005] S1, configure the initial stack space;

[0006] S2, release stack space resources;

[0007] S3. Expand stack space resources.

[0008] In this way, the usage of the event stack can be obtained in real time. When the stack is insufficient, free space is allocated for the event to use. When the stack is redundant, the redundant space is released. This can avoid the device from being unable to operate due to insufficient stack allocation and the waste of resources due to excessive stack allocation. Dynamic adjustment of the stack can be achieved to ensure the smooth operation of the device and the efficient use of stack resources.

[0009] Furthermore, the step S1 includes the following steps:

[0010] Before the equipment is put into operation:

[0011] S1-1. Set the initial size of each event stack and obtain the historical remaining minimum value corresponding to the event based on historical statistics;

[0012] S1-2, configure the release threshold, extension threshold and extension value;

[0013] Equipment in operation:

[0014] S1-3. Obtain the usage of the event stack in real time.

[0015] Furthermore, the step S2 comprises the following steps:

[0016] Equipment in operation:

[0017] S2-1. Obtain the usage of the event stack in real time, obtain the used size of the event, and obtain the remaining space of the event stack;

[0018] S2-2, if the remaining stack space is less than the historical minimum remaining space, execute step S2-3;

[0019] S2-3, record the current working condition of the event and update the historical minimum remaining value corresponding to the event. At this time, the historical minimum value corresponding to the event is updated to the remaining space of the event stack, that is, the updated historical minimum remaining value is the remaining space of the event stack;

[0020] Equipment operation ends:

[0021] S2-4, if the historical remaining minimum value is greater than the release threshold, execute step S2-5;

[0022] S2-5, judging whether the historical working conditions meet the conditions, if so, executing step S2-6;

[0023] S2-6. Mark the event stack resource as too large, and the stack space of the event needs to be released. Only the release threshold space is retained, and the excess space is released. Then, the new stack space is run, and the usage of the new stack of the event is obtained in real time.

[0024] Furthermore, step S3 includes the following steps:

[0025] Equipment in operation:

[0026] S3-1, if the historical remaining minimum value is less than the expansion threshold, execute step S3-2;

[0027] S3-2. Mark that the event stack resource is insufficient, operate stack expansion, and expand the event stack space according to the expansion value, and then run according to the new stack to obtain the usage of the new event stack in real time.

[0028] Furthermore, in step S1-2:

[0029] Release threshold > expansion threshold, expansion value > expansion threshold.

[0030] Furthermore, in step S2-1:

[0031] The remaining space in the stack = the initial size of the event stack - the size used by the event.

[0032] Further, in step S2:

[0033] After the stack resources are expanded, if during the subsequent code execution, the minimum remaining value of the stack history is greater than the release threshold, the stack release operation will be performed again.

[0034] Further, in step S3:

[0035] After stack resources are expanded, if the minimum remaining value of the stack history is less than the expansion threshold during subsequent code execution, the stack expansion operation will be performed again.

[0036] Compared with the prior art, the present invention has the following beneficial effects:

[0037] It can obtain the usage of the event stack in real time. When the stack is insufficient, it allocates free space for the event. When the stack is redundant, it releases the redundant space. This can avoid the device from being unable to operate due to insufficient stack allocation and the waste of resources due to excessive stack allocation. It can realize dynamic adjustment of the stack and ensure the smooth operation of the device and efficient use of stack resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0039] Figure 1 It is a flow chart of the stack dynamic allocation method of the present invention;

[0040] Figure 2 is a flow chart of step S1 of the present invention;

[0041] Figure 3 is a flow chart of step S2 of the present invention;

[0042] Figure 4 is a flow chart of step S3 of the present invention;

[0043] Figure 5 A schematic diagram of the working principle of the stack of the present invention;

[0044] Figure 6 A release diagram of stack resources of the present invention;

[0045] Figure 7 It is an expanded diagram of the stack resources of the present invention. DETAILED DESCRIPTION

[0046] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, which only illustrate the basic structure of the present invention in a schematic manner, and therefore only show the components related to the present invention.

[0047] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. In addition, features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "multiple" means two or more.

[0048] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0049] like Figures 1 to 7 As shown, it is the best embodiment of the present invention. The stack dynamic allocation method of this embodiment comprises the following steps:

[0050] S1, configure the initial stack space;

[0051] S2, release stack space resources;

[0052] S3, expand the stack space resources. In this way, the usage of the event stack can be obtained in real time. When the stack is insufficient, free space is allocated for the event to use. When the stack is redundant, the redundant space is released. This can avoid the device from being unable to operate due to insufficient stack allocation and the waste of resources due to excessive stack allocation. The dynamic adjustment of the stack is realized to ensure the smooth operation of the device and the efficient use of stack resources.

[0053] Specifically, the space used for stack expansion is the free area of ​​the entire space. According to the size of the applied space, a free area of ​​corresponding size is allocated, and the space released by the stack is also returned to the entire space for other purposes. In this way, maximum utilization of resources is achieved.

[0054] In this embodiment, step S1 includes the following steps:

[0055] Before the equipment is put into operation:

[0056] S1-1. Set the initial size of each event stack and obtain the historical remaining minimum value corresponding to the event based on historical statistics;

[0057] S1-2, configure the release threshold, extension threshold and extension value;

[0058] Equipment in operation:

[0059] S1-3, real-time acquisition of event stack usage;

[0060] Among them: release threshold> expansion threshold, expansion value> expansion threshold. .

[0061] In this embodiment, step S2 includes the following steps:

[0062] Equipment in operation:

[0063] S2-1. Obtain the usage of the event stack in real time, obtain the used size of the event, and obtain the remaining space of the event stack;

[0064] S2-2, if the remaining stack space is less than the historical minimum remaining space, execute step S2-3;

[0065] S2-3, record the current working condition of the event and update the historical minimum remaining value corresponding to the event. At this time, the historical minimum value corresponding to the event is updated to the remaining space of the event stack, that is, the updated historical minimum remaining value is the remaining space of the event stack;

[0066] Equipment operation ends:

[0067] S2-4, if the historical remaining minimum value is greater than the release threshold, execute step S2-5;

[0068] S2-5, judging whether the historical working conditions meet the conditions, if so, executing step S2-6;

[0069] S2-6, marking the event stack resource as too large, requiring the event stack space to be released, retaining only the release threshold space, releasing the excess space, and then running according to the new stack space, and obtaining the usage of the new stack of the event in real time;

[0070] Wherein: stack remaining space = initial size of event stack - used size of the event; after stack resources are expanded, if in the subsequent code running process, when the minimum remaining value of stack history is greater than the release threshold, the stack release operation will be executed again.

[0071] In this embodiment, step S3 includes the following steps:

[0072] Equipment in operation:

[0073] S3-1, if the historical remaining minimum value is less than the expansion threshold, execute step S3-2;

[0074] S3-2, marking that the event stack resources are insufficient, operating stack expansion, and expanding the event stack space according to the expansion value, and then running according to the new stack to obtain the usage of the new event stack in real time;

[0075] Among them: After the stack resources are expanded, if during the subsequent code execution, if the stack historical remaining minimum value is less than the expansion threshold, the stack expansion operation will be performed again.

[0076] Specifically, the release and expansion of stack resources are performed dynamically; in the process of release and expansion, the optimal configuration of stack resources is gradually achieved.

[0077] Specifically, Figure 5 As shown, in embedded software, each event (task, interrupt) will be allocated a corresponding stack. PUSH is to push data into the stack, and POP is to pop data from the stack. When PUSH data, the SP pointer moves from the bottom of the stack to the top of the stack, and the remaining space of the stack will decrease. When POP data, the SP pointer moves from the top of the stack to the bottom of the stack, and the remaining space of the stack will increase.

[0078] Specifically, when the device is in the initial state, the space of each time stack is statically set first. During the running process, the content of the stack will continue to change, and the stack pointer (SP: Stack Pointer) will also continue to change. The deeper the call depth, the smaller the remaining space of the stack will be.

[0079] In summary, the present invention can obtain the usage of the event stack in real time. When the stack is insufficient, free space is allocated for use by the event. When the stack is redundant, the redundant space is released. This can avoid the inability of the device to operate due to insufficient stack allocation and the waste of resources due to excessive stack allocation, and realize dynamic adjustment of the stack to ensure the smooth operation of the device and the efficient use of stack resources.

[0080] The above description is based on the ideal embodiment of the present invention. Through the above description, relevant personnel can make various changes and modifications without departing from the technical concept of the present invention. The technical scope of the present invention is not limited to the content in the specification, and its technical scope must be determined according to the scope of the claims.

Claims

1. A stack dynamic allocation method, It is characterized in that The following steps are involved: S1, configure the initial stack space; S2, release stack space resources; S3. Expand stack space resources.

2. The stack dynamic allocation method according to claim 1, It is characterized in that The step S1 comprises the following steps: Before the equipment is put into operation: S1-1. Set the initial size of each event stack and obtain the historical remaining minimum value corresponding to the event based on historical statistics; S1-2, configure the release threshold, extension threshold and extension value; Equipment in operation: S1-3. Obtain the usage of the event stack in real time.

3. The stack dynamic allocation method according to claim 2, It is characterized in that The step S2 comprises the following steps: Equipment in operation: S2-1. Obtain the usage of the event stack in real time, obtain the used size of the event, and obtain the remaining space of the event stack; S2-2, if the remaining stack space is less than the historical minimum remaining space, execute step S2-3; S2-3, record the current working condition of the event and update the historical minimum remaining value corresponding to the event. At this time, the historical minimum value corresponding to the event is updated to the remaining space of the event stack, that is, the updated historical minimum remaining value is the remaining space of the event stack; Equipment operation ends: S2-4, if the historical remaining minimum value is greater than the release threshold, execute step S2-5; S2-5, judging whether the historical working conditions meet the conditions, if so, executing step S2-6; S2-6. Mark the event stack resource as too large, and the stack space of the event needs to be released. Only the release threshold space is retained, and the excess space is released. Then, the new stack space is run, and the usage of the new stack of the event is obtained in real time.

4. The stack dynamic allocation method according to claim 3, It is characterized in that The step S3 comprises the following steps: Equipment in operation: S3-1, if the historical remaining minimum value is less than the expansion threshold, execute step S3-2; S3-2. Mark that the event stack resource is insufficient, operate stack expansion, and expand the event stack space according to the expansion value, and then run according to the new stack to obtain the usage of the new event stack in real time.

5. The stack dynamic allocation method according to claim 2, It is characterized in that In step S1-2: Release threshold > expansion threshold, expansion value > expansion threshold.

6. The stack dynamic allocation method according to claim 3, It is characterized in that In step S2-1: The remaining space in the stack = the initial size of the event stack - the size used by the event.

7. The stack dynamic allocation method according to claim 4, It is characterized in that In step S2: After the stack resources are expanded, if during the subsequent code execution, the minimum remaining value of the stack history is greater than the release threshold, the stack release operation will be performed again.

8. The stack dynamic allocation method according to claim 1, It is characterized in that In step S3: After stack resources are expanded, if the minimum remaining value of the stack history is less than the expansion threshold during subsequent code execution, the stack expansion operation will be performed again.