Resource loading method and device, electronic equipment and computer readable storage medium
By setting priorities for generating resource objects for resource loading requests and dynamically adjusting them in a multi-level queue, the problem of low flexibility in resource loading schemes is solved, achieving an efficient and flexible resource loading process, ensuring timely availability of critical resources, and improving the resource loading efficiency and user experience of the map editor.
Patent Information
- Application Number
- CN202411105541.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2026-02-13
AI Technical Summary
Existing resource loading schemes lack flexibility and cannot set the priority of resources to be loaded, resulting in high-priority resource loading requests being blocked by low-priority resource requests, making it difficult to guarantee resource loading efficiency and state consistency.
By generating resource objects corresponding to resource loading requests, setting priorities, and storing resource objects in the first queue, they are arranged according to priority and then swapped to the second queue for loading. Priorities are dynamically adjusted to ensure that high-priority resources are loaded first and low-priority resources are loaded asynchronously. Multi-level feedback queues are used to manage resource objects.
It improves the flexibility and efficiency of resource loading, ensures that high-priority resources are loaded in a timely manner, improves application response speed and user experience, and maintains the consistency of resource object state.
Smart Images

Figure CN121523749A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a resource loading method, a resource loading device, an electronic device, and a computer-readable storage medium. Background Technology
[0002] Map editors can display point clouds, tracks, photos, and operational data by executing a resource loading process. Specifically, the resource loading process requires loading data of different types and from different sources (such as disk and network) into memory. Related technologies use a queue to manage resource loading requests. When a resource needs to be loaded, the application adds the request to this queue. Then, one or more background threads process the resource loading requests in the order they appear in the queue.
[0003] However, the resource loading solutions provided by the related technologies are not very flexible. Summary of the Invention
[0004] This application provides a resource loading method, a resource loading device, an electronic device, and a computer-readable storage medium, which can provide the opportunity to set the priority of resources to be loaded, so that resources with higher priority will be loaded first compared with resources with lower priority, thereby improving the flexibility of resource loading in the map editor; it can also ensure the consistency of the state of resource objects, which is beneficial to improving the resource loading efficiency of the map editor.
[0005] In a first aspect, this application provides a resource loading method, the method comprising: generating a resource object corresponding to a resource loading request, wherein the attribute of the resource object includes priority; adding the resource object to a first queue, wherein the resource objects in the first queue are stored according to the priority; swapping out the resource objects in the first queue; adding the swapped resource objects to a second queue, wherein the resource objects in the second queue are arranged according to the priority; and loading the resource objects according to the arrangement order of the resource objects in the second queue.
[0006] In the solution provided in the first aspect, a resource object corresponding to the resource loading request is generated. The priority of each resource to be loaded can be set through the attributes of the resource object. Furthermore, the resource objects in the second queue are arranged according to priority. Therefore, high-priority resource objects will be loaded first; for example, synchronous loading can be selected to ensure the timely availability of critical resources. Low-priority resource objects can be loaded asynchronously to improve application response speed and user experience. The solution provided in this application embodiment allows users to conveniently control the order of resource loading, which is beneficial to improving the flexibility of resource loading.
[0007] Specifically, before adding the resource objects to the second queue, the method further includes: adding the resource objects to the first queue, wherein the resource objects in the first queue are stored according to the priority; and swapping out the resource objects stored in the first queue to add all the resource objects stored in the first queue to the second queue at once. On the one hand, resources in the first queue can be stored according to priority, ensuring that resources are loaded according to priority. On the other hand, the first queue serves as temporary storage for resource objects, and by moving all resource objects in the first queue to the second queue at once through a swap operation, it avoids adding resources to the second queue while the loading thread is processing the second queue, thus maintaining the consistency of the resource object state and ensuring that the resource objects in the second queue do not increase indefinitely. Furthermore, this embodiment uses a multi-level feedback queue (second queue and first queue) to manage resource objects. Each loading process retrieves resource objects from the first queue at once, and the first queue is updated every frame. Therefore, it avoids the problem of users having to wait a long time to use new resources due to canceled resource loading.
[0008] In an exemplary embodiment, based on the above scheme, the first queue includes N containers corresponding to N priorities, where N is a positive integer and not less than the total number of priorities of the resource objects; adding the resource objects to the first queue includes: adding the resource object with the attribute of priority i to the i-th container in the first queue, where i is a positive integer not greater than N.
[0009] In the solution provided in this embodiment, resources in the first queue can be stored according to priority to ensure that resources are loaded according to priority.
[0010] In an exemplary embodiment, based on the above scheme, the above-mentioned resource loading according to the arrangement order of the resource objects in the second queue includes: loading the resource objects into a loading thread according to the arrangement order of the resource objects in the second queue, so that the loading thread can load the resource objects based on the priority; the method further includes: if the addition of the resource object to the loading thread fails, adjusting the priority of the resource object; wherein the adjustment method includes any one of the following: increasing the sub-priority while maintaining the current priority; increasing the priority based on the current priority.
[0011] In the solution provided in this embodiment, the priority of a resource object is dynamically adjusted based on its state during the resource loading process. Specifically, if a resource object fails to be added to the loading thread, its priority is increased to obtain another opportunity to be added to the loading thread as soon as possible. This strategy ensures that all resources are loaded correctly, thereby improving the efficiency and stability of the system.
[0012] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a first count, which represents the number of times the resource object failed to be added to the loading thread; if the resource object fails to be added to the loading thread, the method further includes: increasing the first count of the resource object, wherein the first count is used to determine the adjustment range of the priority of the resource object.
[0013] In the solution provided in this embodiment, the priority adjustment range of the resource object is determined based on the number of times the resource object fails to be added to the loading thread, thereby allowing for reasonable priority adjustment.
[0014] In an exemplary embodiment, based on the above scheme, after loading the resource object into the loading thread, the method further includes: if the resource loading of the resource object fails, adjusting the priority of the resource object; wherein the adjustment method includes any one of the following: reducing the sub-priority while maintaining the current priority; or reducing the priority based on the current priority.
[0015] In the solution provided in this embodiment, the priority of a resource object is dynamically adjusted based on its state during the resource loading process. Specifically, if a resource object fails to load in a loading thread, its priority is lowered to give other resource objects a chance to load, so that even resource objects with lower priorities than the first one have a chance to be loaded instead of waiting indefinitely.
[0016] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a second number, which represents the number of times the resource object failed to load resources; if the resource object fails to load resources, the method further includes: increasing the second number of the resource object, wherein the second number is used to determine the adjustment range of the priority of the resource object.
[0017] In the solution provided in this embodiment, the priority adjustment range of the resource object is determined based on the number of times the resource loading fails after the resource object is added to the loading thread, so that the priority can be adjusted reasonably.
[0018] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes usage time, wherein the usage time represents the time when the resource object was last used; the method further includes: updating the usage time of the resource object in response to successful resource loading of the resource object, or in response to the successful loading of the resource object being used; wherein the usage time of the successfully loaded resource object is used to determine the resource object to be unloaded.
[0019] In the solution provided in this embodiment, the last usage time of each resource object is continuously monitored. When the memory usage reaches a first threshold, the resource will be unloaded based on the last usage time to ensure effective memory utilization.
[0020] In an exemplary embodiment, based on the above scheme, the method further includes: in response to successful resource loading of the resource object, storing the resource object in a binary memory block; obtaining the occupancy information of the binary memory block; if the occupancy information of the binary memory block exceeds a first threshold, determining a first resource object to be unloaded based on the usage time of the resource object in the binary memory block; and unloading the first resource object so that the occupancy information of the binary memory block is less than the first threshold.
[0021] In the solution provided in this embodiment, binary memory blocks (Blobs) are used to store loaded resources. The GetSize function can be used to accurately calculate the memory size occupied by the binary memory blocks. Therefore, resources are unloaded when the memory usage exceeds a preset threshold, thus achieving precise control over memory usage. Furthermore, this separates the resource loading and usage processes, allowing resources to be loaded on demand—only when truly needed—significantly reducing memory usage during startup or initialization, improving application startup speed and user experience. Simultaneously, version information can be written to the header of the Blob during writing, and the reading side parses the resource based on the version information, thereby achieving version control for data of the same type.
[0022] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a pointer to the loaded resource; the method further includes: in response to the successful loading of the second resource object, controlling the pointer of the second resource object to point to the loaded resource.
[0023] In an exemplary embodiment, based on the above scheme, generating the resource object corresponding to the resource loading request includes: responding to the target task being triggered, generating at least one resource loading request corresponding to the target task in the main thread; generating resource objects corresponding to the at least one resource loading request respectively in the main thread to obtain at least one resource object corresponding to the target task, wherein each of the resource objects is managed by reference counting.
[0024] In the solution provided in this embodiment, each resource object is managed through reference counting. When the reference count of a resource object is zero, it means that no other object is referencing it, and the resource object can be safely released. Therefore, when the unloading thread unloads a resource, there is no need to worry that the resource is being used by the main thread.
[0025] In an exemplary embodiment, based on the above scheme, in response to the target task being closed, the reference count of the resource object corresponding to the target task is controlled to be zero in the main thread.
[0026] In the solution provided in this embodiment, each resource object is managed by reference counting. Therefore, when the task is closed, it is not necessary to wait for the resources to be unloaded. The reference count of the resource object corresponding to the target task is controlled to be zero in the main thread, so that the task-related resources do not need to be unloaded. This greatly reduces the task closure time, for example, from two or three minutes to less than 30 seconds.
[0027] In an exemplary embodiment, based on the above scheme, the attributes of the target resource object further include unified resource location information; generating the resource object corresponding to each of the at least one resource loading request includes: generating the resource object corresponding to the source loading request based on the unified resource location information carried in the resource loading request and the priority of the resource to be loaded.
[0028] In an exemplary embodiment, based on the above scheme, the unified resource location information includes resource type and source location of the resource; the resource type includes any one of the following: point cloud, trajectory, image, and operation data.
[0029] In the solution provided in this embodiment, resources of different types and sources, such as disk file resources and network resources, are processed in a unified manner, so that users can request various resources in the same way, which helps to improve the scope of application and practicality.
[0030] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a loading state; the method further includes at least one of the following: after the resource object is added to the second queue, the loading state of the resource object is updated to a first state, the first state indicating pending loading; after the resource object is successfully added to the loading thread, the loading state of the resource object is updated to a second state, the second state indicating loading is in progress; after the resource loading process of the resource object is successfully completed, the loading state of the resource object is updated to a third state, the third state indicating successful loading; after the resource loading process of the resource object fails and the number of consecutive failures reaches a second threshold, the loading state of the resource object is updated to a fourth state, the fourth state indicating loading failure.
[0031] In the solution provided in this embodiment, the loading status of the resource object is continuously updated during the resource loading process, which makes it easier to obtain the current resource loading status of the resource object, thereby ensuring that the same resource is loaded only once and avoiding repeated loading of resources.
[0032] In the solution provided in this embodiment, based on the above solution, the method further includes: obtaining the resource status of all resource objects corresponding to the target task in the main thread; if the resource status of all resource objects corresponding to the target task is the third state or the fourth state, then it is determined that the resource loading of the target task is complete.
[0033] In the solution provided in this embodiment, based on the above solution, adding the resource object to the first queue includes: adding the resource object to the first queue in the main thread; swapping out the resource object from the first queue includes: swapping out the resource object from the first queue in the preloading thread; adding the resource object to the second queue includes: adding the resource object to the second queue in the preloading thread; and loading the resource object according to the arrangement order of the resource objects in the second queue includes: loading the resource object according to the arrangement order of the resource objects in the second queue in the loading thread.
[0034] Secondly, this application provides a resource loading device, which includes: an object generation module, a first queue module, an exchange operation module, a second queue module, and a resource loading module;
[0035] The aforementioned object generation module is used to generate resource objects corresponding to resource loading requests, wherein the attributes of the resource objects include priority; the aforementioned first queue module is used to add the resource objects to a first queue, wherein the resource objects in the first queue are stored according to the aforementioned priority; the aforementioned exchange operation module is used to exchange the resource objects in the first queue; the aforementioned second queue module is used to add the exchanged resource objects to a second queue, wherein the resource objects in the second queue are arranged according to the aforementioned priority; and the aforementioned resource loading module is used to load the resource objects according to the arrangement order of the resource objects in the second queue.
[0036] In an exemplary embodiment, based on the above scheme, the first queue includes N containers corresponding to N priorities, where N is a positive integer and not less than the total number of priorities of the resource objects.
[0037] The first queue module mentioned above is specifically used to add resource objects with the attribute of priority i to the i-th container in the first queue, where i is a positive integer not greater than N.
[0038] In an exemplary embodiment, based on the above scheme, the resource loading module is specifically used to: load the resource objects into the loading thread according to the arrangement order of the resource objects in the second queue, so that the loading thread can load the resource objects based on the priority.
[0039] The aforementioned resource loading device further includes a priority adjustment module; wherein the priority adjustment module is used to: if the addition of the aforementioned resource object to the aforementioned loading thread fails, adjust the priority of the aforementioned resource object; wherein the adjustment method includes any one of the following: increasing the sub-priority while maintaining the current priority; increasing the priority based on the current priority.
[0040] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a first count, which represents the number of times the resource object failed to be added to the loading thread; the priority adjustment module is specifically used to: increase the first count of the resource object, wherein the first count is used to determine the adjustment range of the priority of the resource object.
[0041] In an exemplary embodiment, based on the above scheme, the priority adjustment module is further configured to: after loading the resource object into the loading thread, if the loading of the resource object fails, adjust the priority of the resource object; wherein the adjustment method includes any one of the following: reducing the sub-priority while maintaining the current priority; or reducing the priority based on the current priority.
[0042] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a second number, which represents the number of times the resource object failed to load resources; the priority adjustment module is further used to: if the resource object fails to load resources, increase the second number of the resource object, wherein the second number is used to determine the adjustment range of the priority of the resource object.
[0043] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes usage time, wherein the usage time represents the time when the resource object was last used; the resource loading device further includes: a usage time update module; wherein the usage time update module is used to: update the usage time of the resource object in response to successful loading of the resource object, or in response to the successfully loaded resource object being used; wherein the usage time is used to determine the resource object corresponding to the resource to be uninstalled.
[0044] In an exemplary embodiment, based on the above scheme, the resource loading device further includes a resource unloading module; wherein the resource unloading module is configured to: in response to successful loading of the resource object, store the loaded resource in a binary memory block; obtain the occupancy information of the binary memory block; if the occupancy information of the binary memory block exceeds a first threshold, determine a first resource object corresponding to the resource to be unloaded based on the usage time; and unload the resource corresponding to the first resource object so that the occupancy information of the binary memory block is less than the first threshold.
[0045] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a pointer to the loaded resource; the resource loading device further includes a pointer control module; wherein the pointer control module is used to: in response to successful loading of the second resource object, control the pointer of the second resource object to point to the loaded resource.
[0046] In an exemplary embodiment, based on the above scheme, the object generation module is specifically used to: in response to the triggering of a target task, generate at least one resource loading request corresponding to the target task in the main thread; and generate resource objects corresponding to the at least one resource loading request in the main thread to obtain at least one resource object corresponding to the target task, wherein each resource object is managed by reference counting.
[0047] In an exemplary embodiment, based on the above scheme, the resource loading device further includes an object management module; wherein the object management module is used to: in response to the target task being closed, control the reference count of the resource object corresponding to the target task to be zero in the main thread.
[0048] In an exemplary embodiment, based on the above scheme, the attributes of the target resource object further include unified resource location information; the object generation module is specifically used to: generate the resource object corresponding to the source loading request based on the unified resource location information carried in the resource loading request and the priority of the resource to be loaded.
[0049] In an exemplary embodiment, based on the above scheme, the unified resource location information includes resource type and source location of the resource; the resource type includes any one of the following: point cloud, trajectory, image, and operation data.
[0050] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a loading state; the resource loading device further includes a state update module; wherein the state update module is used for at least one of the following:
[0051] After the resource object is added to the second queue, its loading status is updated to the first state, indicating that it is pending loading. After the resource object is successfully added to the loading thread, its loading status is updated to the second state, indicating that it is loading. After the resource loading process is successful, its loading status is updated to the third state, indicating that the loading is successful. After the resource loading process fails and the number of consecutive failures reaches a second threshold, its loading status is updated to the fourth state, indicating that the loading has failed.
[0052] In an exemplary embodiment, based on the above scheme, the resource loading device further includes a state determination module; wherein the state determination module is used to: obtain the resource status of all resource objects corresponding to the target task in the main thread; if the resource status of all resource objects corresponding to the target task is a third state or a fourth state, then determine that the resource loading of the target task is completed.
[0053] In an exemplary embodiment, based on the above scheme, the first queue module is specifically used to: add the resource object to the first queue in the main thread; the swap operation module is specifically used to: swap the resource object out of the first queue in the preloading thread; the second queue module is specifically used to: add the resource object to the second queue in the preloading thread; and the resource loading module is specifically used to: load the resource object according to the arrangement order of the resource objects in the second queue in the loading thread.
[0054] Thirdly, an electronic device is provided, including a processor and a memory. The memory is used to store a computer program, and the processor is used to invoke and run the computer program stored in the memory to perform the resource loading method provided in the first aspect or any embodiment thereof.
[0055] Fourthly, a chip is provided for implementing the methods of any one of the first aspects or their implementations. Specifically, the chip includes a processor for calling and running a computer program from a memory, causing a device equipped with the chip to perform the resource loading method provided in the first aspect or any embodiment thereof.
[0056] Fifthly, a computer-readable storage medium is provided for storing a computer program that causes a computer to execute the resource loading method provided in the first aspect or any embodiment thereof.
[0057] In a sixth aspect, a computer program product is provided, including computer program instructions that cause a computer to execute the resource loading method provided in the first aspect or any embodiment thereof.
[0058] In a seventh aspect, a computer program is provided that, when run on a computer, causes the computer to perform the resource loading method provided in the first aspect or any embodiment thereof.
[0059] In summary, the solution provided in this application generates resource objects corresponding to resource loading requests. The attributes of these resource objects allow for setting priorities for each resource to be loaded. Furthermore, the multiple resource objects in the second queue are arranged according to priority, and the map editor executes the resource loading process based on the order of these objects in the second queue. Therefore, the solution provided in this application offers the opportunity to set the priority of resources to be loaded, allowing users to easily control the order of resource loading and improving the flexibility of resource loading. Additionally, resource objects are first stored in the first queue according to priority, and then all resource objects in the first queue are swapped out through a swap operation and added to the second queue at once. This avoids adding resources to the second queue while the loading thread is processing the second queue, thus maintaining the consistency of the resource object state during the resource loading process and improving the resource loading efficiency of the map editor. Attached Figure Description
[0060] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0061] Figure 1 A flowchart illustrating the resource loading method provided in this application embodiment;
[0062] Figure 2 A schematic block diagram of the first queue provided in an embodiment of this application;
[0063] Figure 3 A schematic block diagram of the second queue provided in an embodiment of this application;
[0064] Figure 4 A flowchart illustrating the resource loading method provided in this application embodiment;
[0065] Figure 5 A flowchart illustrating the resource unloading method provided in this application embodiment;
[0066] Figure 6 A flowchart illustrating the resource loading method provided in this application embodiment;
[0067] Figure 7 A flowchart illustrating the method for loading resources in a high-precision map editor provided in this application embodiment;
[0068] Figure 8 A schematic block diagram of a resource loading device provided in an embodiment of this application;
[0069] Figure 9 A schematic block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0070] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0071] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in sequences other than those illustrated or described herein. In embodiments of this application, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices. In the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0072] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0073] The solution provided in this application can be applied to high-definition map editors. High-definition map editors (HighDefinition Maps or High Precision Maps) typically refer to map data with extremely high detail and accuracy, i.e., high-precision map data. For example, high-precision map data not only includes route and location information from traditional maps but also contains more detailed environmental information, such as road signs, traffic signals, traffic signs, lane lines, and ground arrows. This information is crucial for applications such as autonomous driving. Therefore, after compilation, high-precision map data can be used in navigation, autonomous driving, and other fields to support these systems in performing accurate positioning, perception, and decision-making in complex environments.
[0074] It should be noted that the resource loading scheme provided in this application embodiment can also be applied to scenarios such as audio and video processing, image processing, and network communication, and this application embodiment does not limit it in this regard.
[0075] In the resource loading schemes provided by related technologies, a queue is used to manage resource loading requests. When a resource needs to be loaded, the application adds the resource loading request to this queue. Then, one or more background threads process the resource loading requests in the order they appear in the queue. However, in the resource loading process using the schemes provided by these technologies, once resource loading requests are added to the queue, their order is difficult to change, which may lead to some important resources not being loaded in a timely manner. Furthermore, because the priority of resources to be loaded cannot be set, resource loading requests for high-priority resources may be blocked by resource loading requests for low-priority resources. Therefore, the resource loading schemes provided by these technologies have a need for improved flexibility.
[0076] To address the aforementioned technical problems in related technologies, this application proposes a resource loading scheme according to its embodiments. Specifically, the resource loading scheme provided in this application generates resource objects corresponding to resource loading requests, and the priority of each resource to be loaded can be set through the attributes of the resource objects. Furthermore, multiple resource objects in the second queue are arranged according to priority, and the map editor will execute the resource loading process according to the order of the resource objects in the second queue. It is evident that the scheme provided in this application provides the opportunity to set the priority of resources to be loaded, allowing users to adjust the resource loading order according to the priority of resource loading requests. Higher-priority resource objects will be loaded first; for example, synchronous loading can be selected to ensure timely availability of critical resources, while lower-priority resource objects can be loaded asynchronously to improve application response speed and user experience. The scheme provided in this application allows users to conveniently control the resource loading order, which is beneficial for improving the flexibility of resource loading. In addition, in the solution provided in this application embodiment, resource objects are first stored in a first queue according to priority, and all resource objects in the first queue are swapped out through a swap operation to be added to the second queue at once. This avoids adding resources to the second queue while the loading thread is processing the second queue, thereby maintaining the consistency of the resource object state during the resource loading process and improving the resource loading efficiency of the map editor.
[0077] The technical solutions of the embodiments of this application will be described in detail below through some examples. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0078] Figure 1 This is a flowchart illustrating the resource loading method P100 provided in this application embodiment. The executing entity of method P100 is an electronic device deployed with a map editor, which can be a terminal or a server. For example, the server can be a cloud server, specifically providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, and big data and artificial intelligence platforms. Alternatively, the server can be an independent physical server, a server cluster composed of multiple physical servers, or a distributed system. For example, the terminal can be a vehicle-mounted terminal, an aircraft, a wearable smart device, a computer, a smartphone, a tablet, a smart voice interaction device, a smart home appliance, a medical device, etc. The device is often equipped with a display device, which can be a monitor, display screen, touch screen, etc., and the touch screen can be a touchscreen, touch panel, etc., but is not limited to these.
[0079] refer to Figure 1 Method P100 includes steps S110-S150.
[0080] In step S110, a resource object corresponding to the resource loading request is generated, wherein the attributes of the resource object include priority.
[0081] In an exemplary embodiment, taking a high-precision map editor as an example, the resources requested in the resource loading request can be abstractly understood as any data and information that can be loaded, processed, and used. For example, the resources to be loaded can be of various types and formats, including point clouds, trajectories, operational data, photographs, difference results, etc. The operational data includes vector data from various high-precision map operations, such as traffic signs, ground arrows, roads, road boundaries, ground surface facilities, ground line facilities, etc. A point cloud is a data structure representing an object or scene in three-dimensional space, composed of a series of points, each with its own coordinates in space. Specifically, point cloud data is usually generated by field data collection. The trajectory can be the path taken by a data collection vehicle on a road over a period of time, and this path consists of a series of points. For example, the resources to be loaded can come from various sources, including local files, Cloud Object Storage (COS) cloud storage, Hypertext Transfer Protocol (HTTP) resource servers, etc.
[0082] Unlike related technologies that add resource loading requests to a queue, this embodiment generates a resource object (such as a ResourceHolder) for each resource loading request. For example, the ResourceHolder class can be a proxy class representing the holder of the resource. Specifically, it can contain multiple members, such as priority. Thus, after determining the priority information of the resource to be loaded based on actual needs, the object of the ResourceHolder class can be determined. Table 1 shows the resource object (ResourceHolder A) for resource A to be loaded, specifically, its priority attribute value is "level 0".
[0083] Table 1
[0084] resource objects ResourceHolder A property Priority level 0
[0085] As can be seen, in this embodiment of the application, after determining the resource loading request, the resource loading request is not directly added to a queue. Instead, a resource object corresponding to the resource loading request is generated. Thus, the priority of each resource to be loaded can be set through the attributes of the resource object, thereby enabling the resource loading order to be adjusted according to the priority, ensuring that high-priority resource objects will be loaded first.
[0086] In the exemplary embodiment, the aforementioned priority refers to the priority of the loading order, with higher-priority resources being loaded first. Specifically, it can be described as the priority of the resource to be loaded or the priority of the resource loading request; this embodiment does not limit this. The specific value of the aforementioned priority can be set according to actual conditions. For example, the number of priorities can be set to 8, specifically represented by levels 0 to 7, with the priority decreasing sequentially. Specifically, "level 0" has the highest priority and can represent synchronous loading; levels 1 to 7 can represent asynchronous loading, and the larger the value, the lower the loading priority.
[0087] In an exemplary embodiment, the ResourceHolder class described above includes multiple members, including a Uniform Resource Locator (URL). The URL is used to uniquely represent and locate a resource.
[0088] For example, resource information can be described and managed using the ResourceKey class, similar to the Uniform Resource Locator (URL) in the HTTP protocol. The ResourceKey's property values also include information such as the resource's data source, location, type, and parameters, used to represent and locate the resource.
[0089] For example, in the ResourceKey class, the "data_source_" member variable is similar to the path in a URL, the "provider_" member variable is similar to the protocol and domain name in a URL, the "resource_type_" member variable is similar to the resource category, and the "params_" member variable is similar to the query parameters in a URL. With this information, a resource can be uniquely identified and located.
[0090] Taking a trajectory resource of file type as an example, assuming its path is "D: / 123.trk", it can be represented by ResourceKey:
[0091] provider:file: / /
[0092] data_source: D: / 123.trk
[0093] resource_type: trk
[0094] For a track resource of an HTTP service type, "http: / / example.com / api / v1 / track?coord=84", it can be represented by a ResourceKey:
[0095] provider: http: / /
[0096] data_source: example.com / api / v1 / track
[0097] resource_type: trk
[0098] Query parameter: coord=84
[0099] Taking the application of a resource loading scheme in a high-definition map editor as an example, a task in the editor contains a set of operational data, trajectories, point clouds, and photos within the same area. When a task is triggered in the editor, a series of resource acquisition requests related to that task are generated. These requests are used to load resources of various types (operational data, trajectories, point clouds, photos, etc.) within the same area. As mentioned earlier, data sources can also include local file storage (COS cloud storage), HTTP resource servers, etc.
[0100] Therefore, a resource object can be generated based on the ResourceKey of the resource to be loaded. Specifically, the ResourceKey of the resource to be loaded is used as the attribute value of the resource object. Table 2 shows the resource object (ResourceHolder A) of the resource to be loaded, specifically, its priority attribute value is "level 0"; it also includes the ResourceKey of the resource to be loaded, specifically: taking a file-type trajectory resource as an example, assuming its path is "D: / 123.trk".
[0101] Table 2
[0102]
[0103] As can be seen, the solution provided in this embodiment generates resource objects corresponding to resource loading requests, which can realize unified processing of resources of different types and sources, such as disk file resources and network resources, so that users can request various resources in the same way, which is conducive to improving the scope of application and practicality.
[0104] Next, if the generated resource objects are directly added to the queue for direct resource loading (the second queue below), the following problems may occur. On the one hand, directly adding resources to the second queue may make it difficult to control the loading order of resource objects. For example, when resource objects from multiple tasks are continuously added to the second queue, it is difficult to guarantee that resources are loaded according to priority. On the other hand, the main thread may continue to add new resources to the second queue while the loading thread is processing the second queue. In this way, the loading thread may be processing old resources, while the main thread may have already added new resources, resulting in a chaotic resource loading state. To address the above problems, this embodiment of the application executes steps S120 after executing step S110.
[0105] In step S120, the resource object is added to a first queue, wherein the resource objects in the first queue are stored according to the priority.
[0106] In this embodiment, the first queue (also known as the preloading queue) is set up for two reasons: First, it is used for temporary storage of resource objects. As temporary storage, the first queue prevents the main thread from adding more resource objects while the loading thread is processing the second queue (also known as the loading queue), thus maintaining the consistency of the resource object state. Second, it is also used to sort resource objects. Resources in the first queue can be stored according to priority, ensuring that resources are loaded according to priority.
[0107] In an exemplary embodiment, the ResourcePrepareDispatcher class can be used to manage resource preloading tasks, and can be viewed as a scheduler for resources to be loaded. Specifically, the ResourcePrepareDispatcher class is a separate thread (which can be called the resource preloading thread).
[0108] For example, the ResourcePrepareDispatcher class is used to maintain a set of queues for preloading resources (the first queue mentioned above) (std::vector< ...<ResourceHolder*> resources_prepare_load_[kPriorityCount]).
[0109] Here, "resources_prepare_load_" is a member variable, which is an array of size kPriorityCount (e.g., a priority count of 8), where each element of the array is a std::vector.<ResourceHolder*> A container of type [type]. This array is used to store resources that are in the pre-loading phase, categorized according to different priorities.
[0110] Here, "kPriorityCount" is a constant representing the number of resource loading priorities. This allows "resources_prepare_load_" to group and store resources according to priority. For example, see [reference] Figure 2 The first queue 20 shown in the figure stores resource objects with priority "0" (such as resource object 00, resource object 01, and resource object 02) in the container "resources_prepare_load_[0]"; resource objects with priority "1" (such as resource object 10 and resource object 11) are stored in the container "resources_prepare_load_[1]"; and so on, with resource objects with priority "7" (such as resource object 70-resource object 73) stored in the container "resources_prepare_load_[7]". This ensures that the resource objects in the first queue 20 are stored according to priority.
[0111] For example, when you need to add a new resource to the prepareLoadQueue, you can use the `AddToPrepareLoadQueue(ResourceHolder*holder, uint8_t priority)` method. This method adds the given resource object to the container corresponding to the priority. For example, when you need to remove a resource from the prepareLoadQueue, you can use the `RemoveFromPrepareLoadQueue(ResourceHolder*holder)` method.
[0112] For example, the ResourcePrepareDispatcher class mentioned above can process resource loading tasks according to the resource priority in "resources_prepare_load_" and move them to the second queue (loading queue) mentioned above, which can be loaded by the ResourceLoadDispatcher class. In this way, it can be ensured that high-priority resources are loaded and processed first.
[0113] In step S130, the resource objects in the first queue are swapped out.
[0114] In an exemplary embodiment, resource objects stored in the first queue (preload queue) are swapped out. In one exemplary embodiment, after all resource objects are swapped out, these objects can be temporarily stored in a temporary storage area specifically designed for this operation; for example, this could be a data structure such as an array, list, or another queue, or it could be a region in memory. In another exemplary embodiment, after all resource objects are swapped out, these objects can also be temporarily stored in a memory buffer, awaiting addition to the aforementioned second queue.
[0115] Furthermore, the swapped resource objects can be added to the second queue all at once. This swap operation ensures that the resource state does not change unexpectedly during resource loading. During resource loading, the main thread may continue creating new resource objects and adding them to the preload queue (first queue), while the loading thread is loading resources from the loading queue (second queue). Without the swap operation, the loading thread might load a portion of resources from the loading queue, and then the main thread might continue adding new resources to the preload queue. In this case, the resource state in the loading queue could become chaotic, as it contains both loaded and unloaded resources. By performing the swap operation, the main thread moves all resource objects from the preload queue to the loading queue at once, meaning that all resource objects in the loading queue are updated simultaneously. This allows the loading thread to start loading resources from a completely new and complete loading queue, ensuring the consistency of the resource object state.
[0116] In related technologies, if the application's needs change before all requests in the resource loading request queue have been processed—for example, 10 resources that were originally required are no longer needed, and 20 new resources need to be loaded—then, if the queue system cannot cancel or reorder these requests in a timely manner, the loading of new resources must wait for all requests in the original queue to be processed, leading to unnecessary delays. These delays can negatively impact user experience, as users may have to wait longer to access new resources. However, this application's embodiment avoids the aforementioned problems caused by canceling resource loading. Specifically, through the aforementioned exchange operation, this application's embodiment ensures that the resource objects in the first queue (preloading queue) are updated every frame, and the resource objects in the second queue (loading queue) are obtained from the preloading queue. Therefore, this application's embodiment avoids the aforementioned problems caused by canceling resource loading in related technologies.
[0117] Continue to refer to Figure 1In step S140, the exchanged resource objects are added to a second queue, wherein the resource objects in the second queue are arranged according to the priority.
[0118] In an exemplary embodiment, the resource objects in the second queue are arranged according to their respective priorities, thereby ensuring the orderly loading of resources through the second queue. (See reference...) Figure 3 In the second queue 30 shown, resource objects 00-02 belong to priority level "0", resource objects 10-11 belong to priority level "1", ..., resource objects 70-73 belong to priority level "7". Specifically, the resource loading order is determined based on priority, so high-priority resource objects will be loaded first. For example, synchronous loading can be selected to ensure timely availability of critical resources, while low-priority resource objects can be loaded asynchronously to improve application response speed and user experience. The solution provided in this application embodiment allows users to conveniently control the resource loading order, which is beneficial for improving the flexibility of resource loading.
[0119] In step S150, the resource objects are loaded according to their arrangement order in the second queue.
[0120] In an exemplary embodiment, the ResourceLoadDispatcher class can be used to manage resource loading tasks. The ResourceLoadDispatcher class contains a set of threads, the number of which can be configured by the user, such as 12 threads by default. In this embodiment, multiple threads can handle different resource loading tasks simultaneously, improving resource loading efficiency. Furthermore, a thread pool can help manage the number of threads, avoiding system resource strain caused by creating too many threads.
[0121] Furthermore, the ResourceLoadDispatcher class can be viewed as a scheduler responsible for scheduling resource objects in the second queue to different threads so that these threads can be used to perform the actual resource loading work.
[0122] For example, a resource loader can be represented by the ResourceLoader class. The ResourceLoader class is an abstract class that specifically defines an interface for loading resources, thereby implementing the resource loading process in the aforementioned threads.
[0123] In the solution provided by method P100, a resource object corresponding to the resource loading request is generated. The priority of each resource to be loaded can be set through the attributes of the resource object. Furthermore, the resource objects in the second queue are arranged according to priority. Therefore, high-priority resource objects will be loaded first; for example, synchronous loading can be selected to ensure timely availability of critical resources. Low-priority resource objects can be loaded asynchronously to improve application response speed and user experience. The solution provided in this application embodiment allows users to conveniently control the order of resource loading, which is beneficial for improving the flexibility of resource loading.
[0124] Specifically, method P100 further includes: adding the resource object to the first queue before adding it to the second queue, wherein the resource objects in the first queue are stored according to the priority; and swapping out the resource objects stored in the first queue to add them all at once to the second queue. On one hand, resources in the first queue can be stored according to priority, ensuring that resources are loaded according to priority. On the other hand, the first queue serves as temporary storage for resource objects, and by moving all resource objects from the first queue to the second queue at once through a swap operation, it avoids adding resources to the second queue while the loading thread is processing it, thus maintaining the consistency of the resource object state and preventing the resource objects in the second queue from increasing indefinitely. Furthermore, this embodiment uses a multi-level feedback queue (second queue and first queue) to manage resource objects. Each loading operation retrieves resource objects from the first queue at once, and the first queue is updated every frame, thus avoiding problems caused by canceling resource loading.
[0125] Figure 4 This is a flowchart illustrating the resource loading method P400 provided in an embodiment of this application. Specifically, method P400 shows an embodiment of dynamically adjusting the priority of resource objects during multi-threaded resource loading.
[0126] refer to Figure 4 In step S41, the main thread creates a resource object (ResourceHolder).
[0127] For the specific implementation of step S41, please refer to the specific implementation of step S110, which will not be repeated here.
[0128] In step S42, the main thread determines whether the resource object has been loaded.
[0129] Suppose the main thread creates a series of resource objects in step S41, and each resource object contains an attribute for loading status. Exemplary loading statuses could be: not loaded (first state), loading (second state), loading successful (third state), or loading failed (fourth state). Therefore, the main thread can determine whether a resource object has been fully loaded based on its loading status attribute. For example, if a resource object's loading status is successfully loaded (third state) or failed (fourth state), then the resource object is considered fully loaded. The solution provided in this application continuously updates the loading status of resource objects during the resource loading process, making it easier to obtain the current resource loading status and ensuring that the same resource is loaded only once, avoiding duplicate loading. For example, if resource object 1 for resource a is created in loading task A, and resource object 1 is in the third state, it can be determined that resource a has been loaded. If loading task B also needs to load resource a, it can determine from the status information of resource object 1 that resource a does not need to be loaded again, thus avoiding duplicate loading and improving resource loading efficiency.
[0130] In step S43, the main thread adds the resource objects to the first queue. And in step S44, the preloading thread swaps out the resource objects from the first queue and adds them all at once to the second queue.
[0131] For specific implementation methods of steps S43 and S44, please refer to the specific implementation methods of steps S120 and S130, which will not be repeated here.
[0132] refer to Figure 4 In step S45, the preloading thread attempts to add resource objects from the second queue to the loading thread.
[0133] As mentioned earlier, the ResourceLoadDispatcher class is responsible for managing resource loading tasks. The ResourceLoadDispatcher class contains a thread pool, which can have up to 12 threads. In this embodiment, multiple threads can handle different resource loading tasks simultaneously, improving resource loading efficiency. For example, when there are idle threads in the thread pool, the scheduler (ResourceLoadDispatcher class) retrieves a task from the second queue and assigns it to a thread for processing, i.e., the resource object is successfully added to the loading thread; the exemplary execution step S47: Start loading resources.
[0134] For example, if there are no idle threads in the thread pool, adding a resource object to the loading thread will fail. In the event that adding a resource object to the loading thread fails (the attempt to load fails), the priority of the resource object needs to be adjusted to quickly obtain another opportunity to add it to the loading thread. This allows execution of step S46: adjusting the priority of the resource object. Exemplary adjustment methods include at least one of the following:
[0135] (1) While maintaining the current priority, increase the sub-priority.
[0136] To expedite the re-attempt to add a failed resource object to the loading thread, its sub-priority can be increased. For example, each original priority can have M sub-priority levels, decreasing sequentially from level 1 to M (an integer greater than 2). If, without priority adjustment, resource object A is at original priority (level 1) and sub-priority level M, and adding resource object A to the loading thread fails (the loading attempt fails), then after the first priority adjustment, resource object A can have an original priority of "level 1" and a sub-priority of (M-1).
[0137] In this embodiment, setting sub-priorities can enhance the richness of priority information, which is beneficial for realizing multi-level control over the loading degree of attempts and improving flexibility.
[0138] (2) Increase the priority based on the current priority.
[0139] To expedite the process of adding a failed resource object to the loading thread again, its priority can be increased. For example, if resource object A's original priority is "level 1", and it fails to load, its priority can be increased, for instance, to "level 0".
[0140] In this embodiment, priority adjustment is performed based on the current priority. This achieves the goal of quickly giving resource objects that fail to load another attempt a chance to be added to the loading thread, without increasing the complexity of control, which is beneficial to resource loading efficiency.
[0141] It should be noted that when using method (1) to increase priority, if the priority reaches the highest sub-priority under the original priority after a certain adjustment (i.e., the sub-priority is level 1), and the resource object has not yet been successfully added to the loading thread, the priority is increased on the basis of the original priority "level 1", for example, the priority is adjusted to "level 0", and the sub-priority is "level M", so as to ensure the rationality of the priority adjustment.
[0142] In an exemplary embodiment, the resource object's attribute also includes a first-load count (try_load_count). The first-load count represents the number of times the resource object failed to be added to the loading thread; if the resource object fails to be added to the loading thread, the first-load count is increased. Since the first-load count reflects the number of failed loading attempts, and a larger first-load count indicates a more urgent need to quickly obtain the next opportunity to add it to the loading thread, the adjustment range of the resource object's priority can be determined based on the first-load count. For example, the first-load count is directly proportional to the increase in priority / sub-priority. For instance, when the first-load count of resource object A's attribute is 1, while maintaining the original priority "level 1", the sub-priority is increased from level M to level (M-1); when the first-load count of resource object A's attribute is 2, while maintaining the original priority "level 1", the sub-priority is increased from level (M-1) to level (M-3).
[0143] In the solution provided in this embodiment, the priority adjustment range of the resource object is determined based on the number of times the resource object fails to be added to the loading thread, thereby allowing for reasonable priority adjustment.
[0144] Continue to refer to Figure 4 If loading fails in step S47, for example due to network failure or large data volume, the priority of the resource object needs to be adjusted to maximize the opportunity to load resources that have not yet been loaded. Step S48 is then executed: Adjust the priority of the resource object. Exemplary adjustment methods include at least one of the following:
[0145] (3) Reduce sub-priorities while maintaining the current priority.
[0146] To maximize the chance of loading resources that haven't yet been loaded, their sub-priorities can be lowered. For example, each original priority can have M sub-priority levels, decreasing sequentially from level 1 to M (an integer greater than 2). If, without priority adjustment, resource object A is at its original priority (level 1) and its sub-priority is level 1, and if resource object A fails to load, after the first priority adjustment, its original priority might be "level 1," and its sub-priority level might be "level 2," meaning the current priority remains unchanged while the sub-priority is reduced.
[0147] In this embodiment, setting sub-priorities can enhance the richness of priority information, which is beneficial for realizing multi-level control over the loading degree of attempts and improving flexibility.
[0148] (4) Reduce the priority based on the current priority.
[0149] To maximize the chance of reloading resources that haven't yet been loaded, their priority can be reduced from the current priority. For example, if resource object A's original priority is "Level 1", and it fails to load, its priority can be reduced to "Level 2".
[0150] In this embodiment, priority is adjusted based on the current priority. This approach aims to maximize the opportunity to load resources in the next round without increasing the complexity of the control process, thus improving resource loading efficiency.
[0151] It should be noted that when the priority is reduced by method (3), if the priority reaches the lowest sub-priority under the original priority after a certain adjustment (i.e., the sub-priority is level M), and the resource object has not been successfully loaded next, the priority is reduced based on the original priority "level 1", for example, the priority is adjusted to "level 2" and the sub-priority is "level M", so as to ensure the rationality of the priority adjustment.
[0152] In an exemplary embodiment, the resource object's attribute also includes a second count (load_count). This second count represents the number of times the resource object failed to load. If the resource object successfully joins the loading thread but fails to load, the second count is increased. Since the second count reflects the number of loading failures, and a larger second count indicates that the next loading opportunity should be given to resource objects that have not yet undergone loading processing, the adjustment range for the resource object's priority can be determined based on the second count. For example, the second count is directly proportional to the reduction in priority / sub-priority. For instance, if the second count of resource object A is 1, the sub-priority is increased from level 1 to level 2 while maintaining the original priority "level 1"; if the second count of resource object A is 2, the sub-priority is increased from level 2 to level 4 while maintaining the original priority "level 1". In the solution provided in this embodiment, the adjustment range for the priority of the resource object is determined based on the number of resource loading failures after the resource object joins the loading thread, thereby allowing for reasonable priority adjustment.
[0153] Continue to refer to Figure 4 If loading is successful in step S47, then step S49 is executed: add it to the loading completion queue for use. For example, the resource object's properties also include a pointer to the loaded resource; thus, in response to successful loading of the second resource object, the pointer of the second resource object is controlled to point to the loaded resource. For example, ResourceHolder A and its various properties are represented as shown in Table 3.
[0154] Table 3
[0155]
[0156] The approach provided in method P400 dynamically adjusts the priority of resource objects based on their state during the resource loading process. Specifically, if a resource object fails to be added to the loading thread, its priority is increased to quickly obtain another opportunity to be added to the loading thread; if a resource object fails to load within the loading thread, its priority is decreased to prioritize loading opportunities for other resource objects. This ensures that even resource objects with lower priorities have a chance to be loaded instead of remaining in a waiting state. This strategy guarantees that all resources can be loaded correctly, thereby improving system efficiency and stability.
[0157] Figure 5 This is a flowchart illustrating the resource unloading method P500 provided in an embodiment of this application. Specifically, method P500 shows an embodiment of unloading loaded resources through an unloading thread.
[0158] refer to Figure 5 In step S51, the unloaded thread tracks memory usage.
[0159] As mentioned earlier, successfully loaded resources are stored in memory. However, since memory space is limited, resources need to be unloaded when memory usage reaches a preset threshold to ensure efficient memory utilization.
[0160] In step S52, the unloading thread determines whether the memory usage exceeds the threshold.
[0161] In an exemplary embodiment, in response to successful loading of a resource object, the loaded resource is stored in a binary memory block (Blob).
[0162] For example, the size of a binary memory block can be obtained using the Blob and Resource classes. Specifically:
[0163] The Blob class represents a block of binary data and has the following methods:
[0164] AddRef: Increases the reference count.
[0165] Release: Decrease the reference count.
[0166] GetBlob: Returns a Blob instance.
[0167] GetSize: Returns the size of the Blob.
[0168] The Resource class represents a resource and has the following methods:
[0169] GetBlob: Returns the associated Blob instance.
[0170] GetMemorySize: Returns the memory size of the resource.
[0171] In the solution provided in this embodiment, a binary memory block (Blob) is used to store loaded resources. The GetSize function can be used to accurately calculate the size of the memory occupied by the binary memory block. Therefore, when the occupancy information of the binary memory block exceeds a preset threshold, the resources are unloaded, thereby achieving precise control over memory usage.
[0172] On the other hand, using binary memory blocks (Blobs) to store loaded resources separates resource loading from resource usage, allowing resources to be loaded on demand—only when actually needed—significantly reducing memory usage during startup or initialization, thus improving application startup speed and user experience. Furthermore, using binary memory blocks (Blobs) to store various resource types (such as point clouds, images, audio, or other data formats) allows them to be represented in a unified data format. This unified representation enables resource loaders to handle different resource types in the same way, treating them all as binary data. Therefore, for new resource types, only a new derived class of ResourceLoader needs to be added, without modifying the internal logic of the resource loading process, greatly reducing the chance of introducing bugs. Additionally, version information can be written to the header of the Blob during writing, allowing the reading side to parse the resource based on the version information, thus achieving version control for the same data type.
[0173] In step S53, the resource objects are sorted according to their last usage time. In step S54, the first resource object with the shorter last usage time is determined. In step S55, the resource corresponding to the first resource object is unloaded so that the occupancy information of the binary memory block is less than the first threshold.
[0174] In an exemplary embodiment, referring to Table 3, the resource object's attribute also includes a usage time (last_used_time), i.e., the time since the last use. The usage time indicates the time when the resource object was most recently used. For example, the timing of updating this attribute of the resource object includes:
[0175] 1) In response to the successful loading of the resource object, update the usage time of the resource object.
[0176] 2) When a resource object that has been successfully loaded is used, update the usage time of the resource object.
[0177] In this embodiment, the resources to be unloaded are determined based on the last usage time of the resource object. For example, the longer the last usage time is from the current time, the longer the resource has not been used. Therefore, resources that have not been used for a longer period of time are unloaded first to ensure efficient use of memory.
[0178] For example, the resource unloading thread monitors the memory usage of resources in the current system. If it exceeds a specified threshold, it begins unloading the resources. Resources are first sorted by their last usage time, and then the resources with the longest usage time are unloaded one by one until the memory usage of the resources reaches 60% of the threshold.
[0179] In the embodiment provided by method P500, the resource object's attributes include the last used time, thereby determining the resources to be unloaded based on the last used time to ensure efficient memory utilization. For example, loaded resources are also stored in binary blocks, which on the one hand facilitates precise control over memory usage; on the other hand, using binary memory blocks (Blobs) to store loaded resources helps decouple resource loading and resource usage.
[0180] Figure 6 This is a flowchart illustrating the resource loading method P600 provided in this application embodiment. Method P600 is executed based on method P400. Specifically, method P600 illustrates an embodiment of managing resource objects through reference counting during resource loading. Each resource object is managed using reference counting; when the reference count of a resource object is zero, it means that no other object references it, and the resource object can be safely released. Therefore, when the unloading thread unloads resources, there is no need to worry about the resource being used by the main thread.
[0181] refer to Figure 6 In step S61, the main thread creates the resource object. At this time, the reference count is initially set to 1.
[0182] In this embodiment, in response to the triggering of a target task, at least one resource loading request corresponding to the target task is generated in the main thread. Further, resource objects corresponding to each of the at least one resource loading request are generated in the main thread, resulting in at least one resource object corresponding to the target task. Each resource object is managed using a reference count. For example, the initial value of the reference count for each created resource object is 1.
[0183] For example, the Reference class is a reference counting class that provides basic reference counting functionality. Reference counting is a memory management technique used to track how many other objects reference an object.
[0184] In step S62, it is determined whether the resource object has been fully loaded. The reference count of the resource object remains unchanged from its initial value in this step. Furthermore, the specific implementation of this step can be found in the specific implementation of step S42, and will not be repeated here.
[0185] In step S63, the main thread adds the resource object to the first queue. At this time, the reference count of the resource object is incremented by 1. When the main thread adds the ResourceHolder to the first queue (preloading queue), the reference count of the resource object is incremented by 1 because the preloading queue also holds a reference to the ResourceHolder at this time.
[0186] In step S64, resource objects swapped out of the first queue are added to the second queue all at once. Specifically, when a resource is swapped out of the first queue and onto the loading queue, the resource object reference count is incremented by 1 because the second queue (loading queue) also holds a reference to the ResourceHolder. When a resource is removed from the preloading queue, the resource object reference count is decremented by 1 because the preloading queue no longer holds a reference.
[0187] refer to Figure 6 For the specific implementation of steps S65 to S68 in method P600, please refer to the specific implementation of steps S45 to S48, which will not be repeated here.
[0188] Continue to refer to Figure 6 In step S69, when a resource is successfully loaded, the resource object reference count is incremented by 1 because the loading completion queue holds a reference to the ResourceHolder. When a resource is removed from the second queue, the resource object reference count is decremented by 1 because the second queue no longer holds a reference. When the unloading thread determines that a resource can be unloaded, the reference count of the corresponding resource object is decremented by 1 because the loading completion queue no longer holds a reference to that resource object.
[0189] In an exemplary embodiment, if the reference count of a resource object drops to 0, it indicates that the resource will be destroyed.
[0190] It should be noted that the main thread can reduce its own reference count to ResourceHolder at any time. This means that when a task closes, the main thread doesn't need to wait for the resources to completely unload. The main thread can control the reference count of the resource object corresponding to the target task to be zero, thus significantly reducing task shutdown time, for example, from two or three minutes to less than 30 seconds.
[0191] Understandably, the main thread can reduce its own reference count, which means the main thread can release the reference to the resource. However, this does not necessarily lead to the resource being destroyed immediately, because the preload queue still holds references to it.
[0192] The solution provided in method P600 uses reference counting to track the usage of each resource. When a resource is used, its reference count increases; when a resource is no longer used, its reference count decreases. When a resource's reference count reaches zero, the system unloads the resource. This way, when the main thread cancels a resource loading, it doesn't need to wait for the resource loading thread to finish loading; and when the unloading thread unloads a resource, it doesn't need to worry about the resource being used by the main thread. In contrast, related technologies typically generate resource loading requests in the main thread and process them in a background thread, which forces the main thread to wait for the resource to finish loading, severely impacting program performance.
[0193] Figure 7 A flowchart of the method P700 for loading resources in a high-precision map editor provided in this application embodiment.
[0194] refer to Figure 7 In step S71, the response task is opened, and the high-precision map editor determines the resources to be loaded.
[0195] For example, the types of resources to be loaded can include various types (such as point clouds, trajectories, images, and job data), and the resources to be loaded can also come from various sources, including local files, COS cloud storage, HTTP resource servers, etc.
[0196] In step S72, it is determined whether the resource to be loaded is cached.
[0197] For example, since the Uniform Resource Locator (ResourceKey) is used to uniquely describe and locate resources, the existence of the resource to be loaded in the loaded queue can be determined based on the ResourceKey of the resource to be loaded. If it exists, the loaded resource is retrieved based on the Resource pointer of the corresponding resource object. If it does not exist, the resource loading process is executed according to method P100.
[0198] For example, loaded resources are stored in binary memory blocks. In step S73, memory usage is monitored.
[0199] In the solution provided in this embodiment, a binary memory block (Blob) is used to store loaded resources. The GetSize function can be used to accurately calculate the size of the memory occupied by the binary memory block. Therefore, when the occupancy information of the binary memory block exceeds a preset threshold, the resources are unloaded, thereby achieving precise control over memory usage.
[0200] If it is determined that memory usage exceeds the threshold, step S74 can be executed: perform the resource unloading process. The resource unloading implementation example can be found in the example provided in method P500, and will not be repeated here.
[0201] refer to Figure 7 After acquiring the resources required for the task, the layer module receives a notification and parses the resources into corresponding layer objects. In high-precision map editors, layers are an important data organization method. Each layer contains a set of features of the same type, and each feature has its own location and attribute information. For example, a set of trajectory features forms a trajectory layer, and a set of traffic sign features forms a traffic sign layer. Furthermore, these layers are drawn onto the screen using a rendering engine, and these elements together constitute a visual environment.
[0202] In the resource loading scheme provided in this application embodiment, a resource object corresponding to a resource loading request is generated. The priority of each resource to be loaded can be set through the attributes of the resource object. Further, the resource object is added to a second queue, and multiple resource objects in this second queue are arranged according to priority. It can be seen that the scheme provided in this application embodiment can adjust the resource loading order according to the priority of the resource loading request, so that high-priority resource objects will be loaded first. For example, synchronous loading can be selected to ensure that critical resources are available in a timely manner, while low-priority resource objects can be loaded asynchronously to improve application response speed and user experience. In the scheme provided in this application embodiment, users can conveniently control the resource loading order, which is beneficial to improving the flexibility of resource loading.
[0203] In some embodiments, to ensure the consistency of resource object states, a first queue (preloading queue) and a swap operation are set up. On the one hand, resources in the first queue can be stored according to priority, ensuring that resources are loaded according to priority. On the other hand, the first queue serves as temporary storage for resource objects, and by using a swap operation to move all resource objects in the first queue to the second queue at once, it avoids adding resources to the second queue while the loading thread is processing the second queue, thereby maintaining the consistency of resource object states.
[0204] In some embodiments, the priority of a resource object is dynamically adjusted based on its state during the resource loading process. This strategy ensures that all resources are loaded correctly, thereby improving system efficiency and stability.
[0205] In some embodiments, using binary memory blocks (Blobs) to store loaded resources allows for precise control over memory usage. Furthermore, separating resource loading from resource usage enables on-demand resource loading—meaning resources are only loaded into memory when truly needed. This significantly reduces memory usage during startup or initialization, improving application startup speed and user experience.
[0206] In some embodiments, each resource object is managed using reference counting. When a resource object's reference count is zero, it means that no other object is referencing it, and the resource object can be safely released. Therefore, when the unloading thread unloads a resource, it doesn't need to worry about the resource being used by the main thread, significantly reducing task shutdown time, for example, from two or three minutes to less than 30 seconds.
[0207] The above text combined Figures 1 to 7 The present application describes an embodiment of the resource loading method, which is further illustrated below. Figure 8 The resource loading device embodiments of this application are described in detail below.
[0208] Figure 8 This is a schematic block diagram of a resource loading device 800 provided in an embodiment of this application. The resource loading device 800 is configured in an electronic device, such as... Figure 9 Electronic devices such as the 900 series, and high-precision map editors, etc. (See reference) Figure 8 The resource loading device 800 includes: an object generation module 810, a first queue module 820, an exchange operation module 830, a second queue module 840, and a resource loading module 850.
[0209] The object generation module 810 is used to generate a resource object corresponding to a resource loading request, wherein the attribute of the resource object includes priority; the first queue module 820 is used to add the resource object to a first queue, wherein the resource objects in the first queue are stored according to the priority; the exchange operation module 830 is used to exchange the resource object from the first queue; the second queue module 840 is used to add the exchanged resource object to a second queue, wherein the resource objects in the second queue are arranged according to the priority; and the resource loading module 850 is used to load the resource object according to the arrangement order of the resource objects in the second queue.
[0210] In an exemplary embodiment, based on the above scheme, the first queue includes N containers corresponding to N priorities, where N is a positive integer and not less than the total number of priorities of the resource objects.
[0211] The first queue module mentioned above is specifically used to add resource objects with the attribute of priority i to the i-th container in the first queue, where i is a positive integer not greater than N.
[0212] In an exemplary embodiment, based on the above scheme, the resource loading module 850 is specifically used to: load the resource objects into the loading thread according to the arrangement order of the resource objects in the second queue, so that the loading thread can load the resource objects based on the priority.
[0213] The resource loading device 800 further includes a priority adjustment module; wherein the priority adjustment module is used to: if the resource object fails to be added to the loading thread, adjust the priority of the resource object; wherein the adjustment method includes any one of the following: increasing the sub-priority while maintaining the current priority; increasing the priority based on the current priority.
[0214] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a first count, which represents the number of times the resource object failed to be added to the loading thread; the priority adjustment module is specifically used to: increase the first count of the resource object, wherein the first count is used to determine the adjustment range of the priority of the resource object.
[0215] In an exemplary embodiment, based on the above scheme, the priority adjustment module is further configured to: after loading the resource object into the loading thread, if the loading of the resource object fails, adjust the priority of the resource object; wherein the adjustment method includes any one of the following: reducing the sub-priority while maintaining the current priority; or reducing the priority based on the current priority.
[0216] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a second number, which represents the number of times the resource object failed to load resources; the priority adjustment module is further used to: if the resource object fails to load resources, increase the second number of the resource object, wherein the second number is used to determine the adjustment range of the priority of the resource object.
[0217] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes usage time, wherein the usage time represents the time when the resource object was last used; the resource loading device 800 further includes a usage time update module; wherein the usage time update module is used to update the usage time of the resource object in response to successful loading of the resource object, or in response to the successfully loaded resource object being used; wherein the usage time is used to determine the resource object corresponding to the resource to be uninstalled.
[0218] In an exemplary embodiment, based on the above scheme, the resource loading device 800 further includes a resource unloading module; wherein the resource unloading module is configured to: in response to successful loading of the resource object, store the loaded resource in a binary memory block; obtain the occupancy information of the binary memory block; if the occupancy information of the binary memory block exceeds a first threshold, determine a first resource object corresponding to the resource to be unloaded based on the usage time; and unload the resource corresponding to the first resource object so that the occupancy information of the binary memory block is less than the first threshold.
[0219] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a pointer to the loaded resource; the resource loading device 800 further includes a pointer control module; wherein the pointer control module is used to: in response to the successful loading of the second resource object, control the pointer of the second resource object to point to the loaded resource.
[0220] In an exemplary embodiment, based on the above scheme, the object generation module 810 is specifically used to: in response to the triggering of a target task, generate at least one resource loading request corresponding to the target task in the main thread; and generate resource objects corresponding to the at least one resource loading request in the main thread to obtain at least one resource object corresponding to the target task, wherein each resource object is managed by reference counting.
[0221] In an exemplary embodiment, based on the above scheme, the resource loading device 800 further includes an object management module; wherein the object management module is used to: in response to the target task being closed, control the reference count of the resource object corresponding to the target task to be zero in the main thread.
[0222] In an exemplary embodiment, based on the above scheme, the attributes of the target resource object further include unified resource location information; the object generation module 810 is specifically used to: generate the resource object corresponding to the source loading request according to the unified resource location information carried in the resource loading request and the priority of the resource to be loaded.
[0223] In an exemplary embodiment, based on the above scheme, the unified resource location information includes resource type and source location of the resource; the resource type includes any one of the following: point cloud, trajectory, image, and operation data.
[0224] In an exemplary embodiment, based on the above scheme, the attribute of the resource object further includes a loading status; the resource loading device 800 further includes a status update module; wherein the status update module is used for at least one of the following:
[0225] After the resource object is added to the second queue, its loading status is updated to the first state, indicating that it is pending loading. After the resource object is successfully added to the loading thread, its loading status is updated to the second state, indicating that it is loading. After the resource loading process is successful, its loading status is updated to the third state, indicating that the loading is successful. After the resource loading process fails and the number of consecutive failures reaches a second threshold, its loading status is updated to the fourth state, indicating that the loading has failed.
[0226] In an exemplary embodiment, based on the above scheme, the resource loading device 800 further includes a state determination module; wherein the state determination module is used to: obtain the resource status of all resource objects corresponding to the target task in the main thread; if the resource status of all resource objects corresponding to the target task is a third state or a fourth state, then determine that the resource loading of the target task is completed.
[0227] In an exemplary embodiment, based on the above scheme, the first queue module 720 is specifically used to: add the resource object to the first queue in the main thread; the exchange operation module 730 is specifically used to: exchange the resource object in the first queue in the preloading thread; the second queue module 740 is specifically used to: add the resource object to the second queue in the preloading thread; and the resource loading module 750 is specifically used to: load the resource object according to the arrangement order of the resource objects in the second queue in the loading thread.
[0228] In the resource loading apparatus provided in this application embodiment, the resource generation module generates resource objects corresponding to resource loading requests. Priority can be set for each resource to be loaded through the attributes of the resource objects. Further, the resource objects are added to a second queue, and multiple resource objects in this second queue are arranged according to priority. It is evident that the solution provided in this application embodiment can adjust the resource loading order according to the priority of the resource loading requests, so that high-priority resource objects will be loaded first. For example, synchronous loading can be selected to ensure timely availability of critical resources, while low-priority resource objects can be loaded asynchronously to improve application response speed and user experience. In the solution provided in this application embodiment, users can conveniently control the resource loading order, which is beneficial to improving the flexibility of resource loading.
[0229] The resource loading apparatus of this application embodiment has been described above from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that this functional module can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this application can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the method disclosed in this application embodiment can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. Optionally, the software module can be located in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above method embodiments.
[0230] It should be understood that the resource loading device embodiment and the resource loading method embodiment can correspond to each other, and similar descriptions can be found in the method embodiment. To avoid repetition, further details are omitted here. Specifically, Figure 7 The resource loading device shown can execute the above-described resource loading method embodiments, and the method embodiments corresponding to the foregoing and other operations and / or functions of each module in the resource loading device will not be described again here for the sake of brevity.
[0231] Figure 9 This is a schematic block diagram of an electronic device 900 provided in an embodiment of this application. As described above, the resource loading device can be deployed in, for example, Figure 9 The electronic device shown can therefore be used to execute the resource loading method described above.
[0232] like Figure 9 As shown, the electronic device 900 may include:
[0233] The system includes a memory 910 and a processor 920. The memory 910 stores a computer program 930 and transfers the program code 930 to the processor 920. In other words, the processor 920 can retrieve and run the computer program 930 from the memory 910 to implement the methods described in the embodiments of this application.
[0234] For example, the processor 920 can be used to execute the steps in the above method according to the instructions in the computer program 930.
[0235] In some embodiments of this application, the processor 920 may include, but is not limited to:
[0236] General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0237] In some embodiments of this application, the memory 910 includes, but is not limited to:
[0238] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
[0239] In some embodiments of this application, the computer program 930 may be divided into one or more modules, which are stored in the memory 910 and executed by the processor 920 to complete the resource loading method provided in this application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 930 in the electronic device.
[0240] like Figure 9 As shown, the electronic device 900 may further include:
[0241] Transceiver 940, which can be connected to processor 920 or memory 910.
[0242] The processor 920 can control the transceiver 940 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 940 may include a transmitter and a receiver. The transceiver 940 may further include antennas, and the number of antennas may be one or more.
[0243] It should be understood that the various components in the electronic device 900 are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.
[0244] According to one aspect of this application, a computer storage medium is provided that stores a computer program thereon, which, when executed by a computer, enables the computer to perform the methods of the above-described method embodiments. Alternatively, embodiments of this application also provide a computer program product containing instructions that, when executed by a computer, cause the computer to perform the methods of the above-described method embodiments.
[0245] According to another aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method described in the above-described method embodiments.
[0246] In other words, when implemented using software, it can be implemented wholly or partially in the form of a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0247] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0248] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or modules may be electrical, mechanical, or other forms.
[0249] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. For example, the functional modules in the various embodiments of this application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0250] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A resource loading method, characterized in that, The method includes: Generate a resource object corresponding to the resource loading request, wherein the attributes of the resource object include priority; The resource object is added to the first queue, wherein the resource objects in the first queue are stored according to the priority. Exchange the resource objects in the first queue; The exchanged resource objects are added to a second queue, wherein the resource objects in the second queue are arranged according to the priority. The resource objects are loaded according to their arrangement order in the second queue.
2. The method of claim 1, wherein, The first queue includes N containers corresponding to N priorities, where N is a positive integer and not less than the total number of priorities of the resource objects; Adding the resource object to the first queue includes: Add the resource object with the attribute of priority i to the i-th container in the first queue, where i is a positive integer not greater than N.
3. The method of claim 1, wherein, The step of loading resources onto the resource objects according to their order in the second queue includes: According to the order of the resource objects in the second queue, the resource objects are loaded into the loading thread so that the loading thread can load the resource objects based on the priority. The method further includes: If the resource object fails to be added to the loading thread, the priority of the resource object is adjusted; wherein the adjustment method includes any of the following: increasing the sub-priority while maintaining the current priority; or increasing the priority based on the current priority.
4. The method of claim 3, wherein, The resource object's attributes also include a first count, where the first count represents the number of times the resource object failed to be added to the loading thread; If adding the resource object to the loading thread fails, the method further includes: Increase the first count of the resource object, wherein the first count is used to determine the adjustment range of the priority of the resource object.
5. The method of claim 3, wherein, After loading the resource object into the loading thread, the method further includes: If loading the resource object fails, the priority of the resource object is adjusted; wherein the adjustment method includes any of the following: reducing the sub-priority while maintaining the current priority; or reducing the priority based on the current priority.
6. The method according to claim 5, characterized in that, The resource object's attributes also include a second number, which represents the number of times the resource loading failed. If loading the resources of the resource object fails, the method further includes: Increase the number of the resource object a second time, wherein the second number is used to determine the adjustment range of the priority of the resource object.
7. The method according to any one of claims 3 to 6, characterized in that, The resource object's attributes also include usage time, whereby the usage time represents the time when the resource object was last used; the method further includes: In response to successful resource loading of the resource object, or in response to the successful loading of the resource object being used, update the usage time of the resource object; The usage time is used to determine the resource object corresponding to the resource to be uninstalled.
8. The method according to claim 7, characterized in that, The method further includes: In response to the successful loading of the resource object, the loaded resource is stored in a binary memory block; Obtain the occupancy information of the binary memory block; If the occupancy information of the binary memory block exceeds the first threshold, the first resource object corresponding to the resource to be unloaded is determined based on the usage time. Unload the resources corresponding to the first resource object so that the occupancy information of the binary memory block is less than the first threshold.
9. The method according to claim 8, characterized in that, The resource object's attributes also include pointers to loaded resources; the method further includes: The response indicates that the second resource object has been successfully loaded, and the pointer of the second resource object is set to point to the loaded resource.
10. The method according to any one of claims 1 to 6, characterized in that, The resource object corresponding to the generated resource loading request includes: When a target task is triggered, at least one resource loading request corresponding to the target task is generated in the main thread; In the main thread, resource objects corresponding to the at least one resource loading request are generated respectively, and at least one resource object corresponding to the target task is obtained, wherein each resource object is managed by reference counting.
11. The method according to claim 10, characterized in that, The method further includes: In response to the target task being closed, the reference count of the resource object corresponding to the target task is set to zero in the main thread.
12. The method according to claim 10, characterized in that, The attributes of the target resource object also include unified resource location information; Generating the resource objects corresponding to the at least one resource loading request includes: Based on the unified resource location information carried in the resource loading request and the priority of the resource to be loaded, a resource object corresponding to the source loading request is generated.
13. The method according to claim 12, characterized in that, The unified resource location information includes the resource type and the source location of the resource; the resource type includes any one of the following: point cloud, trajectory, image, and operation data.
14. The method according to any one of claims 3 to 6, characterized in that, The resource object's attributes also include loading status; the method further includes at least one of the following: After the resource object is added to the second queue, the loading status of the resource object is updated to the first status, which indicates that it is waiting to be loaded. After the resource object is successfully added to the loading thread, the loading status of the resource object is updated to the second status, which indicates that it is being loaded. After the resource loading process of the resource object is successfully completed, the loading status of the resource object is updated to the third status, which indicates that the loading was successful. If the resource loading process of the resource object fails and the number of consecutive failures reaches a second threshold, the loading status of the resource object is updated to a fourth status, which indicates that the loading has failed.
15. The method according to claim 14, characterized in that, The method further includes: In the main thread, obtain the resource status of all resource objects corresponding to the target task; If the resource status of all resource objects corresponding to the target task is in the third or fourth state, then the resource loading of the target task is determined to be complete.
16. The method according to claim 1, characterized in that, Adding the resource object to the first queue includes: adding the resource object to the first queue in the main thread; The step of swapping out the resource objects in the first queue includes: swapping out the resource objects in the first queue in the preloading thread; Adding the resource object to the second queue includes: adding the resource object to the second queue in the preloading thread; The step of loading resources onto the resource objects according to their order in the second queue includes: In the loading thread, the resource objects are loaded according to their order of arrangement in the second queue.
17. A resource loading device, characterized in that, The device includes: An object generation module is used to generate a resource object corresponding to a resource loading request, wherein the attributes of the resource object include priority; The first queue module is used to add the resource object to the first queue, wherein the resource object in the first queue is stored according to the priority; The exchange operation module is used to exchange the resource objects in the first queue. The second queue module is used to add the exchanged resource objects to the second queue, wherein the resource objects in the second queue are arranged according to the priority. The resource loading module is used to load resources onto the resource objects according to the order in which the resource objects are arranged in the second queue.
18. An electronic device, characterized in that, Including processor and memory; The memory is used to store computer programs; The processor is configured to execute the computer program to implement the resource loading method as described in any one of claims 1 to 16.
19. A computer-readable storage medium, characterized in that, Used to store computer programs; said computer programs cause a computer to perform the resource loading method as described in any one of claims 1 to 16.