Method and terminal for optimizing List set

By statistics and screening the use frequency of elements in the LIST set in the Net framework, the low -frequency use element is transferred to the storage disk, solving the problem of low List collection memory utilization rate, realizing the high -efficiency utilization of memory and the efficient operation of the List collection Essence

CN119336486APending Publication Date: 2025-01-21CONTEMPORARY NEBULA TECH ENERGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411231712.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-04
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

In the NET framework, there are a large number of low-frequency elements in the List collection, which leads to idle memory resources, affects system performance, and frequent memory allocation and recycling increase the burden of garbage collection.

Method used

By statistics on the frequency of the use element in the LIST set, the element that uses the frequency of use is lower than that of the preset threshold, and transfer it to the storage disk outside the set, and release the occupied memory. When these elements are retrieved, they cached it to the List collection.

Benefits of technology

The idle memory of the LIST set has the occupation of system memory, enhances the utilization rate of the LIST set memory, avoids the low -frequency set element blanking memory, and ensures the efficient operation of the LIST set.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336486A_ABST
    Figure CN119336486A_ABST
Patent Text Reader

Abstract

The invention discloses a method for optimizing a List set and a terminal. The method comprises the following steps: performing memory detection on the List set and counting the use frequency of set elements; screening out set elements of which the use frequencies are lower than a preset threshold value; transferring the screened set elements to a storage disk outside the List set, and releasing the occupied memory; and detecting a retrieval demand of the set element, and when the set element transferred to the storage disk is retrieved and hit, caching the set element to the List set again. The use frequency of the set elements in the List set is counted, the set elements with too low use frequency are transferred from the List set to the storage disk outside the set, and the occupied List memory is released, so that the occupation of the idle memory of the List set on the memory of the system is reduced, the utilization rate of the memory of the List set is improved, and the memory utilization rate of the List set is increased. Elements of the low-frequency set are prevented from occupying the memory, and efficient operation of the List set is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing, and in particular to a method and a terminal for optimizing a List set. Background Art

[0002] NET (pronounced "dot net") is a software framework developed by Microsoft. It aims to provide a unified platform for developing and running applications. It is widely used in many fields such as Web applications (ASP.NET), desktop applications (WinForms, WPF), mobile applications, game development, Internet of Things (IoT), etc. It provides powerful development tools, rich library support and high flexibility. It is an important part of modern software development.

[0003] In .NET, List is a very commonly used collection type. It is a class in the System.Collections.Generic namespace and is used to store a collection of objects of a specified type. <t>As a common collection type in the .NET framework, it is widely used in caching scenarios to improve data access efficiency and reduce frequent requests to external resources (such as databases and remote services).

[0004] When using List <t>In the scenario where List is used as a cache medium to store big data, <t>When there are a large number of low-frequency elements in a collection, these elements occupy memory space, but the actual usage frequency is very low, resulting in a large amount of memory resources being idle and cannot be effectively utilized. This situation is particularly serious in systems with limited memory resources and may affect the overall performance of the system. Although the garbage collection mechanism in the NET framework can automatically manage memory, frequent memory allocation and recycling operations will increase the burden of garbage collection and affect the response speed and performance of the application. Especially in large-scale data processing and high concurrency scenarios, poor memory management may cause garbage collection to be triggered frequently, thereby affecting system stability. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide a method and a terminal for optimizing List collection, so as to solve the problem of low memory utilization of List collection in NET framework.

[0006] In order to solve the above technical problems, the technical solution adopted by the present invention is:

[0007] A method for optimizing a List collection, comprising the steps of:

[0008] S1. Perform memory detection on the List collection and count the usage frequency of the collection elements;

[0009] S2, filtering out the set elements whose usage frequency is lower than a preset threshold;

[0010] S3, transferring the filtered set elements to a storage disk outside the List set and releasing the occupied memory;

[0011] S4. Detect the retrieval demand of the set element, and when the set element transferred to the storage disk is searched and hit, cache the set element again to the List set.

[0012] In order to solve the above technical problems, another technical solution adopted by the present invention is:

[0013] A terminal for optimizing a List set includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor completes the following steps when executing the computer program:

[0014] S1. Perform memory detection on the List collection and count the usage frequency of the collection elements;

[0015] S2, filtering out the set elements whose usage frequency is lower than a preset threshold;

[0016] S3, transferring the filtered set elements to a storage disk outside the List set and releasing the occupied memory;

[0017] S4. Detect the retrieval demand of the set element, and when the set element transferred to the storage disk is searched and hit, cache the set element again to the List set.

[0018] The beneficial effects of the present invention are: providing a method and terminal for optimizing a List set, by counting the usage frequencies of set elements in the List set, transferring set elements with too low usage frequencies from the List set to a storage disk outside the set, and releasing the occupied List memory, thereby reducing the occupation of the idle memory of the List set to the system memory, and at the same time improving the utilization rate of the List set memory, avoiding low-frequency set elements occupying empty memory, and ensuring the efficient operation of the List set. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 A flowchart of a method for optimizing a List set in an embodiment of the present invention;

[0020] Figure 2 This is a schematic diagram of a terminal for optimizing a List set in an embodiment of the present invention;

[0021] Description of labels:

[0022] 1. A terminal for optimizing List collection; 2. Memory; 3. Processor. DETAILED DESCRIPTION

[0023] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.

[0024] Please refer to Figure 1 , a method for optimizing a List collection, comprising the steps of:

[0025] S1. Perform memory detection on the List collection and count the usage frequency of the collection elements;

[0026] S2, filtering out the set elements whose usage frequency is lower than a preset threshold;

[0027] S3, transferring the filtered set elements to a storage disk outside the List set;

[0028] S4. Detect the retrieval demand of the set element, and when the set element transferred to the storage disk is searched and hit, cache the set element again to the List set.

[0029] From the above description, it can be seen that the beneficial effect of the present invention is that: by counting the usage frequency of the collection elements in the List collection, the collection elements with too low usage frequency are transferred from the List collection to a storage disk outside the collection, and the occupied List memory is released, thereby reducing the idle memory of the List collection occupying the system memory, and at the same time improving the utilization rate of the List collection memory, avoiding low-frequency collection elements occupying empty memory, and ensuring the efficient operation of the List collection.

[0030] In an embodiment of the present invention, step S1 specifically includes the following steps:

[0031] Use the AutoFreeMemory interface to perform memory detection on the List collection, and use the parameter freeDueTime to set the detection interval; use the GetDatas interface to count the most recent usage time of all collection elements.

[0032] From the above description, it can be seen that the use of the AutoFreeMemory interface and the GetDatas interface can realize automatic monitoring and statistics of the usage of the collection elements, ensure the latest usage time of the data is accurately recorded, and facilitate the screening of low-frequency elements. Preferably, the detection interval is between 1-3s; more preferably, 1s.

[0033] In an embodiment of the present invention, step S2 specifically includes the steps of:

[0034] Filter out the set elements whose difference between the most recent usage time and the current time is greater than a preset threshold;

[0035] The step S3 specifically comprises the following steps:

[0036] The TrimExcess method is used to release the filtered set elements in the List set, and the released set elements are transferred to a storage disk outside the List set.

[0037] From the above description, we can see that by filtering the collection elements whose recent usage time exceeds the preset threshold and releasing these elements using the TrimExcess method, memory usage can be further optimized. At the same time, transferring the released elements to the storage disk can both retain data and reduce memory usage.

[0038] In an embodiment of the present invention, step S4 specifically includes the steps of:

[0039] Detect the retrieval requirements of collection elements, and use the GetDepthDatas interface to search in the List collection. If the corresponding collection element exists in the data list of the List collection but the corresponding collection element is not hit in the cache, temporarily load the corresponding data cached to the storage disk, and cache this collection element to the List collection again.

[0040] From the above description, it can be seen that when the retrieval demand of collection elements is detected, the required data is loaded from the storage disk through the GetDepthDatas interface and re-cached to the List collection to ensure data availability and access efficiency. This method can achieve a balance between memory usage and data availability.

[0041] In an embodiment of the present invention, the step S4 further includes a step S5:

[0042] Detect the memory usage of the List collection. When the memory usage exceeds the preset ratio, dynamically expand the List collection according to the current usage.

[0043] From the above description, it can be seen that after the corresponding memory is released in the above steps, the memory of the List collection is likely to be too low, which makes it difficult to cope with the usage scenarios of processing large amounts of data and multi-device clusters. In order to solve this problem, by detecting the memory usage of the List collection and dynamically expanding the capacity when it exceeds the preset ratio, insufficient memory can be prevented and the List collection can be ensured to run efficiently under high load.

[0044] Specifically, the dynamic expansion ratio is specified according to the memory usage rate. For example, when the List collection usage rate is ≥80%, the expansion ratio is 1.5 times the current memory capacity; when the usage rate is ≥60%, the expansion ratio is 1.4 times the current memory capacity; when the usage rate is ≥40%, the next expansion ratio is 1.3 times; when the usage rate is ≥20%, the expansion ratio is 1.2 times the current memory capacity; in other scenarios, the expansion ratio is 1.1 times the current memory capacity. If the collection capacity usage rate decreases within the preset time, it means that the collection's demand for capacity expansion has decreased. The next expansion will use the next level of expansion ratio to effectively control capacity application, improve content utilization, and avoid a large amount of idle memory.

[0045] A terminal for optimizing a List set comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, steps in a method for optimizing a List set are completed.

[0046] From the above description, it can be seen that an execution carrier of a method for optimizing a List collection is provided. In the process of executing the above method, by counting the usage frequencies of collection elements in the List collection, collection elements with too low usage frequencies are transferred from the List collection to a storage disk outside the collection, and the occupied List memory is released, thereby reducing the occupation of the idle memory of the List collection on the system memory. At the same time, the utilization rate of the List collection memory is improved, avoiding low-frequency collection elements occupying empty memory, and ensuring the efficient operation of the List collection.

[0047] The present invention provides a method and a terminal for optimizing a List collection, which are mainly applied to improve the memory usage efficiency of a List collection under a NET framework, and are specifically described below with reference to embodiments.

[0048] Please refer to Figure 1 , Embodiment 1 of the present invention is:

[0049] A method for optimizing a List collection, comprising the steps of:

[0050] S1. Perform memory detection on the List collection and count the usage frequency of the collection elements;

[0051] S2, filter out the set elements whose usage frequency is lower than a preset threshold;

[0052] S3, transferring the filtered set elements to a storage disk outside the List set;

[0053] S4. Detect the retrieval demand of the collection element. When the collection element transferred to the storage disk is searched and hit, cache the collection element to the List collection again.

[0054] That is, in this embodiment, by counting the usage frequency of the collection elements in the List collection, the collection elements with too low usage frequency are transferred from the List collection to a storage disk outside the collection, and the occupied List memory is released, thereby reducing the occupation of the idle memory of the List collection on the system memory. At the same time, the utilization rate of the List collection memory is improved, avoiding low-frequency collection elements occupying empty memory, and ensuring the efficient operation of the List collection.

[0055] Please refer to Figure 1 , Embodiment 2 of the present invention is:

[0056] Based on the first embodiment, step S1 specifically includes the following steps:

[0057] Use the AutoFreeMemory interface to perform memory detection on the List collection, and use the parameter freeDueTime to set the detection interval; use the GetDatas interface to count the most recent usage time of all collection elements. Using the AutoFreeMemory interface and the GetDatas interface, you can automatically monitor and count the usage of collection elements, ensure that the latest usage time of the data is accurately recorded, and facilitate the screening of low-frequency elements; the detection interval is 1s.

[0058] Step S2 specifically includes the following steps:

[0059] Filter out the set elements whose difference between the most recently used time and the current time is greater than a preset threshold;

[0060] Step S3 specifically includes the following steps:

[0061] Use the TrimExcess method to release the filtered collection elements in the List collection and transfer the released collection elements to a storage disk outside the List collection.

[0062] Step S4 specifically includes the following steps:

[0063] Detect the retrieval requirements of collection elements, use the GetDepthDatas interface to search in the List collection, if the corresponding collection element exists in the data list of the List collection but the corresponding collection element is not hit in the cache, temporarily load the corresponding data cached to the storage disk, and cache this collection element again to the List collection. Detect the retrieval requirements of collection elements, use the GetDepthDatas interface to search in the List collection, if the corresponding collection element exists in the data list of the List collection but the corresponding collection element is not hit in the cache, temporarily load the corresponding data cached to the storage disk, and cache this collection element again to the List collection.

[0064] Please refer to Figure 1 , Embodiment 3 of the present invention is:

[0065] Based on the first or second embodiment, step S4 further includes step S5:

[0066] Detect the memory usage of the List collection. When the memory usage exceeds the preset ratio, dynamically expand the List collection according to the current usage;

[0067] The specific steps include: when the usage rate of the List collection is ≥80%, the expansion ratio is 1.5 times the current memory capacity; when the usage rate is ≥60%, the expansion ratio is 1.4 times the current memory capacity; when the usage rate is ≥40%, the next expansion ratio is 1.3 times; when the usage rate is ≥20%, the expansion ratio is 1.2 times the current memory capacity; in other scenarios, the expansion ratio is 1.1 times the current memory capacity. If the collection capacity usage rate decreases within the preset time, it means that the collection's demand for capacity expansion has decreased. The next expansion will use the next level of expansion ratio to effectively control capacity application, improve content utilization, and avoid a large amount of idle memory.

[0068] That is, in this embodiment, after the corresponding memory is released in the above steps, the memory of the List collection is likely to be too low, which makes it difficult to cope with the usage scenarios of processing large amounts of data and multi-device clusters. In order to solve this problem, by detecting the memory usage rate of the List collection and dynamically expanding the capacity when it exceeds the preset ratio, insufficient memory can be prevented and the List collection can be ensured to still run efficiently under high load.

[0069] Specifically, step S5 further includes step S6:

[0070] Monitor the number of collection elements and the memory of collection elements in the List collection. When either the number of collection elements or the memory of collection elements exceeds the set value, an alarm is issued.

[0071] Specifically, in List <t>Add UpCountEvent and UpMemoryEvent events to the collection:

[0072] List <t>exList=new List <t>(100,4086) means instantiating a List <t>, and set the upper limit warning value of the number of collection elements to 50 and the memory warning value to 4086KB (collection elements are objects stored in the collection, which can be value type or reference type data).

[0073] When List <t>If the number of collection elements exceeds 50, an UpCountEvent event will be triggered and an alarm will be processed.

[0074] List <t>The collection calculates the memory size occupied by each element T (the memory size is calculated according to the data type: int is calculated as 4 bytes, long is calculated as 8 bytes, and string type is calculated as the actual length). When the total memory occupied by the elements is greater than the budget value of 4086KB, the UpMemoryEvent event is triggered and an alarm is processed.

[0075] Please refer to Figure 1 , Embodiment 4 of the present invention is:

[0076] A method for optimizing List collection is specifically applied as follows:

[0077] S1. Perform memory detection on the List collection and count the usage frequency of the collection elements:

[0078] Use the AutoFreeMemory interface to set the memory detection interval, for example, once every 1 second. When using the GetDatas interface to obtain collection elements, record the most recent usage time LastActiveTime of each element.

[0079] S2. Filter out the set elements whose usage frequency is lower than the preset threshold:

[0080] Traverse the List collection and filter out the elements whose difference between the most recently used time and the current time is greater than a preset threshold (for example, 30 minutes).

[0081] S3. Transfer the filtered set elements to the storage disk:

[0082] Use the TrimExcess method to release the filtered low-frequency elements and transfer them to the storage disk to free up memory space.

[0083] S4. Detection of retrieval requirements for set elements:

[0084] When you need to retrieve a collection element, use the GetDepthDatas interface to retrieve it from the List collection. If it does not hit the cache, load the corresponding data from the storage disk and re-cache it to the List collection.

[0085] S5. Check the memory usage of the List collection:

[0086] The memory usage of the List collection is checked regularly. If it exceeds a preset ratio (e.g. 80%), the collection is dynamically expanded to prevent insufficient memory and improve system stability.

[0087] Please refer to Figure 1 , Embodiment 5 of the present invention is:

[0088] A terminal 1 for optimizing a List set includes a memory 2, a processor 3, and a computer program stored in the memory 2 and executable on the processor 3. When the processor 3 executes the computer program, the steps in any one of the methods for optimizing a List set in embodiments 1 to 4 are completed.

[0089] In summary, a method and terminal for optimizing List collections are provided. By counting the usage frequency of collection elements in the List collection, collection elements with too low usage frequency are transferred from the List collection to a storage disk outside the collection, and the occupied List memory is released, reducing the occupation of the idle memory of the List collection on the system memory, while improving the utilization rate of the List collection memory, avoiding low-frequency collection elements occupying the memory, and ensuring the efficient operation of the List collection. In addition, the usage rate of the List collection is monitored while the memory is released, and the List memory is dynamically expanded to avoid excessive memory release leading to degradation of List collection performance.

[0090] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.< / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t>

Claims

1. A method for optimizing a List collection, characterized in that: Includes steps: S1. Perform memory detection on the List collection and count the usage frequency of the collection elements; S2, filtering out the set elements whose usage frequency is lower than a preset threshold; S3, transferring the filtered set elements to a storage disk outside the List set and releasing the occupied memory; S4. Detect the retrieval demand of the set element, and when the set element transferred to the storage disk is searched and hit, cache the set element again to the List set.

2. A method for optimizing a List set according to claim 1, characterized in that: The step S1 specifically includes the following steps: Use the AutoFreeMemory interface to perform memory detection on the List collection, and use the parameter freeDueTime to set the detection interval; use the GetDatas interface to count the most recent usage time of all collection elements.

3. A method for optimizing a List set according to claim 2, characterized in that: The step S2 specifically includes the following steps: Filter out the set elements whose difference between the most recent usage time and the current time is greater than a preset threshold; The step S3 specifically comprises the following steps: The TrimExcess method is used to release the filtered set elements in the List set, and the released set elements are transferred to a storage disk outside the List set.

4. A method for optimizing a List set according to claim 1, characterized in that: The step S4 specifically comprises the following steps: Detect the retrieval requirements of collection elements, and use the GetDepthDatas interface to search in the List collection. If the corresponding collection element exists in the data list of the List collection but the corresponding collection element is not hit in the cache, temporarily load the corresponding data cached to the storage disk, and cache this collection element to the List collection again.

5. The method for optimizing a List set according to claim 1, characterized in that: The step S4 further includes a step S5: Detect the memory usage of the List collection. When the memory usage exceeds the preset ratio, dynamically expand the List collection according to the current usage.

6. A terminal for optimizing a List collection, characterized in that: The invention comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are performed: S1. Perform memory detection on the List collection and count the usage frequency of the collection elements; S2, filtering out the set elements whose usage frequency is lower than a preset threshold; S3, transferring the filtered set elements to a storage disk outside the List set and releasing the occupied memory; S4. Detect the retrieval demand of the set element, and when the set element transferred to the storage disk is searched and hit, cache the set element again to the List set.

7. A terminal for optimizing List set according to claim 6, characterized in that: The step S1 specifically includes the following steps: Use the AutoFreeMemory interface to perform memory detection on the List collection, and use the parameter freeDueTime to set the detection interval; use the GetDatas interface to count the most recent usage time of all collection elements.

8. A terminal for optimizing List set according to claim 7, characterized in that: The step S2 specifically includes the following steps: Filter out the set elements whose difference between the most recent usage time and the current time is greater than a preset threshold; The step S3 specifically comprises the following steps: The TrimExcess method is used to release the filtered set elements in the List set, and the released set elements are transferred to a storage disk outside the List set.

9. A terminal for optimizing List set according to claim 6, characterized in that: The step S4 specifically comprises the following steps: Detect the retrieval requirements of collection elements, and use the GetDepthDatas interface to search in the List collection. If the corresponding collection element exists in the data list of the List collection but the corresponding collection element is not hit in the cache, temporarily load the corresponding data cached to the storage disk, and cache this collection element to the List collection again.

10. The terminal for optimizing List set according to claim 6, characterized in that: The step S4 further includes a step S5: Detect the memory usage of the List collection. When the memory usage exceeds the preset ratio, dynamically expand the List collection according to the current usage.