Storage space allocation method and device, vehicle and computer readable storage medium
By designing large and small memory allocation areas in the vehicle-side memory pool and selecting an appropriate allocation strategy based on the memory request size, the problems of high latency, severe fragmentation, and high risk of leakage in the traditional memory allocation mechanism under vehicle-side HTTP service scenarios are solved, achieving efficient memory management and system stability.
Patent Information
- Application Number
- CN202511957049.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-23
- Publication Date
- 2026-03-20
AI Technical Summary
Traditional memory allocation mechanisms suffer from high latency in HTTP request response, severe memory fragmentation, low utilization, and high risk of memory leaks under high concurrency in automotive HTTP service scenarios, making it difficult to meet the requirements of automotive-grade high reliability, high concurrency, and long-term operation.
The vehicle-side memory pool is designed, including a large memory allocation area and a small memory allocation area. By comparing the memory request size with a preset threshold, an appropriate allocation strategy is selected to allocate storage space. The small memory allocation area selects from pre-allocated memory blocks using pointer offset, while the large memory allocation area allocates memory blocks dynamically. This achieves separate management of small and large memory, reducing the risk of system calls and memory leaks.
It reduces HTTP request response latency in high-concurrency scenarios, improves memory utilization and system stability, and ensures the real-time performance and long-term stable operation of the vehicle-side system.
Smart Images

Figure CN121704785A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data storage, and more particularly, to a storage space allocation method and device, a vehicle and a computer readable storage medium in the technical field of data storage. BACKGROUND
[0002] In a vehicle-side system, HTTP services are often used to implement key functions such as remote control, state reporting, and OTA (Over-The-Air) upgrade. Such services need to dynamically allocate temporary memory for each HTTP request to store data such as request headers, request bodies, and response buffers. Currently, the malloc and free functions provided by the C language standard library are commonly used for memory management. However, in the context of vehicle-grade high reliability, high concurrency, and long-period operation, the traditional memory allocation mechanism requires a system call to enter the kernel state every time malloc is called, and the operating system traverses the free memory linked list to find an appropriate memory block. This process involves lock contention and memory search, which has a large overhead. In a high-concurrency HTTP service, each request needs to allocate small blocks of memory multiple times (such as a few hundred bytes to a few KB), resulting in a sharp increase in system call frequency and significantly increasing request processing delay, making it difficult to meet the real-time requirements of vehicle-side systems. SUMMARY
[0003] Embodiments of the present application provide a storage space allocation method, device, vehicle and computer readable storage medium, which can solve the problem of high HTTP request response delay in high concurrency in the vehicle-side HTTP service scenario using the traditional memory allocation mechanism.
[0004] In a first aspect, a storage space allocation method is provided, which includes: in response to a memory application request initiated by a target service thread to a vehicle-side memory pool, obtaining an application memory size corresponding to the memory application request; comparing the application memory size with a preset memory threshold to obtain a comparison result; determining a target allocation strategy from a first space allocation strategy and a second space allocation strategy according to the comparison result, the vehicle-side memory pool including a first memory allocation area and a second memory allocation area, the first space allocation strategy referring to selecting a to-be-allocated memory block from a plurality of pre-allocated memory blocks in the first memory allocation area using a pointer offset method, and allocating corresponding storage space for the service thread based on the to-be-allocated memory block, and the second space allocation strategy referring to creating a memory block in the second memory allocation area, and allocating corresponding storage space for the service thread based on the created memory block; and allocating corresponding target storage space for the target service thread based on the target allocation strategy.
[0005] The application obtains an application memory size corresponding to a memory application request, compares the application memory size with a preset memory threshold, obtains a comparison result, determines a target allocation strategy from a first space allocation strategy and a second space allocation strategy according to the comparison result, the vehicle end memory pool includes a first memory allocation area and a second memory allocation area, the first space allocation strategy refers to selecting a to-be-allocated memory block from a plurality of pre-allocated memory blocks of the first memory allocation area in a pointer offset manner, and allocating corresponding storage space for a service thread based on the to-be-allocated memory block, the second space allocation strategy refers to creating a memory block in the second memory allocation area, and allocating corresponding storage space for a service thread based on the created memory block, and the technical scheme of allocating corresponding target storage space for the target service thread based on the target allocation strategy. Through the comparison result of the application memory size and the preset memory threshold, it can be determined whether the application memory is large memory or small memory, and then the storage space for the current service thread is allocated based on the large memory allocation area or the small memory allocation area according to the comparison result, so as to realize the separate management of small memory and large memory application. On the one hand, in a high-concurrency scenario, it is not necessary to initiate a system call to the system for each HTTP request to apply for allocating storage space, thereby reducing the number of system calls and being conducive to reducing the response delay of HTTP requests under high concurrency. On the other hand, since the small memory allocation area includes a plurality of pre-allocated memory blocks and the storage space is allocated through a pointer offset manner, and the large memory allocation area allocates storage space through a dynamically created memory block, the small memory allocation area can maintain a regular memory block layout, and the large memory allocation area can independently apply for a complete memory block, thereby avoiding external fragmentation caused by the interleaved release of memory blocks of different sizes, and being conducive to improving the memory utilization rate of the vehicle end system in long-term operation. On the other hand, the vehicle end memory pool serves as a unified memory entrance, facilitating centralized tracking and batch recycling of the memory associated with the service thread. Even if the business logic is interrupted abnormally, the pool-level cleaning mechanism can also ensure resource release, fundamentally reduce the risk of memory leakage, and ensure long-term stable operation of the vehicle end system.
[0006] In a possible implementation, determining the target allocation strategy from the first space allocation strategy and the second space allocation strategy according to the comparison result comprises: determining the first space allocation strategy as the target allocation strategy in a case where the application memory size is less than or equal to the preset memory threshold; and determining the second space allocation strategy as the target allocation strategy in a case where the application memory size is greater than the preset memory threshold, so as to accurately select a suitable storage space allocation strategy for the target service thread according to the application memory size, improve the memory management efficiency and reliability of the vehicle-side system, and effectively solve the problems of increased system overhead and rising service response delay caused by frequent and indiscriminate triggering of system calls in the traditional memory allocation mechanism, thereby guaranteeing the real-time performance and stability of the vehicle-side service, especially in a high-concurrency HTTP request scenario.
[0007] In a possible implementation, allocating the corresponding target storage space for the target service thread based on the target allocation strategy comprises: in a case where the target allocation strategy is the first space allocation strategy, determining a pre-allocated memory block pointed to by a memory management pointer in a plurality of pre-allocated memory blocks of the first memory allocation area to obtain a to-be-allocated memory block, the pre-allocated memory block pointed to by the memory management pointer being a pre-allocated memory block with remaining storage space; determining whether the memory size of the remaining storage space in the to-be-allocated memory block is greater than or equal to the application memory size; and in a case where the memory size of the remaining storage space is greater than or equal to the application memory size, determining the remaining storage space in the to-be-allocated memory block as the target storage space allocated for the target service thread. By using the first space allocation strategy to allocate the target storage space for the target service thread, unnecessary system calls and global heap management overhead are avoided, and the response speed and memory usage stability of the vehicle-side system in a high-concurrency HTTP service scenario are significantly improved.
[0008] In a possible implementation, after determining whether the memory size of the remaining storage space in the to-be-allocated memory block is greater than or equal to the application memory size, the storage space allocation method further comprises: in a case where the memory size of the remaining storage space is less than the application memory size and the allocation number corresponding to the to-be-allocated memory block is greater than a number threshold, adding an expansion memory block to the first memory allocation area, wherein the allocation number is a cumulative number of failures of allocating storage space for the service thread from the to-be-allocated memory block, and the memory size of the remaining storage space of the expansion memory block is greater than the memory size of the to-be-allocated memory block; selecting storage space with a memory size greater than or equal to the application memory size from the expansion memory block to obtain a candidate storage space; and determining the candidate storage space as the target storage space allocated for the target service thread. By executing the memory expansion strategy, the success rate of allocating the target storage space for the target service thread in the first memory allocation area is improved.
[0009] In a possible implementation manner, after the expansion memory block is added in the first memory allocation area, the storage space allocation method further includes: pointing the memory management pointer to the expansion memory block; and after the memory management pointer is pointed to the expansion memory block, the target storage space can be directly allocated to the target service thread through the expansion memory block, and subsequent storage space allocation tasks can be ensured to be preferentially performed on the new expansion memory block, which is beneficial to improve the success rate of storage space allocation and further improve the response efficiency of the HTTP request.
[0010] In a possible implementation manner, based on the target allocation strategy, the corresponding target storage space is allocated for the target service thread, including: in a case where the target allocation strategy is a second space allocation strategy, creating a storage space matching the application memory size in the second memory allocation area to obtain a to-be-allocated storage space; adding the memory address of the to-be-allocated storage space and the memory size of the to-be-allocated storage space to a management linked list of the second memory allocation area; and determining the storage space pointed to by a target memory address in the management linked list as the target storage space allocated for the target service thread, the target memory address being a starting address of the to-be-allocated storage space. The entire allocation process not only realizes on-demand, accurate, and traceable large memory allocation, but also isolates the interference of large memory on small memory allocation performance. In addition, since the memory allocation based on the second space allocation strategy is recorded in the management linked list of the second memory allocation area, when the service thread ends, the vehicle-side memory pool can traverse the management linked list to release all the memory blocks at one time, without relying on the manual call of free, thereby fundamentally eliminating the risk of memory leakage caused by omission of release.
[0011] In a possible implementation manner, after the corresponding target storage space is allocated for the target service thread based on the target allocation strategy, the storage space allocation method further includes: in response to the end of the target service thread, resetting the pointer offset of the memory block in the first memory allocation area to 0; emptying the management linked list of the second memory allocation area and releasing the storage space in the second memory allocation area; and adding the vehicle-side memory pool to the reusable memory pool queue, so that a new service thread reuses the vehicle-side memory pool in the reusable memory pool queue, which not only realizes automatic, batch, and non-omission recovery of memory resources, but also improves the response speed and resource utilization efficiency of the system through memory pool reuse.
[0012] In a second aspect, a storage space allocation apparatus is provided, and the storage space allocation apparatus includes: The acquisition module is configured to acquire an application memory size corresponding to a memory application request initiated by a target service thread to a vehicle-side memory pool. The comparison module is configured to compare the application memory size with a preset memory threshold to obtain a comparison result. The selection module is used to determine the target allocation strategy from the first space allocation strategy and the second space allocation strategy based on the comparison results. The vehicle-side memory pool includes a first memory allocation area and a second memory allocation area. The first space allocation strategy refers to selecting a memory block to be allocated from multiple pre-allocated memory blocks in the first memory allocation area using a pointer offset method, and allocating corresponding storage space for the service thread based on the memory block to be allocated. The second space allocation strategy refers to creating a memory block in the second memory allocation area, and allocating corresponding storage space for the service thread based on the created memory block. The allocation module is used to allocate corresponding target storage space to the target service thread based on the target allocation strategy.
[0013] In one possible implementation, the selection module is specifically used to determine the first space allocation strategy as the target allocation strategy when the requested memory size is less than or equal to a preset memory threshold; and to determine the second space allocation strategy as the target allocation strategy when the requested memory size is greater than the preset memory threshold.
[0014] In one possible implementation, the allocation module is specifically used to determine, when the target allocation strategy is the first space allocation strategy, the pre-allocated memory block pointed to by the memory management pointer among multiple pre-allocated memory blocks in the first memory allocation area, to obtain the memory block to be allocated, wherein the pre-allocated memory block pointed to by the memory management pointer is a pre-allocated memory block with remaining storage space; determine whether the memory size of the remaining storage space in the memory block to be allocated is greater than or equal to the requested memory size; if the memory size of the remaining storage space is greater than or equal to the requested memory size, determine the remaining storage space in the memory block to be allocated as the target storage space allocated for the target service thread.
[0015] In one possible implementation, the allocation module is specifically used to add an expanded memory block in the first memory allocation area if the remaining memory size is less than the requested memory size and the allocation count corresponding to the memory block to be allocated is greater than the count threshold. Here, the allocation count is the cumulative number of times the storage space for the service thread fails to be allocated from the memory block to be allocated, and the remaining memory size of the expanded memory block is greater than the memory size of the memory block to be allocated. The module then selects a storage space from the expanded memory block whose memory size is greater than or equal to the requested memory size to obtain a candidate storage space. Finally, the candidate storage space is determined as the target storage space to be allocated to the target service thread.
[0016] In one possible implementation, an allocation module is specifically used to point the memory management pointer to the expanded memory block.
[0017] In one possible implementation, the allocation module is specifically used to create a storage space matching the requested memory size in the second memory allocation area when the target allocation strategy is the second space allocation strategy, thereby obtaining the storage space to be allocated; add the memory address and memory size of the storage space to be allocated to the management linked list of the second memory allocation area; and determine the storage space pointed to by the target memory address in the management linked list as the target storage space allocated for the target service thread, wherein the target memory address is the starting address of the storage space to be allocated.
[0018] In one possible implementation, the storage space allocation device further includes: The recycling unit is used to, after allocating the corresponding target storage space to the target service thread based on the target allocation strategy, and in response to the end of the target service thread, reset the pointer offset of the memory block in the first memory allocation area to 0; clear the management list of the second memory allocation area and release the storage space in the second memory allocation area; and add the vehicle-side memory pool to the reusable memory pool queue so that the new service thread can reuse the vehicle-side memory pool in the reusable memory pool queue.
[0019] Thirdly, a vehicle is provided, including a memory and a processor. The memory is used to store executable program code, and the processor is used to call and run the executable program code from the memory, causing the vehicle to perform the storage space allocation method in the first aspect or any possible implementation thereof.
[0020] Fourthly, a computer program product is provided, comprising: computer program code, which, when run on a computer, causes the computer to execute the storage space allocation method in the first aspect or any possible implementation thereof.
[0021] Fifthly, a computer-readable storage medium is provided that stores computer program code, which, when executed on a computer, causes the computer to perform the storage space allocation method described in the first aspect or any possible implementation thereof. Attached Figure Description
[0022] Figure 1 A schematic flowchart of a storage space allocation method provided in an embodiment of this application is shown; Figure 2 A flowchart illustrating the storage space allocation process provided in this application is shown; Figure 3 This paper shows a schematic diagram of the structure of a storage space allocation device provided in an embodiment of this application; Figure 4A schematic diagram of the structure of a vehicle provided in an embodiment of this application is shown. Detailed Implementation
[0023] The technical solutions in this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. "And / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0024] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0025] The following explains the relevant terms used in this application.
[0026] 1. Vehicle-side service module, developed using traditional C language, serves as the core functional component of the terminal, responsible for data interaction with external HTTP (Hypertext Transfer Protocol) services. Its main functions include: acquiring basic vehicle information (such as model, firmware version, etc.), real-time monitoring of vehicle operating status (such as vehicle speed, battery level, door lock status, etc.), and collecting and reporting vehicle logs and event data (such as fault codes, user operation records, remote control command execution results, etc.).
[0027] 2. HTTP server request refers to the data communication process initiated by the vehicle-side service module to a specified server based on an HTTP request. This process is used to actively obtain cloud configuration information, upload vehicle status data, or submit remote control command execution feedback, and is a key interaction mechanism for realizing vehicle-cloud collaboration.
[0028] 3. Traditional memory allocation (malloc / free): Traditional memory allocation refers to the dynamic memory management mechanism provided by the C language standard library. The malloc function is used to request a specified amount of storage space at runtime, and the ree function is used to release memory previously allocated by malloc. This mechanism relies on the operating system's heap manager, and is prone to memory leaks without explicit deallocation or in abnormal paths. Furthermore, it suffers from performance bottlenecks and fragmentation issues in high-concurrency scenarios.
[0029] The following explains the shortcomings of traditional memory allocation.
[0030] In vehicle-mounted systems, HTTP services are commonly used to implement critical functions such as remote control, status reporting, and OTA upgrades. These services require dynamically allocating temporary memory for each HTTP request to store data such as request headers, request bodies, and response buffers. Currently, memory management generally relies on the malloc and free functions provided by the C standard library. However, in automotive-grade scenarios requiring high reliability, high concurrency, and long-term operation, traditional memory allocation mechanisms have the following drawbacks: 1. High HTTP request response latency under high concurrency Traditional memory allocation mechanisms require a system call to enter kernel mode for each malloc call, during which the operating system traverses the free memory list to find a suitable memory block. This process involves lock contention and memory search, resulting in significant overhead. In high-concurrency HTTP services, each request requires multiple allocations of small memory blocks (e.g., hundreds of bytes to several KB), causing a sharp increase in the frequency of system calls and significantly increasing request processing latency, making it difficult to meet the real-time requirements of the vehicle.
[0031] 2. Severe memory fragmentation and low utilization. Because the size of HTTP request / response data is highly random (e.g., HTTP request headers are approximately several hundred bytes, while response data can reach several KB to tens of KB), the size of memory blocks allocated by malloc varies. Furthermore, if adjacent memory blocks are not released synchronously during free allocation, a large number of discontinuous small free blocks will form. As the system runs for a long time, fragmentation accumulates continuously. Even if the total free memory is sufficient, it may lack a sufficiently large contiguous space to meet the needs of subsequent large memory allocations, resulting in the anomaly of "sufficient memory but allocation failure."
[0032] 3. High risk of memory leaks, affecting the stability of the vehicle-side system. Traditional memory allocation mechanisms require developers to strictly ensure that "allocation-release" occurs in pairs. However, in complex business logic (such as HTTP request timeouts, abnormal redirects, and multi-threaded resource contention), it is easy to overlook the `free` call, resulting in allocated memory not being reclaimed. Vehicle-side systems typically need to run continuously 24 / 7, and memory leaks will continue to accumulate, eventually exhausting available memory, causing system lag, service crashes, or even malfunctions in the entire vehicle, seriously threatening functional safety.
[0033] This application provides a storage space allocation method, apparatus, vehicle, and computer-readable storage medium. This application independently designs a memory management mechanism for a vehicle-side system. By designing a vehicle-side memory pool including a large memory allocation area and a small memory allocation area, when a service thread corresponding to an HTTP request initiates a memory request to the vehicle-side memory pool, the system selects to allocate corresponding storage space for the service thread from the large memory allocation area or the small memory allocation area, based on the relationship between the requested memory size indicated by the memory request and a preset memory threshold. The small memory allocation area includes multiple pre-allocated memory blocks. The small memory allocation area selects a memory block to be allocated from the multiple pre-allocated memory blocks using a pointer offset method and allocates storage space based on the memory block to be allocated. The large memory allocation area dynamically creates memory blocks and allocates storage space based on the created memory blocks. By adopting this memory management mechanism, the problems of high HTTP request response latency, severe memory fragmentation, low utilization, and high risk of memory leaks under high concurrency in vehicle-side HTTP service scenarios, which affect the stability of the vehicle-side system, can be effectively solved by the relationship between the requested memory size and the preset memory threshold. This indicates whether the requested memory is large or small, and storage space is allocated to the current service thread based on this relationship, achieving separate management of small and large memory requests. On the one hand, in high-concurrency scenarios, it is unnecessary to initiate a system call to request storage space for each HTTP request, reducing the number of system calls and thus helping to reduce the response latency of HTTP requests under high concurrency. On the other hand, since the small memory allocation area includes multiple pre-allocated memory blocks and allocates storage space through pointer offset, while the large memory allocation area allocates storage space through dynamically created memory blocks, this allows the small memory allocation area to maintain a regular memory block layout, and the large memory allocation area to independently request complete memory blocks. This avoids external fragmentation caused by the interleaved release of memory blocks of different sizes later on, which is beneficial to improving the memory utilization of the vehicle-side system during long-term operation. Furthermore, the vehicle-side memory pool serves as a unified memory entry point, facilitating centralized tracking and batch reclamation of memory associated with service threads. Even if business logic is abnormally interrupted, the pool-level cleanup mechanism ensures resource release, fundamentally reducing the risk of memory leaks and ensuring the long-term stable operation of the vehicle-side system.
[0034] The following is an embodiment of a storage space allocation method provided in this application specification.
[0035] Figure 1 A schematic flowchart illustrating a storage space allocation method provided in an embodiment of this application is shown, such as... Figure 1As shown, the storage space allocation method provided in this application embodiment is applied to the vehicle-side system of a vehicle, and the storage space allocation method includes the following schemes: S110: In response to the memory request initiated by the target service thread to the vehicle-side memory pool, obtain the memory size corresponding to the memory request; S120: Compare the requested memory size with the preset memory threshold to obtain the comparison result; S130: Based on the comparison results, determine the target allocation strategy from the first space allocation strategy and the second space allocation strategy; S140: Based on the target allocation strategy, allocate the corresponding target storage space to the target service thread.
[0036] The target service thread can be understood as the vehicle-side service thread corresponding to the HTTP request. When the target service thread executes the corresponding target task, it initiates a memory request to the vehicle-side memory pool designed in this application. By parsing the memory request, it obtains the requested memory size indicated by the memory request and requests the corresponding target storage space for the service thread from the vehicle-side memory pool based on the requested memory size.
[0037] Specifically, the vehicle-side memory pool includes a first memory allocation area (also known as the small memory allocation area) and a second memory allocation area (the large memory allocation area). The first and second memory allocation areas employ different space allocation strategies for allocating storage space to service threads. The first memory allocation area comprises multiple pre-allocated memory blocks, which are pre-divided memory blocks with contiguous memory addresses. The first space allocation strategy uses pointer offsets to select a memory block to be allocated from the multiple pre-allocated memory blocks in the first memory allocation area and allocates corresponding storage space to the service thread based on this block. The memory block to be allocated is one of the multiple pre-allocated memory blocks. Since the first memory allocation area consists of multiple pre-allocated memory blocks with contiguous memory addresses (i.e., it is composed of a group of consecutively arranged pre-allocated memory blocks), the system maintains a memory management pointer, which initially points to the first pre-allocated memory block. When memory needs to be allocated, each pre-allocated memory block is checked sequentially to see if it has any remaining storage space. If the pre-allocated memory block currently pointed to by the memory management pointer is full, that is, there is no remaining storage space, the memory management pointer is incremented by a fixed offset so that it points to the next pre-allocated memory block with remaining storage space. This process continues until the pre-allocated memory block pointed to by the memory management pointer has no remaining storage space. In other words, the memory block to be allocated can be obtained by obtaining the pre-allocated memory block pointed to by the memory management pointer.
[0038] The second memory allocation region is a contiguous memory area that is not pre-divided. During system initialization, there are no pre-allocated memory blocks in the second memory allocation region. The second space allocation strategy refers to dynamically creating memory blocks in the second memory allocation region and allocating corresponding storage space to service threads based on these created memory blocks. The second space allocation strategy can be understood as follows: when memory allocation is needed, the system allocates a suitable-sized memory block from the second memory allocation region and then provides this block to the service threads, allocating corresponding storage space from within the allocated memory block. Compared to the first space allocation strategy, the second space allocation strategy is more flexible in its memory allocation method and is suitable for situations where memory requirements are uncertain or large.
[0039] After obtaining the requested memory size, it is compared with a preset memory threshold to obtain a comparison result, which refers to the relationship between the requested memory size and the preset memory threshold. Based on the comparison result, either the first space allocation strategy or the second space allocation strategy is determined as the target allocation strategy. Then, the corresponding target storage space is allocated to the target service thread according to the target allocation strategy. That is, if the target allocation strategy is the first space allocation strategy, the target storage space is allocated to the target service thread based on the first space allocation strategy; if the target allocation strategy is the second space allocation strategy, the target storage space is allocated to the target service thread based on the second space allocation strategy.
[0040] This application adopts a technical solution that responds to a memory request initiated by a target service thread to the vehicle-side memory pool, obtains the requested memory size, compares the requested memory size with a preset memory threshold, obtains a comparison result, and determines a target allocation strategy from a first space allocation strategy and a second space allocation strategy based on the comparison result. The vehicle-side memory pool includes a first memory allocation area and a second memory allocation area. The first space allocation strategy refers to selecting a memory block to be allocated from multiple pre-allocated memory blocks in the first memory allocation area using a pointer offset method, and allocating corresponding storage space for the service thread based on the memory block to be allocated. The second space allocation strategy refers to creating a memory block in the second memory allocation area, and allocating corresponding storage space for the service thread based on the created memory block. Based on the target allocation strategy, the target storage space is allocated to the target service thread. The comparison result between the requested memory size and the preset memory threshold indicates whether the requested memory is large or small. Then, based on the comparison result, storage space is allocated to the current service thread based on the large or small memory allocation area, realizing the separate management of small and large memory requests. On the one hand, in high-concurrency scenarios, there's no need to initiate a system call for each HTTP request to request storage space, reducing the number of system calls and thus lowering response latency for HTTP requests under high concurrency. On the other hand, since the small memory allocation area includes multiple pre-allocated memory blocks and allocates storage space using pointer offsets, while the large memory allocation area allocates storage space using dynamically created memory blocks, the small memory allocation area maintains a regular memory block layout, and the large memory allocation area can independently request complete memory blocks. This avoids external fragmentation caused by the interleaved release of memory blocks of different sizes later, which helps improve the memory utilization of the vehicle-side system during long-term operation. Furthermore, the vehicle-side memory pool serves as a unified memory entry point, facilitating centralized tracking and batch reclamation of memory associated with service threads. Even if business logic is abnormally interrupted, the pool-level cleanup mechanism ensures resource release, fundamentally reducing the risk of memory leaks and guaranteeing the long-term stable operation of the vehicle-side system.
[0041] The following are Figure 1 The specific implementation methods of each step in the illustrated embodiment will be explained below: In one possible implementation, determining the target allocation strategy from the first and second space allocation strategies based on the comparison results includes the following steps: If the requested memory size is less than or equal to the preset memory threshold, the first space allocation strategy will be determined as the target allocation strategy. If the requested memory size exceeds the preset memory threshold, the second space allocation strategy will be determined as the target allocation strategy.
[0042] If the comparison result shows that the requested memory size is less than or equal to the preset memory threshold, it indicates that the target storage space requested by the target service thread from the vehicle-side memory pool is a small storage space, and the small memory allocation path can be used for storage space allocation. In this case, the first space allocation strategy is determined as the target allocation strategy. If the comparison result shows that the requested memory size is greater than the preset memory threshold, it indicates that the target storage space requested by the target service thread from the vehicle-side memory pool is a large storage space, and the large memory allocation path can be used for storage space allocation. In this case, the second space allocation strategy is determined as the target allocation strategy. This achieves precise selection of the appropriate storage space allocation strategy for the target service thread according to the requested memory size, improving the memory management efficiency and reliability of the vehicle-side system. It effectively solves the problem of increased system overhead and service response latency caused by frequent and indiscriminate triggering of system calls in traditional memory allocation mechanisms. Especially in high-concurrency HTTP request scenarios, it ensures the real-time performance and stability of the vehicle-side service.
[0043] In one possible implementation, allocating the corresponding target storage space for the target service thread based on the target allocation strategy includes the following steps: When the target allocation strategy is the first space allocation strategy, the pre-allocated memory block pointed to by the memory management pointer among the multiple pre-allocated memory blocks in the first memory allocation area is determined to obtain the memory block to be allocated. The pre-allocated memory block pointed to by the memory management pointer is a pre-allocated memory block with remaining storage space. Determine whether the size of the remaining storage space in the memory block to be allocated is greater than or equal to the size of the requested memory; If the remaining memory size is greater than or equal to the requested memory size, the remaining memory size in the memory block to be allocated will be determined as the target memory size allocated to the target service thread.
[0044] When the target allocation strategy is the first space allocation strategy, the pre-allocated memory block pointed to by the memory management pointer is determined from multiple pre-allocated memory blocks in the first memory allocation area to obtain the memory block to be allocated. The memory block to be allocated is the pre-allocated memory block pointed to by the memory management pointer, and the pre-allocated memory block pointed to by the memory management pointer is a pre-allocated memory block with remaining storage space, that is, the size of the remaining storage space is not 0.
[0045] After identifying the memory block to be allocated, it is determined whether the size of the remaining storage space within that block is greater than or equal to the requested memory size. If the remaining storage space is greater than or equal to the requested memory size, it indicates that the memory block to be allocated can serve as the target storage space for the target service thread, and the remaining storage space within the block is thus designated as the target storage space for the target service thread. Alternatively, if the size of the remaining storage space is equal to the requested memory size, then the remaining storage space is the target storage space for the target service thread; if the size of the remaining storage space is greater than the requested memory size, a space with a size equal to the requested memory size is selected from the remaining storage space and used as the target storage space for the target service thread.
[0046] By adopting the first space allocation strategy to allocate target storage space for the target service thread, unnecessary system calls and global heap management overhead are avoided, significantly improving the response speed and memory usage stability of the vehicle system in high-concurrency HTTP service scenarios.
[0047] In one possible implementation, after determining whether the size of the remaining storage space in the memory block to be allocated is greater than or equal to the requested memory size, the storage space allocation method further includes the following steps: If the remaining storage space is smaller than the requested memory size, and the number of allocations corresponding to the memory block to be allocated is greater than the number of allocations threshold, an expansion memory block is added to the first memory allocation area; Select storage space with a size greater than or equal to the requested memory size from the expanded memory block to obtain alternative storage space; The alternative storage space is determined as the target storage space to be allocated for the target service thread.
[0048] The allocation count is the cumulative number of times that have failed to allocate storage space for the service thread from the unallocated memory block.
[0049] If the remaining storage space is smaller than the requested memory size, and the number of allocation attempts for the pending memory block exceeds a threshold (e.g., 5 attempts), it indicates that the target storage space cannot be allocated to the target service thread using the pending memory block; in other words, the storage space allocation fails. This triggers a memory expansion strategy, which adds a new memory block to the first memory allocation area—an expanded memory block. The expanded memory block is a completely free memory block, and its remaining storage space is larger than the size of the pending memory block. For example, if the pending memory block is 16KB, and the expanded memory block is 1.5 times larger (24KB), the allocated memory block will have an additional allocation attempt. Since the pending memory block cannot be allocated to the target service thread, the number of allocation attempts for that block is increased by one; for example, if it was originally 5 attempts, it becomes 6. The expanded memory block and the pending memory block in the first memory allocation area are considered small memory blocks.
[0050] After expanding the memory block, a storage space with a size greater than or equal to the requested memory size is selected from the expanded memory block. This storage space is called the candidate storage space, and then the candidate storage space is determined as the target storage space to be allocated to the target service thread. By implementing the memory expansion strategy, the success rate of allocating the target storage space for the target service thread in the first memory allocation area is improved.
[0051] In one possible implementation, after adding an expanded memory block to the first memory allocation area, the storage space allocation method further includes the following steps: Set the memory management pointer to the expanded memory block.
[0052] After adding an expanded memory block to the first memory allocation area, since the expanded memory block is completely free, the memory management pointer is set to point to the expanded memory block. Because the target storage space cannot be allocated to the target service thread through the memory block to be allocated, pointing the memory management pointer to the expanded memory block allows the target storage space to be allocated directly to the target service thread through the expanded memory block. This also ensures that subsequent storage space allocation tasks are preferentially performed on the new expanded memory block, which helps improve the success rate of storage space allocation and thus improves the response efficiency of HTTP requests.
[0053] In one possible implementation, allocating the corresponding target storage space to the target service thread based on the target allocation strategy includes the following steps: When the target allocation strategy is the second space allocation strategy, a storage space matching the requested memory size is created in the second memory allocation area to obtain the storage space to be allocated; Add the memory address and size of the storage space to be allocated to the management list of the second memory allocation area; The storage space pointed to by the target memory address in the management linked list is determined as the target storage space to be allocated for the target service thread. The target memory address is the starting address of the storage space to be allocated.
[0054] When the target allocation strategy is the second space allocation strategy, a contiguous storage space matching the requested memory size is dynamically created in the second memory allocation area by calling the underlying memory interface (e.g., mmap). This created contiguous storage space is then used as the storage space to be allocated. The storage space to be allocated created in the second memory allocation area is considered a large storage space.
[0055] After obtaining the storage space to be allocated, the starting address (i.e., memory address) and the memory size of the storage space to be allocated are encapsulated into a management node. This management node is then added to a dedicated management list in the second memory allocation area. This management list tracks all large memory allocation records throughout their lifecycle, providing a basis for subsequent unified memory release. The target memory address (i.e., the starting address of the storage space to be allocated) is then extracted from this management node, and the storage space pointed to by this target memory address is allocated as the target storage space for the target service thread. This entire allocation process not only achieves on-demand, precise, and traceable large memory allocation but also isolates the performance of large memory allocations from the interference of small memory allocations. Furthermore, since memory allocations based on the second space allocation strategy are all recorded in the management list of the second memory allocation area, when a service thread ends, the vehicle-side memory pool can traverse this management list and release all memory blocks at once, without requiring developers to manually call `free`, fundamentally eliminating the risk of memory leaks due to missed releases.
[0056] In one possible implementation, allocating the corresponding target storage space to the target service thread based on the target allocation strategy includes the following steps: In response to the termination of the target service thread, the pointer offset of the memory block in the first memory allocation area is reset to 0; Clear the management list of the second memory allocation area and release the storage space in the second memory allocation area; Additionally, the vehicle-side memory pool is added to the reusable memory pool queue so that new service threads can reuse the vehicle-side memory pool in the reusable memory pool queue.
[0057] To ensure safe resource reclamation and long-term system stability, this application implements a delayed resource reclamation strategy upon termination of the target service thread. Specifically: First, the pointer offsets of all memory blocks in the first memory allocation area are reset to 0, logically clearing the allocated memory blocks and restoring them to their initial free state, preparing for subsequent reuse. Second, the management list of the second memory allocation area is traversed, releasing each storage space recorded in the list sequentially and clearing the list to ensure no memory leaks, thus cleaning up the vehicle-side memory pool. Finally, the vehicle-side memory pool is marked as "reusable" and added to the reusable memory pool queue. Thus, when the next HTTP service thread (i.e., a new service thread) starts, it can directly obtain an initialized and clean memory pool from the reusable memory pool queue without needing to re-allocate underlying memory or rebuild the management structure, significantly reducing thread creation overhead. This not only achieves automatic, batch, and complete memory resource reclamation but also improves system response speed and resource utilization efficiency through memory pool reuse.
[0058] Figure 2 This application provides a flowchart of the storage space allocation process, as shown below. Figure 2 As shown, G_POOL_S represents the structure of the vehicle-side memory pool, d represents a small memory block in the small memory allocation area pointed to by the memory management pointer current, max_value(4K) represents the preset memory threshold, for example, 4K, large represents the entry point to the large memory allocation area, G_POOL_T represents the internal structure of the pre-allocated memory block, which includes last, end, next, and failed. Last and end are used to manage the pointer offset within the block, next points to the next small memory block, and failed represents the count of failed allocations. Large_pool_t represents the management node in the second memory allocation area. The management node contains next and next, next indicates the link to the next large storage space, and alloc represents the actual physical address of the large storage space (i.e., the address returned by mmap, which is the starting address). This application constructs a vehicle-side memory pool comprising a small memory allocation area and a large memory allocation area. The allocation path is determined by comparing the requested memory size with a preset memory threshold (4KB). The small memory block is described by GWM_POOL_T and adopts a sequential allocation mechanism. The remaining space is controlled by last and end, and failed records the number of allocation failures to trigger expansion in the small memory allocation area. The large storage space records the alloc address through a large linked list to achieve independent management and safe release. This structure effectively achieves the memory management goals of high performance, low fragmentation, and high reliability. It effectively solves the problems of high HTTP request response latency, severe memory fragmentation, low utilization, and high memory leak risk under high concurrency in vehicle-side HTTP service scenarios, which affect the stability of the vehicle-side system.
[0059] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0060] Figure 3 This application provides a schematic diagram of the structure of a storage space allocation device according to an embodiment of the present application. Figure 3 As shown, the storage space allocation device 300 includes: The acquisition module 310 is used to respond to the memory request initiated by the target service thread to the vehicle memory pool and obtain the memory size corresponding to the memory request; Comparison module 320 is used to compare the requested memory size with a preset memory threshold and obtain the comparison result; The selection module 330 is used to determine the target allocation strategy from the first space allocation strategy and the second space allocation strategy based on the comparison result. The vehicle-side memory pool includes a first memory allocation area and a second memory allocation area. The first space allocation strategy refers to selecting a memory block to be allocated from multiple pre-allocated memory blocks in the first memory allocation area using a pointer offset method, and allocating corresponding storage space for the service thread based on the memory block to be allocated. The second space allocation strategy refers to creating a memory block in the second memory allocation area, and allocating corresponding storage space for the service thread based on the created memory block. The allocation module 340 is used to allocate corresponding target storage space to the target service thread based on the target allocation strategy.
[0061] In one possible implementation, the selection module 330 is specifically used to determine the first space allocation strategy as the target allocation strategy when the requested memory size is less than or equal to a preset memory threshold; and to determine the second space allocation strategy as the target allocation strategy when the requested memory size is greater than the preset memory threshold.
[0062] In one possible implementation, the allocation module 340 is specifically used to determine, when the target allocation strategy is the first space allocation strategy, the pre-allocated memory block pointed to by the memory management pointer among the multiple pre-allocated memory blocks in the first memory allocation area, to obtain the memory block to be allocated, wherein the pre-allocated memory block pointed to by the memory management pointer is a pre-allocated memory block with remaining storage space; determine whether the memory size of the remaining storage space in the memory block to be allocated is greater than or equal to the requested memory size; if the memory size of the remaining storage space is greater than or equal to the requested memory size, determine the remaining storage space in the memory block to be allocated as the target storage space allocated for the target service thread.
[0063] In one possible implementation, the allocation module 340 is specifically used to add an expanded memory block in the first memory allocation area if the remaining memory size is less than the requested memory size and the allocation count corresponding to the memory block to be allocated is greater than the count threshold. Here, the allocation count is the cumulative number of times the storage space for the service thread fails to be allocated from the memory block to be allocated, and the remaining memory size of the expanded memory block is greater than the memory size of the memory block to be allocated. The module then selects a storage space from the expanded memory block whose memory size is greater than or equal to the requested memory size to obtain a candidate storage space. Finally, the module determines the candidate storage space as the target storage space to be allocated to the target service thread.
[0064] In one possible implementation, the allocation module 340 is specifically used to point the memory management pointer to the expanded memory block.
[0065] In one possible implementation, the allocation module 340 is specifically used to create a storage space matching the requested memory size in the second memory allocation area when the target allocation strategy is the second space allocation strategy, thereby obtaining the storage space to be allocated; add the memory address and memory size of the storage space to be allocated to the management linked list of the second memory allocation area; and determine the storage space pointed to by the target memory address in the management linked list as the target storage space allocated for the target service thread, wherein the target memory address is the starting address of the storage space to be allocated.
[0066] In one possible implementation, the storage space allocation device 300 further includes: The recycling unit is used to, after allocating the corresponding target storage space to the target service thread based on the target allocation strategy, and in response to the end of the target service thread, reset the pointer offset of the memory block in the first memory allocation area to 0; clear the management list of the second memory allocation area and release the storage space in the second memory allocation area; and add the vehicle-side memory pool to the reusable memory pool queue so that the new service thread can reuse the vehicle-side memory pool in the reusable memory pool queue.
[0067] It should be noted that the storage space allocation device provided in the above embodiments is only illustrated by the division of the above functional modules when executing the storage space allocation method. In practical applications, the above functional allocation can be completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the storage space allocation device and the storage space allocation method embodiments provided in the above embodiments belong to the same concept. Therefore, for details not disclosed in the device embodiments of this application, please refer to the above embodiments of the storage space allocation method of this application, which will not be repeated here.
[0068] This application designs a vehicle-side memory pool that includes a large memory allocation area and a small memory allocation area. When a service thread corresponding to an HTTP request initiates a memory request to the vehicle-side memory pool, it selects to allocate the corresponding storage space for the service thread from the large memory allocation area or the small memory allocation area based on the relationship between the requested memory size indicated by the memory request and the preset memory threshold. The small memory allocation area includes multiple pre-allocated memory blocks. The small memory allocation area selects the memory block to be allocated from the multiple pre-allocated memory blocks through pointer offset and allocates storage space based on the memory block to be allocated. The large memory allocation area dynamically creates memory blocks and allocates storage space based on the created memory blocks. By adopting this memory management mechanism, the problems of high HTTP request response latency, severe memory fragmentation, low utilization, and high risk of memory leaks under high concurrency in vehicle-side HTTP service scenarios, which affect the stability of the vehicle-side system, can be effectively solved by the relationship between the requested memory size and the preset memory threshold. This indicates whether the requested memory is large or small, and storage space is allocated to the current service thread based on this relationship, achieving separate management of small and large memory requests. On the one hand, in high-concurrency scenarios, it is unnecessary to initiate a system call to request storage space for each HTTP request, reducing the number of system calls and thus helping to reduce the response latency of HTTP requests under high concurrency. On the other hand, since the small memory allocation area includes multiple pre-allocated memory blocks and allocates storage space through pointer offset, while the large memory allocation area allocates storage space through dynamically created memory blocks, this allows the small memory allocation area to maintain a regular memory block layout, and the large memory allocation area to independently request complete memory blocks. This avoids external fragmentation caused by the interleaved release of memory blocks of different sizes later on, which is beneficial to improving the memory utilization of the vehicle-side system during long-term operation. Furthermore, the vehicle-side memory pool serves as a unified memory entry point, facilitating centralized tracking and batch reclamation of memory associated with service threads. Even if business logic is abnormally interrupted, the pool-level cleanup mechanism ensures resource release, fundamentally reducing the risk of memory leaks and ensuring the long-term stable operation of the vehicle-side system.
[0069] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0070] Figure 4 This application provides a schematic diagram of the structure of a vehicle according to an embodiment of the present application. Figure 4 As shown, the vehicle 400 includes a memory 401 and a processor 402. The memory 401 stores executable program code 4011, and the processor 402 is used to call and execute the executable program code 4011 to perform a storage space allocation method.
[0071] This embodiment can divide the vehicle into functional modules according to the above method example. For example, each function can be assigned to a separate module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0072] When each function is divided into modules corresponding to its specific function, the vehicle may include: an acquisition module, a comparison module, a selection module, and an allocation module. It should be noted that all relevant content regarding the steps involved in the above method embodiments can be referenced from the functional descriptions of the corresponding modules, and will not be repeated here.
[0073] The vehicle provided in this embodiment is used to execute the above-described storage space allocation method, and thus can achieve the same effect as the above implementation method.
[0074] When using integrated units, the vehicle may include a processing module and a storage module. The processing module is used to control and manage the vehicle's movements. The storage module is used to support the vehicle in executing relevant program code and data.
[0075] The processing module may be a processor or a controller, which can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor may also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc., and the storage module may be a memory.
[0076] This embodiment also provides a computer-readable storage medium storing computer program code. When the computer program code is run on a computer, the computer executes the aforementioned related method steps to implement a storage space allocation method in the above embodiment.
[0077] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement a storage space allocation method as described in the above embodiment.
[0078] In addition, the vehicle provided in the embodiments of this application may specifically be a chip, component or module. The vehicle may include a connected processor and a memory. The memory is used to store instructions. When the vehicle is running, the processor may call and execute the instructions to make the chip execute a storage space allocation method in the above embodiments.
[0079] In this embodiment, the vehicle, computer-readable storage medium, computer program product, or chip are all used to execute the corresponding storage space allocation method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding storage space allocation method provided above, and will not be repeated here.
[0080] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0081] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, 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 units may be electrical, mechanical, or other forms.
[0082] 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 storage space allocation method, characterized in that, The storage space allocation method includes: In response to a memory request initiated by the target service thread to the vehicle-side memory pool, the requested memory size corresponding to the memory request is obtained; The requested memory size is compared with a preset memory threshold to obtain a comparison result; Based on the comparison results, a target allocation strategy is determined from the first space allocation strategy and the second space allocation strategy. The vehicle-side memory pool includes a first memory allocation area and a second memory allocation area. The first space allocation strategy refers to selecting a memory block to be allocated from multiple pre-allocated memory blocks in the first memory allocation area using a pointer offset method, and allocating corresponding storage space for the service thread based on the memory block to be allocated. The second space allocation strategy refers to creating a memory block in the second memory allocation area, and allocating corresponding storage space for the service thread based on the created memory block. Based on the target allocation strategy, a corresponding target storage space is allocated to the target service thread.
2. The storage space allocation method according to claim 1, characterized in that, The step of determining the target allocation strategy from the first space allocation strategy and the second space allocation strategy based on the comparison result includes: If the requested memory size is less than or equal to the preset memory threshold, the first space allocation strategy is determined as the target allocation strategy; If the requested memory size is greater than the preset memory threshold, the second space allocation strategy will be determined as the target allocation strategy.
3. The storage space allocation method according to claim 1, characterized in that, The step of allocating corresponding target storage space to the target service thread based on the target allocation strategy includes: When the target allocation strategy is the first space allocation strategy, the pre-allocated memory block pointed to by the memory management pointer among the multiple pre-allocated memory blocks in the first memory allocation area is determined to obtain the memory block to be allocated. The pre-allocated memory block pointed to by the memory management pointer is a pre-allocated memory block with remaining storage space. Determine whether the size of the remaining storage space in the memory block to be allocated is greater than or equal to the requested memory size; If the size of the remaining storage space is greater than or equal to the size of the requested memory, the remaining storage space in the memory block to be allocated is determined as the target storage space to be allocated to the target service thread.
4. The storage space allocation method according to claim 3, characterized in that, After determining whether the size of the remaining storage space in the memory block to be allocated is greater than or equal to the requested memory size, the storage space allocation method further includes: If the size of the remaining storage space is smaller than the requested memory size, and the number of allocations corresponding to the memory block to be allocated is greater than the number of allocations threshold, an expansion memory block is added to the first memory allocation area. The number of allocations is the cumulative number of times that storage space allocation for the service thread fails to be allocated from the memory block to be allocated, and the size of the remaining storage space of the expansion memory block is greater than the size of the memory block to be allocated. From the expanded memory blocks, select storage spaces with a size greater than or equal to the requested memory size to obtain alternative storage spaces; The alternative storage space is determined as the target storage space allocated for the target service thread.
5. The storage space allocation method according to claim 4, characterized in that, After adding an expanded memory block to the first memory allocation area, the storage space allocation method further includes: The memory management pointer is set to point to the expanded memory block.
6. The storage space allocation method according to claim 1, characterized in that, The step of allocating corresponding target storage space to the target service thread based on the target allocation strategy includes: When the target allocation strategy is the second space allocation strategy, a storage space matching the requested memory size is created in the second memory allocation area to obtain the storage space to be allocated; Add the memory address and size of the storage space to be allocated to the management list of the second memory allocation area; The storage space pointed to by the target memory address in the management list is determined as the target storage space to be allocated to the target service thread, and the target memory address is the starting address of the storage space to be allocated.
7. The storage space allocation method according to claim 6, characterized in that, After allocating corresponding target storage space to the target service thread based on the target allocation strategy, the storage space allocation method further includes: In response to the termination of the target service thread, the pointer offset of the memory block in the first memory allocation area is reset to 0; Clear the management list of the second memory allocation area and release the storage space in the second memory allocation area; In addition, the vehicle-side memory pool is added to the reusable memory pool queue so that new service threads can reuse the vehicle-side memory pool in the reusable memory pool queue.
8. A storage space allocation device, characterized in that, The storage space allocation device includes: The acquisition module is used to respond to a memory request initiated by the target service thread to the vehicle-side memory pool and acquire the memory size corresponding to the memory request. The comparison module is used to compare the requested memory size with a preset memory threshold to obtain a comparison result; The selection module is used to determine the target allocation strategy from the first space allocation strategy and the second space allocation strategy according to the comparison result. The vehicle-side memory pool includes a first memory allocation area and a second memory allocation area. The first space allocation strategy refers to selecting a memory block to be allocated from multiple pre-allocated memory blocks in the first memory allocation area using a pointer offset method, and allocating corresponding storage space for the service thread based on the memory block to be allocated. The second space allocation strategy refers to creating a memory block in the second memory allocation area, and allocating corresponding storage space for the service thread based on the created memory block. The allocation module is used to allocate corresponding target storage space to the target service thread based on the target allocation strategy.
9. A vehicle, characterized in that, The vehicles include: Memory, used to store executable program code; A processor is configured to call and run the executable program code from the memory, causing the vehicle to perform the storage space allocation method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed, implements the storage space allocation method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Memory management method and device, electronic device and storage medium
CN116089321A
Memory optimization method and device for network application firewall
CN119668869A