Industrial control system variable memory allocation method and device
By using a memory allocation method that collaboratively manages sets of bit free blocks and byte free blocks, the problem of low memory allocation efficiency in industrial control systems is solved. This achieves efficient memory address allocation and release, optimizes memory usage statistics and space layout, and adapts to complex variable requirements.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-22
- Publication Date
- 2026-04-03
AI Technical Summary
Existing methods for allocating variable memory in industrial control systems are inefficient, especially when dealing with large-scale memory management and frequent operations, which leads to a significant decrease in the response speed of configuration software.
A memory allocation method that coordinates the management of bit free block sets and byte free block sets is adopted. Through initialization, search, splitting and release operations, the memory allocation and release process is optimized, and free blocks are merged when necessary to reduce fragmentation.
It improves memory allocation efficiency, reduces the computational load of statistical operations, optimizes memory space layout, adapts to the complex needs of mixed variables, and provides a flexible and reliable foundation for memory management.
Smart Images

Figure CN121785947A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial control, and more particularly to a method and apparatus for allocating variable memory in an industrial control system. Background Technology
[0002] When programming control logic using industrial control system configuration software, a large number of variables need to be created for data acquisition, calculation, and output. To conserve control system memory resources, variables are of various types, including bit-based digital quantities (such as Boolean BOOL) and byte-based analog quantities (such as integer INT, floating-point FLOAT, strings, arrays, etc.). The configuration software needs to allocate unique and non-overlapping memory addresses for these variables within the system memory range and support address modification, allocation to specific locations (such as for Modbus communication), and memory usage statistics.
[0003] Currently, the common memory allocation method in control system programming software is as follows: First, a contiguous virtual memory region is pre-allocated in the software according to the maximum memory capacity of the control system, and managed using a bitmap. During initialization, all bits are marked as free (e.g., set to 0). When memory needs to be allocated for variables, the entire bitmap is scanned byte-by-byte or bit-by-bit, starting from the memory's starting address, to find contiguous segments marked as free. If a free segment of the required length is found, it is marked as occupied (e.g., set to 1). When calculating memory usage load, the entire bitmap also needs to be traversed to count the number of set bits.
[0004] However, each time memory is allocated for a variable, a complete traversal search must be performed on the entire pre-allocated management area, starting from the beginning of the memory space, using either a bitwise or byte-wise search method to find a sufficiently long contiguous free space. The efficiency of this search method depends entirely on the actual memory layout and the already allocated memory. In the worst-case scenario, such as when the memory space is partially fragmented, the algorithm needs to perform multiple such traversals to find a suitable location, and its time consumption will increase dramatically and non-linearly with the increase of the total memory capacity. When the system manages a large amount of memory, or when allocation and deallocation operations occur frequently, this inefficient search process will significantly slow down the overall response speed of the configuration software, becoming a limiting factor for system performance. Summary of the Invention
[0005] (a) Technical problems to be solved In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides a method and apparatus for allocating variable memory in industrial control systems, which solves the technical problem of low allocation and lookup efficiency.
[0006] (II) Technical Solution To achieve the above objectives, the main technical solutions adopted by the present invention include: In a first aspect, embodiments of the present invention provide a method for allocating memory for industrial control system variables. This method implements memory allocation by coordinating the management of a set of bit free blocks and a set of byte free blocks, wherein the set of bit free blocks and the set of byte free blocks jointly represent the complete free state of the memory area; the method includes: Based on the initial address and total size of the memory area, initialize the bit free block set and the byte free block set, so that the bit free block set is initially empty and the byte free block set is initially a free block corresponding to the memory area range; In response to a memory operation request for a variable, search for the target free block in the set of bit free blocks and / or the set of byte free blocks; If the memory operation request is a memory allocation request, the requested memory is divided from the target free block, and the corresponding free block set is updated according to the division result; If the memory operation request is a memory release request, the released memory region will be inserted as a new free block into the corresponding free block set.
[0007] Optionally, the memory allocation request includes allocation requests with a specified starting address and allocation requests without a specified starting address; searching for a target free block in the set of bit free blocks and / or the set of byte free blocks includes: for allocation requests with a specified starting address, searching in the corresponding free block set for a free block whose address range includes the specified starting address as the target free block; for allocation requests without a specified starting address, searching in the corresponding free block set for a free block whose length is not less than the requested memory size as the target free block, according to the first-match strategy or the best-match strategy.
[0008] Optionally, the method further includes: merging consecutively addressed free blocks in the bit free block set and the byte free block set when no target free block is found or when the process is executed periodically according to a preset period.
[0009] Optionally, merging contiguous free blocks in the bit free block set and the byte free block set includes: converting and migrating whole-byte free regions recorded in the bit free block set that meet the byte alignment condition to the byte free block set for management.
[0010] Optionally, the method further includes: calculating the memory area utilization rate based on the total size of the memory area and the total byte length of all free blocks in the bit free block set and the byte free block set; wherein, the total byte length of all free blocks is obtained by multiplying the sum of the bit lengths of all free blocks in the bit free block set by 8 and adding the byte lengths of all free blocks in the byte free block set.
[0011] Secondly, embodiments of the present invention provide an industrial control system variable memory allocation device. The device implements memory allocation by coordinating the management of a set of bit free blocks and a set of byte free blocks, wherein the set of bit free blocks and the set of byte free blocks jointly represent the complete free state of the memory area; the device includes: The initialization module is used to initialize the bit free block set and the byte free block set according to the initial address and total size of the memory area, so that the bit free block set is initially empty and the byte free block set is initially a free block corresponding to the memory area range; The lookup module is used to search for a target free block in the set of bit free blocks and / or the set of byte free blocks in response to a memory operation request for a variable. The partitioning and updating module is used to partition the requested memory from the target free block if the memory operation request is a memory allocation request, and update the corresponding free block set according to the partitioning result. The release module is used to insert the released memory region as a new free block into the corresponding free block set if the memory operation request is a memory release request.
[0012] Optionally, the memory allocation request includes allocation requests with a specified starting address and allocation requests without a specified starting address; the search module is specifically used to: for allocation requests with a specified starting address, search in the corresponding free block set for a free block whose address range includes the specified starting address as the target free block; for allocation requests without a specified starting address, search in the corresponding free block set for a free block whose length is not less than the requested memory size as the target free block according to the first matching strategy or the best matching strategy.
[0013] Optionally, the device further includes: The merging module is used to merge contiguous free blocks in the bit free block set and the byte free block set when no target free block is found or when the merge is executed periodically according to a preset period.
[0014] Optionally, the merging module is specifically used to convert and migrate whole-byte free regions that are recorded in the bit free block set and meet the byte alignment conditions to the byte free block set for management.
[0015] Optionally, the device further includes: a calculation module for calculating the utilization rate of the memory area based on the total size of the memory area and the total byte length of all free blocks in the bit free block set and the byte free block set; wherein the total byte length of all free blocks is obtained by multiplying the sum of the bit lengths of all free blocks in the bit free block set by 8 and adding the byte lengths of all free blocks in the byte free block set.
[0016] (III) Beneficial Effects The beneficial effects of this invention are: This application provides a method for allocating variable memory in an industrial control system. By adopting a memory allocation method guided by a set of free data, it can not only efficiently allocate and release random or specific memory addresses for variables, but also efficiently adapt to the allocation of analog, digital, continuous byte, and continuous bit memory in the control system, and can also efficiently perform statistics on system memory usage. Attached Figure Description
[0017] Figure 1 A flowchart of a variable memory allocation method for an industrial control system provided in an embodiment of this application is shown; Figure 2 This application illustrates a memory management flowchart provided in an embodiment. Figure 3 This application provides an embodiment of a system free memory state evolution diagram. Figure 4 This illustration shows an evolution diagram of the consolidation state of an idle data block according to an embodiment of this application; Figure 5 A structural block diagram of an industrial control system variable memory allocation device provided in an embodiment of this application is shown. Detailed Implementation
[0018] To better explain and facilitate understanding of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0019] Currently, in addition to the problem of low allocation and search efficiency, existing technologies also have the following problems: Whenever the overall memory utilization needs to be obtained, the system must rescan the entire massive management bitmap, checking the status of each smallest management unit one by one. The computational load of this operation is proportional to the total amount of memory managed, representing a significant overhead. As the control system grows in size, this statistical operation consumes increasing processing time, causing significant response delays in the configuration software when attempting to assess system load.
[0020] Furthermore, this method faces a dilemma between resource efficiency and data validity when deploying memory layout information to the actual controller hardware. If the complete state information of the entire predefined memory region is distributed for management convenience, it unnecessarily occupies valuable storage space and communication bandwidth of the controller. Conversely, if resources are saved by only distributing the actually occupied memory region, the large amount of fragmented data generated during long-term operation makes it difficult to organize and transmit a batch of efficient, continuous, and valid data blocks, thus diminishing the actual benefits of this optimization attempt.
[0021] Based on this, the present application provides a method for allocating variable memory in an industrial control system. By adopting a memory allocation method guided by a set of free data, it can not only efficiently allocate and release random or specific memory addresses for variables, but also efficiently adapt to the allocation of analog, digital, continuous byte, and continuous bit memory in the control system, and can also efficiently perform statistics on system memory usage.
[0022] To better understand the above technical solutions, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that the present invention can be understood more clearly and thoroughly, and that the scope of the present invention can be fully conveyed to those skilled in the art.
[0023] To facilitate understanding of the embodiments of this application, the terms involved in this application are explained below: Configuration software: a type of specialized software used for data acquisition and process control, and as a development tool or development environment for the host computer human-machine interface of a monitoring system.
[0024] Variables: These are named locations that store data. They can hold different types of data, such as integers, floating-point numbers, and strings. Furthermore, the value of a variable can be changed during program execution.
[0025] Memory address: It is a unique identifier for each byte or storage unit in the system memory.
[0026] Digital quantity: It is a discrete signal, usually represented by a single bit, with only two states: 0 and 1.
[0027] Analog signal: It is a continuous signal that can take any value within a certain range.
[0028] Bit: The smallest unit of data in a computer, representing each bit of a binary number.
[0029] Byte: A unit of data consisting of 8 bits.
[0030] Total size (Lt): This refers to the total capacity of the entire contiguous logical memory area used for variable allocation, as defined by the configuration software. Its unit can be bytes.
[0031] Please see Figure 1 , Figure 1A flowchart illustrating an industrial control system variable memory allocation method according to an embodiment of this application is shown. It should be understood that this method can be executed by an industrial control system variable memory allocation device, and the specific device can be configured according to actual needs; this embodiment is not limited thereto. For example, the device can be a computer or a server, etc. Specifically, this method implements memory allocation by coordinating the management of a set of bit free blocks and a set of byte free blocks, wherein the set of bit free blocks and the set of byte free blocks jointly represent the complete free state of the memory area; the method includes: Step S110: Based on the initial address and total size of the memory area, initialize the bit free block set and the byte free block set, so that the bit free block set is initially empty and the byte free block set is initially a free block corresponding to the memory area range; Step S120: In response to the memory operation request of the variable, search for the target free block in the bit free block set and / or the byte free block set; Step S130: If the memory operation request is a memory allocation request, the requested memory is divided from the target free block, and the corresponding free block set is updated according to the division result. Step S140: If the memory operation request is a memory release request, then the released memory region is inserted as a new free block into the corresponding free block set.
[0032] Therefore, by means of the above technical solution, this application can achieve the following technical effects: First, it fundamentally restructures the memory management paradigm. By collaboratively maintaining dynamic sets of bit-free blocks and byte-free blocks, it replaces the inefficient full memory traversal mechanism. This transforms memory allocation and release operations from time-consuming linear or even quadratic complexity searches into efficient queries and updates of structured sets, achieving an order-of-magnitude improvement in allocation efficiency. Second, in terms of memory utilization statistics, this application completely eliminates the need for a global scan of a massive bitmap. A single fast summation operation on the lengths of free blocks recorded in the two sets is all that's needed to complete the calculation instantly, transforming the statistical operation from a resource-intensive task into a lightweight computation with instantaneous response. Third, through a specially designed free block consolidation mechanism, the system can proactively detect and merge contiguous free regions and convert eligible bit-free blocks into byte-free blocks, effectively reducing external memory fragmentation, significantly improving the availability of large contiguous memory blocks, and optimizing the overall memory space layout. Finally, by managing bit-level and byte-level idle resources in parallel and with precise segmentation and conversion rules, this method naturally and efficiently adapts to the complex requirements of mixed digital and analog variables in industrial control programming, providing a flexible and reliable memory management foundation for configuration software.
[0033] To facilitate understanding of the embodiments of this application, specific embodiments are described below.
[0034] Specifically, such as Figure 2 As shown, Figure 2 A flowchart illustrating a memory management process according to an embodiment of this application is shown. Figure 2 As shown, the entire memory management module is divided into three parts: memory allocation unit 100, memory management unit 200, and memory data area 300.
[0035] The memory allocation unit 100 is responsible for responding to variable operation requests in the configuration software. Its main functions include: defining the memory area to be managed based on the memory resources of the control system, and initializing the bit free block set and the byte free block set; responding to memory allocation requests, searching for and allocating suitable memory space by querying the free block set, and updating the corresponding set status; and responding to memory release requests, releasing the relevant memory and inserting it as a new free block into the corresponding set. The memory management unit 200 is responsible for maintaining and optimizing the set of bit free blocks and the set of byte free blocks in memory data units. Its main functions include: periodically or under specific conditions, merging the set of bit free blocks and the set of byte free blocks, merging free blocks with contiguous addresses to reduce fragmentation; converting whole-byte bit free blocks that meet byte alignment conditions into the set of byte free blocks to optimize management granularity; and quickly calculating the overall system memory utilization based on the set data. Memory data area 300 is the entire area of system memory, guided by the set of free data areas, and is the object of operation of memory allocation unit and memory management unit.
[0036] To facilitate understanding of the three parts described above—memory allocation unit 100, memory management unit 200, and memory data area 300—the following will use… Figure 2 The specific process will be described in detail.
[0037] Optionally, such as Figure 2 As shown, in memory allocation unit 100, step 101 initializes and pre-allocates system memory: setting the initial address and total size Lt of the system memory. For example, in this instance, the initial address is preset to 0, the total length is 1000 bytes, and two data block sets, a bit free block set and a byte free block set, are used to represent the free space of the memory area. Initially, the bit free data block set is empty, and the byte free area is the total size of the memory area, such as... Figure 3 The shaded portion of 301 in the image (different slash directions indicate bit memory and byte memory).
[0038] And, after the initial allocation of the memory area is completed, the variable memory allocation and release operation in step 102 is executed.
[0039] Furthermore, when performing memory allocation, step 103 can determine whether to perform fixed memory allocation or random memory allocation as needed.
[0040] If step 104, random matching, is performed, and random address allocation involves arbitrarily selecting suitable free addresses for memory allocation, generally starting from the free position at the beginning of the data area to match suitable memory spaces; if step 107, fixed address allocation or fixed address release, is performed, fixed address allocation involves allocating memory in a specific memory address space. For example, if variable A is specified at address 100 as a 1-bit digital value, and variable B is specified at address 101 as a 2-byte analog value, then 1 bit of memory needs to be allocated at address 100, and 2 bytes need to be allocated at address 101. Figure 3 As shown in 302; variable memory can only be released at fixed addresses. For example, if variable A is deleted, the memory starting at address 100 and with a length of 1 bit will be released.
[0041] Furthermore, in the random memory allocation in step 104, it can be set to either the first match in step 105 or the best match in step 106. The first match is to find the first free memory block in the set of free data blocks from the least significant bit to the most significant bit, which is greater than or equal to the allocated memory space. The best match is to find the space in the set of free data blocks from the least significant bit to the most significant bit, which is the same size as the allocated memory space, and allocate it. If the search fails, the first match is used.
[0042] Furthermore, in the fixed address allocation / release process of step 107, depending on whether the allocation type is bit type or byte type, a free data block containing the corresponding address is searched from the least significant bit to the most significant bit in the set of free data blocks for bits and bytes respectively. If the search fails, an error is reported; if the search succeeds, the corresponding free data block is returned.
[0043] Furthermore, during the initial allocation, depending on whether the allocation type is bit or byte, step 108 is executed to search for a free data block matching the specified length, starting from the first element of the array set of free bit or byte data blocks. If the byte memory search fails, it indicates that there are insufficient free data blocks for allocation, so step 201 (free data block consolidation) is performed, and the memory search is repeated. If the search fails, an "insufficient memory" error is reported. If the bit space search fails, the first matching data block is selected from the byte free data block set for data block splitting. If the search is successful, the corresponding free data block is returned.
[0044] And, after executing step 108, execute step 109 to allocate or release the found free data blocks. The allocation rules are handled according to the following scheme: Case 1: Allocate byte memory in the free byte data block. Its input is: a byte free block FB_byte (starting address S, length L_bytes), and a request to allocate K bytes at address A. Its output is: 0, 1, or 2 new free blocks. And its rule is: If A = S and K = L_bytes, then the entire block is allocated and the original free block disappears. As Figure 3 shown in 303, when allocating 100 bytes at address 0, free data block 1 disappears; if A = S and K < L_bytes, it is split into: new byte free block 1 (S + K, L_bytes - K); if A > S and A + K < S + L_bytes, it is split into: new byte free block 1 (S, A - S), new byte free block 2 (A + K, (S + L_bytes) - (A + K)); Case 2: Allocate bit memory in the free bit data block. Its input is: a bit free block FB_bit (starting address S, length L_bits), and a request to allocate K bits at address A. Its output is: 0, 1, or 2 new free blocks. And its rule is: If A = S and K = L_bits, then the entire block is allocated and the original free block disappears; if A = S and K < L_bits, it is split into: new bit free block 1 (S + K, L_bits - K); if A > S and A + K < S + L_bits, it is split into: new bit free block 1 (S, A - S), new bit free block 2 (A + K, (S + L_bits) - (A + K)), as Figure 3 shown in 304, free data block 1 is split into two new free data blocks 1 and free data block 2; Case 3: Allocate bit memory in the free byte data block. Its input is: a byte free block FB_byte (starting address S, length L_bytes), and a request to allocate K bits at address A. Its output is: 1, 2, or 3 new free blocks. And its rule is: If A >= S and (A % 8 + K) < 8, that is, the occupied bit data block does not cross bytes, then it is split into: new bit free block 1 (S, A - S) (this block does not exist when A = S). New bit free block 2 (A + K, (A / 8 + 1) * 8 - (A + K)), that is, from the end bit of the occupied part to the start bit of the next byte. New byte free block 3 ((A + K) / 8 + 1, (S + L_bytes) - ((A + K) / 8 + 1)), that is, from the next byte of the occupied memory to the end byte of the data block; if A > S, (A % 8 + K) > 8 and (A + K) = (S + L_bytes) * 8, that is, the occupied data block crosses bytes and occupies to the end bit, then it is split into: new bit free block 1 (S, A - S). As Figure 3As shown in Figure 305, if 3 bits are allocated at memory address 103.3, then three new free data areas 3, 4, and 5 are created. The advantage of this allocation method is that the free data blocks can be allocated to be smaller to adapt to the memory allocation of digital quantities, and the byte data blocks are more concentrated to adapt to the memory allocation of analog quantities. If A≥S, (A%8+K)>8 and (A+K)<(S+L_bytes)*8, that is, the occupied data block spans bytes and does not occupy the end bit, then it is divided into: new free block 1 and new free block 2. The new free block 1 is (S,AS), and this block does not exist when A=S; the new free block 2 is (A+K,(S+L_bytes)*8-(A+K)), that is, from the occupied end bit to the end bit of the free area.
[0045] Furthermore, based on the allocation result of step 109, the newly generated free data blocks are placed into the corresponding set of bit or byte free data blocks (i.e., step 110), and unnecessary free data blocks are eliminated.
[0046] In the memory management unit 200, step 201 involves consolidating free data blocks to reduce their number, thereby improving the operating efficiency and availability of the memory allocation unit 100. During this process, the free data block set is checked sequentially from least significant bit to most significant bit to determine if two free data blocks are contiguous, i.e., FB_bit1 (starting address S1, length L1_bits) and FB_bit2 (starting address S2, length L2_bits), where (S1 + L1_bits) = S2. These are then merged into a larger free data block. If the new free data block starts at address 0 and has a length of an integer byte, it is placed in the byte free data set. Then, in the same manner, contiguous data blocks in the byte free data set are merged into a larger free data block. The entire process is as follows: Figure 4 As shown, step 306 generates a new free bit data block 4 after releasing 3 bits of memory space 103.3-103.5. At this time, there are three consecutive free bit data blocks 3 (4 bits), 4 (3 bits), and 5 (1 bit). Step 307 combines the first and last bits of free 3 and free 4 to form a new free bit block 3 (7 bits). Step 308 combines the first and last bits of the new free 3 and free 4 to form a new free byte block 3 (1 byte) and adds it to the byte free data block set. Step 309 merges byte free block 3 (1 byte) and byte free block 4 (897 bytes) into a new byte free block 3 (898 bytes). Step 201 is performed when the search for free memory in step 108 fails and is executed in the background at a preset interval. The specific value of the preset interval can be set according to actual needs, and this embodiment is not limited to this. For example, the preset interval can be 12 hours, etc.
[0047] In addition, whole-byte free regions that are recorded in the bit free block set and meet the byte alignment conditions will be converted and migrated to the byte free block set for management.
[0048] For example, the system iterates through each record in the bit free block set. A bit free block is considered a regular byte-level free block if and only if it simultaneously meets both conditions: byte alignment (its starting address is a multiple of 8) and integer byte length (its length is a multiple of 8). The system then removes this record from the bit free block set, converts its unit of measurement from "bit" to "byte," divides the starting address by 8 to obtain the byte starting address, and divides the length by 8 to obtain the byte length. This generates a new byte free block record, which is then inserted into the byte free block set in sequence. This operation aims to optimize management granularity, making byte-level memory allocation more efficient; it also purifies the set structure, allowing the bit set to focus more on managing true bit-level fragmentation; and by consolidating scattered, compliant bit blocks into contiguous byte blocks, it further reduces external memory fragmentation, improving the success rate of subsequent allocation of large contiguous memory blocks and overall management efficiency.
[0049] In addition, step 202 is to calculate the memory usage rate by adding the lengths of all members of the free bit data block set and the byte data block set, that is, the free length Le = (L1_bits + ... + Ln_bits) * 8 + (L1_bytes + ... Ln_bytes), and (Lt - Le) / Lt is the system memory usage rate, where Lt is the total length of the entire data area.
[0050] It should be understood that the above-described method for allocating variable memory in industrial control systems is merely exemplary, and those skilled in the art can make various modifications based on the above method, and the modified solutions also fall within the protection scope of this application.
[0051] Please see Figure 5 , Figure 5This diagram illustrates a structural block diagram of an industrial control system variable memory allocation device 500 according to an embodiment of this application. It should be understood that the industrial control system variable memory allocation device 500 is capable of performing the steps described in the above method embodiments. The specific functions of the industrial control system variable memory allocation device 500 can be found in the description above; detailed descriptions are omitted here to avoid repetition. The industrial control system variable memory allocation device 500 includes at least one software function module that can be stored in memory or embedded in the operating system (OS) of the industrial control system variable memory allocation device 500 in the form of software or firmware. Specifically, the device 500 implements memory allocation by coordinating the management of a set of bit free blocks and a set of byte free blocks, wherein the set of bit free blocks and the set of byte free blocks jointly represent the entire free state of the memory area; the device 500 includes: The initialization module 510 is used to initialize the bit free block set and the byte free block set according to the initial address and total size of the memory area, so that the bit free block set is initially empty and the byte free block set is initially a free block corresponding to the memory area range; The lookup module 520 is used to look up a target free block in the set of bit free blocks and / or the set of byte free blocks in response to a memory operation request for a variable. The segmentation and update module 530 is used to segment the requested memory from the target free block if the memory operation request is a memory allocation request, and update the corresponding free block set according to the segmentation result. The release module 540 is used to insert the released memory region as a new free block into the corresponding free block set if the memory operation request is a memory release request.
[0052] Optionally, the memory allocation request includes allocation requests with a specified starting address and allocation requests without a specified starting address; the search module 520 is specifically used to: for allocation requests with a specified starting address, search in the corresponding free block set for a free block whose address range includes the specified starting address as the target free block; for allocation requests without a specified starting address, search in the corresponding free block set for a free block whose length is not less than the requested memory size as the target free block according to the first matching strategy or the best matching strategy.
[0053] Optionally, the device 500 further includes a merging module (not shown) for merging consecutively addressed free blocks in the bit free block set and the byte free block set when no target free block is found or when the merging is performed periodically according to a preset period.
[0054] Optionally, the merging module is specifically used to convert and migrate whole-byte free regions that are recorded in the bit free block set and meet the byte alignment conditions to the byte free block set for management.
[0055] Optionally, the device 500 further includes: a calculation module (not shown) for calculating the utilization rate of the memory area based on the total size of the memory area and the total byte length of all free blocks in the bit free block set and the byte free block set; wherein the total byte length of all free blocks is obtained by multiplying the sum of the bit lengths of all free blocks in the bit free block set by 8 and adding the byte lengths of all free blocks in the byte free block set.
[0056] Since the apparatus described in the above embodiments of the present invention is an apparatus used to implement the methods of the above embodiments of the present invention, those skilled in the art can understand the specific structure and variations of the apparatus based on the methods described in the above embodiments of the present invention, and therefore will not be described again here. All apparatuses used in the methods of the above embodiments of the present invention fall within the scope of protection of the present invention.
[0057] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0058] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions.
[0059] It should be noted that any reference numerals placed between parentheses in the claims should not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention can be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In claims that enumerate several means, several of these means may be embodied by the same hardware. The use of the terms first, second, third, etc., is merely for convenience of expression and does not indicate any order. These terms can be understood as part of the component names.
[0060] Furthermore, it should be noted that in the description of this specification, the terms "one embodiment," "some embodiments," "embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0061] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the claims should be interpreted to include both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0062] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, then this invention should also include these modifications and variations.
Claims
1. A method for allocating variable memory in an industrial control system, characterized in that, The method implements memory allocation by coordinating the management of a set of bit free blocks and a set of byte free blocks, wherein the set of bit free blocks and the set of byte free blocks together represent the entire free state of the memory region; the method includes: Based on the initial address and total size of the memory region, initialize the bit free block set and the byte free block set, so that the bit free block set is initially empty and the byte free block set is initially a free block corresponding to the range of the memory region; In response to a memory operation request for a variable, a target free block is located in the set of bit free blocks and / or the set of byte free blocks; If the memory operation request is a memory allocation request, the requested memory is divided from the target free block, and the corresponding free block set is updated according to the division result; If the memory operation request is a memory release request, the released memory region is inserted as a new free block into the corresponding free block set.
2. The method according to claim 1, characterized in that, The memory allocation request includes allocation requests with a specified starting address and allocation requests without a specified starting address; the step of searching for a target free block in the bit free block set and / or the byte free block set includes: For the allocation request at the specified starting address, search the corresponding free block set for a free block whose address range includes the specified starting address as the target free block; For the allocation request without a specified starting address, in the corresponding set of free blocks, a free block whose length is not less than the requested memory size is searched as the target free block according to the first matching strategy or the best matching strategy.
3. The method according to claim 1, characterized in that, The method further includes: If the target free block is not found or if the operation is performed periodically according to a preset period, free blocks with consecutive addresses in the bit free block set and the byte free block set are merged.
4. The method according to claim 3, characterized in that, The merging of consecutively addressed free blocks in the bit free block set and the byte free block set includes: The whole-byte free regions recorded in the bit free block set that meet the byte alignment conditions are converted and migrated to the byte free block set for management.
5. The method according to claim 1, characterized in that, The method further includes: The utilization rate of the memory area is calculated based on the total size of the memory area and the total byte length of all free blocks in the bit free block set and the byte free block set. The total byte length of all free blocks is obtained by multiplying the sum of the bit lengths of all free blocks in the bit free block set by 8 and adding the byte lengths of all free blocks in the byte free block set.
6. A variable memory allocation device for an industrial control system, characterized in that, The device performs memory allocation by coordinating the management of a set of bit free blocks and a set of byte free blocks, wherein the set of bit free blocks and the set of byte free blocks together represent the complete free state of the memory region; the device includes: An initialization module is used to initialize the bit free block set and the byte free block set according to the initial address and total size of the memory area, so that the bit free block set is initially empty and the byte free block set is initially a free block corresponding to the range of the memory area; A lookup module is used to search for a target free block in the bit free block set and / or the byte free block set in response to a memory operation request for a variable. The segmentation and update module is used to segment the requested memory from the target free block if the memory operation request is a memory allocation request, and update the corresponding free block set according to the segmentation result; The release module is used to insert the released memory region as a new free block into the corresponding free block set if the memory operation request is a memory release request.
7. The apparatus according to claim 6, characterized in that, The memory allocation request includes allocation requests with a specified starting address and allocation requests without a specified starting address; the search module is specifically used to: for the allocation request with a specified starting address, search in the corresponding free block set for a free block whose address range includes the specified starting address as the target free block; for the allocation request without a specified starting address, search in the corresponding free block set for a free block whose length is not less than the requested memory size according to the first matching strategy or the best matching strategy as the target free block.
8. The apparatus according to claim 6, characterized in that, The device further includes: The merging module is used to merge consecutively addressed free blocks in the bit free block set and the byte free block set when the target free block is not found or when it is executed periodically according to a preset period.
9. The apparatus according to claim 8, characterized in that, The merging module is specifically used to convert and migrate whole-byte free regions that are recorded in the bit free block set and meet the byte alignment conditions to the byte free block set for management.
10. The apparatus according to claim 6, characterized in that, The device further includes: The calculation module is used to calculate the utilization rate of the memory area based on the total size of the memory area and the total byte length of all free blocks in the bit free block set and the byte free block set; wherein, the total byte length of all free blocks is obtained by multiplying the sum of the bit lengths of all free blocks in the bit free block set by 8 and adding the byte lengths of all free blocks in the byte free block set.