Memory management method and electronic equipment

By allocating preset capacity memory areas for wearable device applications in advance, the performance reduction problem caused by frequent memory applications is solved, and more efficient memory management and application performance improvement is achieved.

CN119988006AActive Publication Date: 2025-05-13HONOR DEVICE CO LTD

Patent Information

Application Number
CN202510039227.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-09
Publication Date
2025-05-13
Estimated Expiration
2045-01-09

AI Technical Summary

Technical Problem

In wearable devices, when applications frequently apply for memory in a short period of time, the memory management process consumes a lot of time, resulting in reduced performance.

Method used

When the application is started, multiple preset capacity memory areas are allocated to the application in advance according to the configuration information, and each memory area contains multiple memory blocks of the same size. When the application requests memory, directly select the appropriate memory block from these memory areas to return the memory address.

Benefits of technology

It significantly shortens the time for memory application and improves the operational performance and performance of applications, especially when frequent memory applications are applied in a short period of time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119988006A_ABST
    Figure CN119988006A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a memory management method and electronic equipment, which are applied to wearable equipment. When a first application in the wearable device is started, a plurality of memory areas are allocated to the first application in advance according to the first configuration information. Each memory area corresponds to a preset capacity, a plurality of memory blocks are arranged in the memory area, and the memory capacity of the memory blocks is equal to the preset capacity. In the running process of the first application, when the memory is applied, appropriate memory blocks can be matched from a plurality of memory areas, and address information of the memory blocks is returned. The capacity of the memory block is greater than or equal to the capacity required for applying for the memory, and the memory block is in an idle state. Therefore, by planning and managing the memory in advance, the memory address information can be returned at an extremely high speed when the first application applies for the memory. Particularly, under the scenes that equipment hardware resources are limited and the first application frequently applies for the memory in a short time, the time consumed by memory application can be remarkably shortened, and the application running efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of wearable devices, and in particular to a memory management method and an electronic device. Background Art

[0002] With the advancement and development of technology, as well as people's pursuit of convenience and multi-functions, the applications on wearable devices are becoming more and more abundant and the functions are becoming more and more powerful.

[0003] The operation of applications involves memory management. Currently, due to the limited hardware resources of wearable devices, memory management methods that occupy relatively small resources are generally used, such as the best fit algorithm. This algorithm uses a linked list to manage memory space. When an application requests memory, it selects the most appropriate memory node from the linked list and returns the corresponding memory address.

[0004] However, in wearable devices, when an application frequently requests memory in a short period of time, it may cause the process to consume a lot of time, resulting in performance degradation. Summary of the invention

[0005] The embodiment of the present application provides a memory method and electronic device, which are applied to the field of wearable devices. When the application is started, a memory area is allocated to the application in advance according to the configuration information. Each memory area corresponds to a preset capacity, and the memory area contains multiple memory blocks, and the memory capacity of each memory block is equal to the preset capacity. When the application in the wearable device applies for memory, it will directly search for a suitable memory block from the memory area and return the memory address. This method can effectively speed up the efficiency of memory application and release, thereby improving the performance and performance of application operation.

[0006] In a first aspect, an embodiment of the present application provides a memory management method, which is applied to a wearable device, and the method includes:

[0007] In response to the start of the first application, a plurality of memory areas corresponding to respective preset capacities are allocated to the first application, wherein the memory area includes a plurality of memory blocks with the same capacity, and the capacity of the memory blocks in the memory area is equal to the preset capacity;

[0008] In response to a first request of a first application, determining a first memory area among a plurality of memory areas, and determining a first memory block among a plurality of memory blocks of the first memory area;

[0009] The address information of the first memory block is returned to the first application to allocate the first memory block to the first application.

[0010] In this implementation, during the operation of the first application after it is started, memory application and release will continue to occur, and multiple memory applications may occur frequently in a short period of time. This method allocates multiple memory areas of preset capacity in advance, and sets multiple memory blocks of the same memory size as the preset capacity in each memory area. When the first application applies for memory, it will select a memory area with a preset capacity greater than or equal to the memory capacity applied for from multiple allocated memory areas according to the capacity of the applied memory, as the first memory area. Then, in the first memory area, a free memory block is further selected as the first memory block, and the memory address is returned to the first application. In this way, even if the first application frequently applies for memory multiple times in a short period of time, since the memory area has been allocated to the first application in advance and the efficiency of the first memory block is determined to be high, the time consumed by the memory application can be significantly shortened, thereby improving the operating efficiency of the first application.

[0011] In a possible implementation, in response to starting the first application, a plurality of memory areas corresponding to respective preset capacities are allocated to the first application, including:

[0012] In response to starting the first application, obtaining first configuration information corresponding to the first application, the first configuration information including allocation quantities associated with each of a plurality of preset capacities;

[0013] According to the first configuration information corresponding to the first application, memory areas corresponding to a plurality of preset capacities are allocated to the first application, and the number of memory blocks included in the memory area corresponding to any preset capacity is equal to the allocated number.

[0014] In this implementation, it is described that when the first application is started, the wearable device can allocate a memory area for it in advance according to the first configuration information. The first configuration information includes the preset capacity of different memory areas and the number of memory blocks associated with different preset capacities. Among them, the first configuration information can be obtained in combination with the memory application and release of the first application during operation. In other words, when the wearable device allocates a memory area for the first application in advance, it will take into account the preset capacity of the applied memory area and the number of memory blocks in each memory area. The purpose is to enable the allocated multiple memory areas to meet the memory application of the first application as much as possible and cope with the situation of frequent memory applications in a short period of time, while also avoiding a large amount of occupation and waste of memory resources as much as possible.

[0015] In a possible implementation, the method further includes:

[0016] Generate first configuration information according to memory usage information of the first application during operation;

[0017] The memory usage information includes multiple memory application information and multiple memory release information. The memory application information includes the capacity of the memory block applied for by the first application and the time of application. The memory release information includes the capacity of the memory block released by the first application and the time of release.

[0018] In a possible implementation, generating the first configuration information according to the memory usage information of the first application during operation includes:

[0019] For any first interval among the preset multiple intervals, based on the memory usage information of the first application during the running process, determine the occupied quantity corresponding to each of the multiple moments in the running process of the first application, where the occupied quantity is the number of memory blocks whose capacity occupied by the first application belongs to the first interval;

[0020] Determine a maximum value among the occupancy quantities corresponding to the multiple moments to obtain a target quantity corresponding to the first interval;

[0021] First configuration information is generated according to target quantities corresponding to each of the plurality of intervals.

[0022] In this implementation, the production process of the first configuration information is described. First, during the operation of the first application, its memory usage information is recorded. The memory usage information may include time information of memory application and release, as well as corresponding capacity information. Then, the interval range of the memory capacity may be determined according to the actual situation, such as 0B~8B, 8B~16B, 16B~32B, etc., where B represents Byte, that is, one byte, and the same applies below. For any of the interval ranges of the memory capacity, statistics are performed in the recorded memory usage information, and the interval range here may also be referred to as the first interval. First, from the memory usage information, according to whether the memory capacity information is within the first interval, the corresponding recorded information is filtered out. Then, according to the application and release at each moment, the memory occupancy corresponding to each moment is statistically obtained, that is, how many memory blocks in the first interval are still occupied by the first application at each moment. Then, a maximum value is determined from the number of memory block occupancy obtained by statistics at multiple moments, and the maximum value is used as the target number of the first interval.

[0023] This method first combines the memory usage during the actual operation of the first application, obtains the first configuration information by statistics, and then allocates multiple memory areas to the first application according to the first configuration information when the first application is started. It can be understood that the number and time of applying for and releasing memory will not be exactly the same each time the first application runs, but there will be certain similarities in general. Therefore, the first configuration information obtained in this way can more accurately reflect the usage peak of the first application in different memory capacity intervals during the operation process, so as to effectively deal with the problem of a large number of memory applications in a short period of time for the first application. At the same time, this can also significantly improve the hit rate. The hit rate here refers to the proportion of the first application's memory application or release requests that are processed by the memory management module. The higher the hit rate, the shorter the overall time consumed in memory application and release, and the better the application's operating performance.

[0024] In a possible implementation, generating first configuration information according to target quantities corresponding to each of the multiple intervals includes:

[0025] For any first interval among the multiple intervals, determining a preset capacity corresponding to the first interval, wherein a maximum value of the first interval is equal to the preset capacity;

[0026] Determine that the number of memory blocks associated with the preset capacity corresponding to the first interval is equal to the target number corresponding to the first interval, so as to generate first configuration information.

[0027] In this implementation, it is described that the maximum value of the first interval is used as the preset capacity of the corresponding memory area, and at the same time, the target number of the first interval obtained based on the memory usage information of the first application is used as the number of memory blocks in the corresponding memory area. Since the target number is the maximum value of the memory blocks occupied at each moment obtained by statistics, when the first application encounters similar frequent memory requests during subsequent operation, it can generally ensure that free memory blocks that meet the needs can be obtained from the pre-allocated memory area. In this way, on the one hand, it can avoid wasting precious memory resources in the wearable device, and on the other hand, it can also maximize the possibility of the first application always being able to quickly apply for free memory.

[0028] In a possible implementation, in response to a first request of a first application, determining a first memory area from among a plurality of memory areas includes:

[0029] In response to a first request of a first application, obtaining a first application capacity included in the first request;

[0030] When the first application capacity is less than a preset threshold, a first memory area is determined from among the multiple memory areas, wherein the first memory area is a memory area having the smallest difference between the corresponding preset capacity and the first application capacity among the multiple memory areas.

[0031] In a possible implementation, determining a first memory block from a plurality of memory blocks in a first memory area includes:

[0032] Among the multiple memory blocks in the first memory area, a memory block in an idle state is determined as the first memory block.

[0033] In this implementation, a process of determining a first memory block from multiple memory areas when a first application applies for memory is described. First, the memory area is determined according to the memory capacity contained in the memory application request, wherein the memory application request may also be referred to as the first request, and the corresponding memory capacity may be referred to as the first application capacity. Among the multiple memory areas, a memory area whose preset capacity is greater than or equal to the first application capacity and whose difference between the preset capacity and the first application capacity is the smallest may be selected as the first memory area. Then, in the first memory area, a memory block in an idle state is selected as the first memory block, and the memory address is returned.

[0034] This method, combined with the above-mentioned first configuration information, can make the memory management as expected during the entire process of the first application running. In the first configuration information, different memory capacity intervals and corresponding target quantities are set. For example, a memory area with a preset capacity of 8B, in which the size range of memory objects that can be accommodated is 0B to 8B; a memory area with a pre-trial capacity of 16B, although the size range of memory objects that can be accommodated is 0B to 16B, in this method, memory objects in the range of 8B to 16B will be preferentially accommodated. In other words, for example, a 7B object, although it can be stored in a memory area with a preset capacity of 8B or a memory area with a preset capacity of 16B, will be preferentially stored in a memory area with a smaller preset capacity. This is mainly because the first configuration information itself is obtained by statistics based on the memory interval range, and memory management in this way can also play a role in reducing memory fragmentation.

[0035] In a possible implementation, the method further includes:

[0036] In response to a second request of the first application, the first memory block is marked as being in an idle state, wherein the first memory block marked as being in an idle state belongs to the first memory area.

[0037] In this implementation, it is explained that in the memory area, not only corresponding memory is allocated to the memory application of the first application, but also memory processing is performed according to the request for memory release, wherein the memory release request can also be referred to as the second request. Here, when processing the second request, the memory block corresponding to the memory address in the second request is not directly returned to the operating system of the wearable device, but continues to be retained in the memory area, and the corresponding memory block is reset to an idle state. In this way, the memory blocks in the memory area can be reused according to demand. For example, when the first application applies for and occupies a certain memory block, and then releases the memory block, if a memory block of similar size memory capacity is applied for later, the memory block can still be used. In this way, the overall memory utilization efficiency is improved, and there is no need to prepare a new idle memory block for each memory application.

[0038] In a possible implementation, the method further includes:

[0039] In response to closing the first application, the memory area allocated for the first application is released.

[0040] In this implementation, it is explained that when the first application ends running, the memory area allocated to it when the first application is started will also be released. In this way, on the one hand, it does not occupy the precious memory space in the wearable device and does not affect the subsequent running of other applications. On the other hand, it can also reduce unnecessary power consumption to a certain extent.

[0041] In a second aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, the memory being used to store code instructions, and the processor being used to run the code instructions to execute the method described in the first aspect or any possible implementation of the first aspect.

[0042] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program or instructions are stored. When the computer program or instructions are run on a computer, the computer executes the method described in the first aspect or any possible implementation of the first aspect.

[0043] In a fourth aspect, an embodiment of the present application provides a computer program product comprising a computer program, which, when executed on a computer, enables the computer to execute the method described in the first aspect or any possible implementation manner of the first aspect.

[0044] In a fifth aspect, the present application provides a chip or a chip system, which includes at least one processor and a communication interface, the communication interface and the at least one processor are interconnected by a line, and the at least one processor is used to run a computer program or instruction to execute the method described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip can be an input / output interface, a pin or a circuit, etc.

[0045] In a possible implementation, the chip or chip system described above in the present application further includes at least one memory, in which instructions are stored. The memory may be a storage unit inside the chip, such as a register, a cache, etc., or a storage unit of the chip (e.g., a read-only memory, a random access memory, etc.).

[0046] It should be understood that the second to fifth aspects of the present application correspond to the technical solutions of the first aspect of the present application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A schematic diagram of memory allocation provided in an embodiment of the present application;

[0048] Figure 2 A schematic diagram of implementing linked list-based memory management provided in an embodiment of the present application;

[0049] Figure 3 A schematic diagram of implementing the memory application of the Best Fit algorithm provided in an embodiment of the present application;

[0050] Figure 4 Implementation diagram of memory release of the Best Fit algorithm provided in the embodiment of the present application Figure 1 ;

[0051] Figure 5 Implementation diagram of memory release of the Best Fit algorithm provided in the embodiment of the present application Figure 2 ;

[0052] Figure 6 A schematic diagram of a wearable device application interface provided in an embodiment of the present application;

[0053] Figure 7 Schematic diagram of JS software architecture provided for the embodiment of the present application;

[0054] Figure 8 A schematic diagram of the application program operation process provided in the embodiment of the present application;

[0055] Fig. 9A schematic diagram of memory allocation during application execution provided in an embodiment of the present application;

[0056] Fig.10 A schematic diagram of the hardware architecture of a wearable device provided in an embodiment of the present application;

[0057] Fig.11 A schematic diagram of the software architecture of a wearable device provided in an embodiment of the present application;

[0058] Fig.12 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 1 ;

[0059] Fig.13 Schematic diagram of the memory management architecture provided in the embodiment of the present application Figure 1 ;

[0060] Fig.14 A schematic diagram of the implementation of the memory area and memory block provided in the embodiment of the present application;

[0061] Fig.15 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 2 ;

[0062] Fig.16 Schematic diagram of the memory management architecture provided in the embodiment of the present application Figure 2 ;

[0063] Fig.17 A schematic diagram of an implementation of a configuration file for memory management provided in an embodiment of the present application;

[0064] Fig.18 A schematic diagram of implementing memory application provided in an embodiment of the present application;

[0065] Fig.19 A schematic diagram of implementing memory application and release provided in an embodiment of the present application;

[0066] Fig. 20 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 3 ;

[0067] Fig.21 A schematic diagram of a memory log of an application running process provided in an embodiment of the present application;

[0068] Fig. 22 A schematic diagram of implementing memory usage peak statistics during application operation provided in an embodiment of the present application;

[0069] Fig.23 A schematic diagram of a curve showing the change in memory usage over time during the running of an application provided in an embodiment of the present application;

[0070] Fig.24 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 4 ;

[0071] Fig.25 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0072] In order to clearly describe the technical solutions of the embodiments of the present application, some terms and technologies involved in the embodiments of the present application are briefly introduced below:

[0073] 1. JavaScript

[0074] JavaScript is a widely used high-level programming language that was originally designed for web development to enhance user interaction with web pages. With the development of technology, JavaScript has become a full-stack language that is not only used on the browser side, but also widely used on the server side.

[0075] JavaScript has certain conveniences in building applications, including: 1. Cross-platform. JavaScript code can run on multiple platforms, including operating systems such as Windows, macOS, and Linux, as well as various mobile devices and servers; 2. Dynamic typing. JavaScript is a weakly typed or dynamically typed programming language. Developers do not need to declare data types in advance, which makes code writing more flexible and faster; 3. Object-oriented. It supports a prototype-based object model, which simplifies object-oriented programming; 4. Rich libraries and frameworks, with a huge ecosystem, these tools greatly accelerate the development process.

[0076] 2. JerryScript

[0077] JerryScript is a lightweight JavaScript interpreter designed specifically for resource-constrained devices such as wearable devices, microcontrollers, and other embedded systems. It makes it possible to execute JavaScript code in these environments with limited computing power and small memory.

[0078] Its main features include: small size, the compiled JerryScript library is very small; low resource consumption, JerryScript is optimized to use as little CPU and RAM resources as possible; good compatibility, supporting most functions of standard specifications; modularity, the high modularity of JerryScript allows users to include or exclude specific functions as needed to further reduce the size.

[0079] 3. Memory Management

[0080] Memory management refers to how the operating system allocates, manages, and releases memory resources of a computer or other electronic device to ensure that programs can run efficiently and that multiple programs can safely share limited physical memory. Good memory management is essential to improving system performance because it directly affects multitasking capabilities, response speed, and overall system stability.

[0081] Memory management involves some key concepts, including memory allocation and memory recycling. For memory allocation, the program needs a certain amount of memory to store information such as code, data, and stack when running, and appropriate memory space needs to be allocated. For memory recycling, when the program no longer needs certain memory blocks, these memory blocks will be recycled so that other programs or other parts of the same program can use them again.

[0082] 4. Memory fragmentation

[0083] Memory fragmentation refers to the phenomenon that during the memory management process, the available memory space is divided into many small blocks due to the discontinuity of program allocation and release of memory. These small blocks are free when viewed individually, but are too small to satisfy new memory allocation requests.

[0084] Among memory fragmentation, a common type is external fragmentation. External fragmentation occurs in memory management at the operating system level. When multiple programs allocate and release memory blocks of different sizes, some small, scattered free areas may be left. Although the total free memory may be sufficient, these free blocks are isolated from each other and are not of the right size, so they cannot be combined to satisfy a larger new allocation request. This will result in the system being unable to effectively utilize the total free memory, even though there may be enough free memory.

[0085] 5. BestFit Algorithm

[0086] Best Fit is a memory allocation algorithm that selects the partition closest to the requested size from the available free partitions when allocating memory. Specifically, when a process requests a certain amount of memory, Best Fit searches the list of all free partitions for the partition that best fits the requested size, that is, the smallest partition that can accommodate the requested size.

[0087] The goal of Best Fit is to minimize external fragmentation because it always tries to reserve large blocks of free space for possible large-scale memory requests in the future. However, Best Fit may need to traverse the entire list of free partitions to find the most suitable partition, which will result in a slower allocation speed. In other words, Best Fit is a memory allocation algorithm that focuses on memory efficiency but sacrifices a certain allocation speed. When designing an operating system or memory manager, it is necessary to weigh the pros and cons of different algorithms according to the needs of specific applications.

[0088] 6. Time complexity

[0089] Time complexity is a concept in algorithm analysis that describes the relationship between the running time of an algorithm and the size of the data. It measures how quickly the time required for an algorithm to execute grows as the amount of data increases. Time complexity is often expressed in big O notation, such as O(n), O(log n), or O(1), representing different types of efficiency and performance characteristics.

[0090] Time complexity is one of the important tools used in computer science to analyze and compare the efficiency of algorithms. It is not determined by timing, but by counting the number of basic operations of the algorithm, such as comparison and addition, and only retaining the part that plays a dominant role as the data scale increases. Understanding time complexity helps developers predict the scalability and performance bottlenecks of the algorithm and make improvements accordingly.

[0091] 7. Stack Space / Heap Space

[0092] In computer science, stack space and heap space are two data structures or areas used for memory management, which have different characteristics and uses. Stack is a Last In First Out (LIFO) data structure. It is usually used to store local variables, parameters, return addresses and other information during function calls. When a function is called, a new stack frame is created and pushed to the top of the stack; when the function is executed, the stack frame is popped from the top of the stack. Stack management is done automatically by the compiler, so its operation is very efficient. The size of the stack space is usually predetermined and limited.

[0093] The heap is an area where memory can be dynamically allocated and has no fixed structure. Programmers can request and release memory blocks on the heap through the interface provided by the programming language. Memory on the heap can be shared between different parts of the program, and its life cycle is not determined by function calls, but can be explicitly controlled by the programmer. Because more management work is required, the operation of the heap is usually slower than the stack.

[0094] 8. Other terms

[0095] In the embodiments of the present application, words such as "first" and "second" are used to distinguish the same or similar items with substantially the same functions and effects. For example, the first chip and the second chip are only used to distinguish different chips, and their order is not limited. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.

[0096] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0097] In the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, c can be single or multiple.

[0098] 9. Wearable devices

[0099] In the embodiments of the present application, wearable devices refer to electronic devices designed to be worn on the body, which usually integrate microcomputer technology, sensors and other hardware, and can perform multiple functions, such as tracking health data, receiving notifications, playing music, etc. Such devices are often paired with smartphones or other computing devices, and can also operate independently.

[0100] Common wearable devices include smart watches and smart bracelets, which can display time, receive call and message notifications, and are often equipped with heart rate monitors, GPS and other functions. They can also track users' exercise status and sleep quality.

[0101] Wearable devices also include smart glasses, which may be used for navigation, taking pictures or video calls; ear-worn devices, in addition to basic audio playback, may also have noise reduction functions and health monitoring functions, such as detecting body temperature.

[0102] Wearable devices can also be clothing and accessories, such as smart clothing, shoes or other accessories with built-in sensors that can be used to monitor physical condition or improve athletic performance.

[0103] Based on the above introduction, the relevant technologies involved in this application are further introduced in detail below.

[0104] Nowadays, wearable devices are becoming more and more popular. Smart bracelets and smart watches, as typical representatives of wearable devices, have gradually become an indispensable part of modern life. They not only include the traditional function of checking time, but also bring unprecedented convenience to health management, information acquisition, life and work.

[0105] For example, in terms of health management, wearable devices integrate a variety of sensors that can track users' daily activities, such as steps, distance, calories burned, etc., and can monitor heart rate, sleep patterns and even stress levels. Through long-term data accumulation and analysis, users can get personalized health advice and even warn of potential health risks. When an abnormal heart rhythm is detected, the smartwatch may remind the user to seek medical help. This instant feedback helps people manage their health more proactively.

[0106] In terms of information acquisition, smart watches provide a fast and convenient channel for receiving notifications. Whether it is text messages, emails or social media updates, all important information can be seen at a glance on the wrist. Some models of wearable devices also support voice assistant functions, allowing users to complete tasks such as checking the weather, setting alarms or navigation routes through simple voice commands, greatly improving efficiency. In addition, payment functions have also been integrated into some devices, allowing users to easily complete transactions without taking out their mobile phones.

[0107] Also, from the perspective of daily life and work, functions such as calendar synchronization and reminders make smart bracelets and watches excellent personal assistants. For busy professionals, it is crucial to receive meeting notifications or schedule changes in the first place. With the advancement of technology, various wearable devices will continue to evolve, providing users with more diverse and more intimate services, and becoming a bridge between the digital world and real life.

[0108] At the same time, the popularity of wearable devices such as smart watches and smart bracelets has spawned a rich and colorful third-party application ecosystem. These applications have greatly expanded the functionality of the devices and met the diverse daily needs of users. The following lists different types of third-party applications and briefly describes them:

[0109] 1. Health and fitness: This is a common category of apps that provide everything from basic heart rate monitoring to complex sports tracking services. For example, some apps can record specific data for various sports such as running, cycling, swimming, etc., and provide personalized training plans based on the user's activity level. There are also specialized apps that help users monitor their food intake, hydration, and mental health.

[0110] 2. Message notification and communication: This type of application enhances the information delivery capabilities of the device. In addition to basic SMS and phone reminders, it also includes notifications of social media updates, emails, and other instant messaging tools. Some advanced applications also support replying to messages directly on the watch or sending instructions through voice assistants to ensure that users will not miss any important information.

[0111] 3. Payment and financial services: With the popularity of mobile payments, many smart watches now have integrated NFC (near field communication module) chips, allowing users to use built-in wallet applications for contactless payments. In addition, there are also applications for financial management that can help users track budgets, manage bills and even investment portfolios.

[0112] 4. Travel and Navigation: Navigation apps can provide users with real-time route guidance when going out for adventure or daily commuting. They are usually connected to map services, which can not only plan the best route, but also provide practical information such as public transportation timetables and walking guides.

[0113] With the support of the above-mentioned third-party applications, smart watches and smart bracelets are not just a kind of technological accessories, but have become indispensable multi-functional partners in people's lives, continuously improving our lifestyles.

[0114] As the number of third-party applications on wearable devices increases and their functions are enhanced, it is natural to consider memory management. The following will briefly introduce the relevant technologies with reference to the accompanying drawings.

[0115] like Figure 1 As shown, a simple memory allocation architecture is shown. Figure 1 There is a memory space in the wearable device, and its capacity is assumed to be 128MB. The operating system and various applications in the wearable device need to allocate a certain amount of memory area accordingly. The processor interacts with the memory space through registers or caches to enable the application to run normally. As an example, Figure 1In the displayed memory space, the operating system occupies 22MB, process one occupies 10MB, process two occupies 24MB, process three occupies 15MB, and additional virtual memory 27MB, etc. In addition, there are some free memory areas in the memory space that are not occupied by processes. For example, free memory one is between the memory areas of process one and process two, and its memory size is 12MB, and free memory two is between the memory areas of process two and process three, and its memory size is 15MB. It can be understood that in some memory management methods, spatial memory cannot always be effectively utilized. For example, in some cases, the total memory capacity of multiple blocks of free memory can meet the memory capacity required by the application process, but because the relatively simple memory management method does not support the combination of discontinuous free memory, such multiple blocks of free memory are actually unavailable, which also forms the so-called memory fragmentation.

[0116] In wearable devices, due to limited hardware resources, both computing resources and memory resources are limited and precious. Therefore, in terms of memory management methods, the more complex memory management methods used in ordinary home computers or servers are rarely used. Instead, some relatively simple memory management methods with less resource consumption are used.

[0117] like Figure 2 As shown, a data structure similar to a linked list can be used to manage the memory space. Figure 2 The left side is still a memory space in which multiple application processes are distributed, and there are free memory areas between the application processes. Figure 2 On the right side is a one-way linked list, which has a start node and an end node, which are located at the beginning and end of the linked list respectively. There are multiple nodes in the middle of the linked list, and each node can correspond to a free memory area in the memory space. For example, node A corresponds to free memory one, node B corresponds to free memory two, and node C corresponds to free memory three. In each node, the size of the corresponding free memory area, the starting memory address and other information can be included. When a new application process wants to apply for memory space to be allocated for it, it can use the above linked list to find memory space that meets its needs and return the corresponding memory address information.

[0118] Among the memory management methods based on linked list-like data structures, a commonly used method is the Best Fit algorithm, which can also be called the best adaptation algorithm. Figures 3 to 5 The principle is briefly explained.

[0119] Figure 3 The content shown in the figure can reflect how the Best Fit algorithm handles the process when responding to memory request instructions. First, Figure 3As shown in (a), a data structure of a bidirectional linked list is shown here, omitting the start node and the end node. The linked list contains 4 nodes, namely node A, corresponding to a memory capacity of 3MB, an address segment of 278-309; node B, corresponding to a memory capacity of 5MB, an address segment of 457-510; node C, corresponding to a memory capacity of 10MB, an address segment of 105-205; node D, corresponding to a memory capacity of 26MB, an address segment of 702-963. It can be understood that the memory capacity size and address segment corresponding to the nodes in the figure are used as examples to illustrate the process of the Best Fit algorithm, which does not completely correspond to the actual device situation, and will not be repeated here. It can also be noted that the nodes in the linked list are sorted according to their corresponding memory capacity, gradually increasing from left to right. In some implementations, the Best Fit algorithm sorts the nodes in the linked list according to their corresponding memory capacity in order to return the address information of the best-fitting memory area more quickly when responding to the memory request instruction.

[0120] For example, if an application wants to apply for a memory space with a capacity of 8MB, it can start from the left side of the linked list and check whether the capacity requirement is met one by one. Since the memory capacity corresponding to node A is 3MB, which is less than 8MB, it does not meet the requirement, and continues to check the next node, corresponding to Figure 3 (b). Similarly, we can see Figure 3 Node B in (b) also does not meet the requirement of providing at least 8MB of memory space, so we check further, corresponding to Figure 3 (c). Since the memory capacity corresponding to node C is 10MB, which is larger than the 8MB required by the memory application, the address of the memory space corresponding to node C can be returned to the application. In some implementations, 10MB of memory space is not directly allocated to the application, but 8MB is still allocated on demand, and the information of node C is adjusted, including the memory capacity of the remaining 2MB and the corresponding memory address information.

[0121] After the memory space of node C is allocated to the application, node C can be deleted. At the same time, the linked list needs to adjust and maintain its own data structure. Figure 3 As shown in (d), after node C is gone, node B needs to connect to node D.

[0122] The above combination Figure 3This paper briefly explains how the Best Fit algorithm allocates memory. To sum up, when facing a new memory request, it always selects a memory area in the free memory that can meet the demand and has the smallest memory capacity for allocation. This can reduce memory fragmentation to a certain extent and increase memory allocation efficiency. In addition, for the convenience of understanding, the above method uses a method of checking from left to right in response to memory request instructions and looking for the best-fit node. However, in fact, the time complexity of this method is relatively low, only O(n), where n can be understood as the number of nodes in the linked list. When the nodes in the linked list are already sorted by memory capacity, a method such as binary search can be used to find the best-fit node, and the time complexity at this time will be reduced to O(log n). When the number of nodes increases, the efficiency of the algorithm can be effectively improved.

[0123] It is understandable that a complete memory management method should not only include memory application, but also include the process of memory release. Figure 4 and Figure 5 For explanation. Figure 4 As shown, suppose there was originally a linked list, including node A, corresponding to a memory capacity of 3MB, address segment 278-309; node B, corresponding to a memory capacity of 5MB, address segment 457-510; node D, corresponding to a memory capacity of 26MB, address segment 702-963. Now the application process releases a memory area with a capacity of 10MB and an address segment of 105-205. When Best Fit adds a new node to the linked list data structure, it wants to maintain its overall state sorted by node memory capacity. Therefore, it cannot simply add the new node to the beginning or end of the linked list. Figure 4 In the example, the memory capacity of the new node C is 10MB, so it should be between node B and node C in terms of size. Similarly, this process still requires a certain amount of computing power, and generally speaking, the time complexity is O(logn).

[0124] Furthermore, in more complex cases, the memory release process may be as follows Figure 5 As shown. Figure 5In the example, assume that the application releases a memory space with a memory capacity of 10B and a memory address segment of 356-456. The linked list contains three nodes, including node A, corresponding to a memory capacity of 3MB and an address segment of 278-309; node B, corresponding to a memory capacity of 5MB and an address segment of 457-510; and node D, corresponding to a memory capacity of 12MB and an address segment of 702-823. First, the released memory address information is combined to determine whether the released memory space forms a continuous memory space with the memory space of the node in the current linked list. For example, the address segment 356-456 of the released memory space and the address segment 457-510 corresponding to node B can form a continuous memory space, so the information of node B can be modified without adding a new node. Then, the information of node B is modified to a memory capacity of 15MB and a memory address segment of 356-510. Finally, since the information of node B has changed, it is also necessary to check whether the order of the overall memory capacity of the linked list is met, so the position of node B needs to be adjusted. For example, node A is connected to node D, and then node D is connected to node B.

[0125] From the above description, we can see that the Best Fit algorithm itself is relatively simple and does not consume much resources, so it is often used in some wearable devices.

[0126] However, there may be some problems when the wearable device application runs under the memory management method described above. In order to better explain the relevant issues, the following is an explanation based on some actual scenarios.

[0127] With the development of technology, the applications of wearable devices are becoming more and more abundant and their functions are becoming more and more powerful. Figure 6 As shown, in Figure 6 (a) shows an application interface of a smart bracelet, which can contain multiple types of applications, such as text messages, videos, communications, and news. Users can click to interact and use them. When users click on the communication application, they can see Figure 6 (b) shows the screen. Figure 6 In (b), there is a communication list, each row represents a communication friend, including the friend's avatar, the latest information, etc. After seeing the communication list, the user can further click on a friend to communicate.

[0128] Applications like this can be quickly developed on wearable devices using JerryScript. JerryScript is similar to JavaScript and can be seen as an object-oriented high-level programming language. The JerryScript engine can be seen as a lightweight JavaScript engine that is specially optimized to reduce its demand for system resources and is designed for resource-constrained devices, such as various wearable devices and Internet of Things (IoT) devices. Its goal is to run JavaScript code in a low-power, small-memory environment. In the following text, JerryScript will be referred to as JS. Figure 7 A brief description of its architecture in wearable devices is given.

[0129] like Figure 7 As shown, from top to bottom, it includes the application layer, JS application framework layer, OS framework layer and OS kernel layer. Among them, the application layer includes third-party applications, pre-installed applications, etc. The JS application framework can also be called the JS engine, which is a software component responsible for interpreting or compiling and executing JS code, including JS data binding, JS runtime and JS framework (C++). Among them, the JS runtime provides the necessary environment for the application to run, and there are various open source or developer-customized libraries in the JS framework for application calls. A structural pattern adopted by the JS engine can be called MVVM, which is an architectural pattern that separates data and UI through Model, View and ViewModel, emphasizing data binding and decoupling.

[0130] Among them, Model represents the data model or business logic of the application, which is responsible for handling the access, processing and operation of data. It usually includes data structure, database operations, network requests, etc. Model does not interact directly with the UI layer. It only exposes some interfaces for the ViewModel layer to call, so that the ViewModel can obtain the required data. View is the visual part of the user interface, responsible for displaying data and interacting with users. The ViewModel is the bridge between the Model and the View, responsible for taking data from the Model and converting it into a form that can be used by the View. The ViewModel does not directly operate the View, but binds the data to the View through the data binding mechanism, so that the changes in the data can be automatically reflected in the View, realizing the two-way binding of data. Data binding is one of the core features of the MVVM framework. It synchronizes the data of the View and ViewModel so that they stay synchronized. When the data in the ViewModel changes, the data binding will automatically update the part of the View that is bound to the data, and vice versa.

[0131] For applications written in JS, the running process can be as follows Figure 8 As shown, they are parsing, compiling, and execution. First, when a JS file is loaded, the JS engine will parse the code first. At this stage, the engine converts the source code into an abstract syntax tree (AST), which is a data structure that represents the structure of the program. If a syntax error is encountered during this process, it will immediately throw an error and stop execution. Next is compilation. Modern JS engines can use Just-In-Time Compilation (JIT) technology to compile the code while parsing. The JIT compiler converts AST into bytecode or directly generates machine code. This step can optimize code performance at runtime because the compiler can adjust the way the code is compiled according to the actual running situation. Finally, once the code is compiled, the JS engine starts to execute the code. Since JS is a single-threaded language, there is only one call stack and one task queue by default, so the code is generally executed synchronously in sequence.

[0132] Since JS itself is an interpreted language, relatively early JS engines need to interpret the code line by line. In other words, in many cases, it is not possible to clearly know how much memory space is needed when the application starts running, and memory can only be requested sequentially as needed during the running process. With the development of technology, modern JS engines have introduced just-in-time compilation and other optimization technologies, so that JS code does not always run in a purely interpreted manner, but the efficiency of memory application and release is still far behind static languages ​​like C++.

[0133] Therefore, when the JS application is running, a large amount of memory will be requested. Fig. 9 Let's take an example to illustrate. Fig. 9As shown, the left side is a relatively simple JS program code. The first line declares an integer variable num as 42, the second line declares a string variable str as "Hello", and the third line adds the two variables to obtain a new string variable result. The memory space on the right side correspondingly shows the memory application involved in the running process of the application on the left. The memory space can be divided into stack space and heap space, wherein the stack space can directly store variables of basic types, for example, memory block 901 corresponds to the integer variable num declared in the first line. For some non-basic type variables, such as the string variable str in the second line, they are generally not directly stored in the stack space, but only an address pointer is stored in the memory block 902 of the stack space, pointing to the memory block 904 in the space, and the specific value "Hello" of the string variable str is stored in the memory block 904. When adding two variables, since the data type of the variable num is an integer, it also needs to be converted to a string type first, corresponding to the memory block 905 in the heap space, in which the converted value "42" is stored. Finally, "Hello" and "42" are concatenated and stored in memory block 906 to obtain "Hello 42".

[0134] Through the description of the above scenarios, it can be understood that JS language can help developers develop and iterate third-party applications faster, which helps users experience more complete and powerful applications. However, from the examples provided above, it can be seen that even a short program involves several memory requests. For a large application, many memory requests will be involved during the operation. In some cases, the application may even have a large number of memory requests in a short period of time. For example, when opening a communication application, the rendering of the contact list may involve hundreds of memory requests, and the virtual machine scheduling of the JS engine may involve tens of thousands of memory requests. Generally speaking, these large amounts of memory requests correspond to relatively small memory spaces, such as a few bytes or dozens of bytes. The problem is that if a large number of small memory requests appear in a short period of time, in some wearable devices, it may significantly affect the operating efficiency of third-party applications.

[0135] Understandably, some relatively complex memory management methods are used on general home computers or servers, and since the hardware resources are relatively abundant, there will be no problem in the face of a large number of memory applications in a short period of time. However, on wearable devices, when using the Best Fit algorithm similar to the one introduced above for memory management, memory application and release may take up a lot of time. For example, each time memory is applied, it is necessary to find the most suitable node from the linked list corresponding to the BestFit algorithm to allocate memory. Each time memory is released, it may be necessary to insert new nodes into the linked list, or adjust the nodes, and sort the node positions. Although the time complexity of these memory application and release processes is not very high in theory, when a large number of memory applications and releases are required within a period of time, it will definitely take a long time. The normal operation of the application depends on the application and release of memory. When the memory management method is difficult to cope with a large number of memory applications in a short period of time, the corresponding application will also become stuck, which will obviously affect the user experience.

[0136] Based on this, the embodiment of the present application proposes the following technical concept: for third-party applications in wearable devices, record the information of memory application and release during runtime. Then, based on the memory usage information statistics, a configuration information is generated. When the subsequent application is started, multiple memory areas are allocated in advance according to the configuration information, and each memory area corresponds to a preset capacity. Each memory area contains multiple memory blocks of the same size, and the capacity of the memory block is equal to the above-mentioned preset capacity. It can be understood that each memory area can be used to store objects with a memory capacity within a certain range. In this way, when responding to the application's memory application request, the appropriate memory area is determined according to the memory capacity that needs to be allocated, and then the memory block in the memory area that is in an idle state is selected, and the corresponding memory address information is returned.

[0137] In this way, each time a memory request is processed, the target memory block can be determined very quickly, significantly improving the efficiency of memory requests. Even if a large number of memory requests appear in a short period of time, they can be processed well, and the memory management process will not become a factor that reduces the performance of the application.

[0138] The technical solution provided in this application can be applied to wearable devices. The following is a brief introduction to wearable devices.

[0139] For example, Fig.10The hardware structure diagram of the wearable device provided in the embodiment of the present application. The wearable device may include a processor 1010, a mobile communication module 1020, a wireless communication module 1030, a display screen 1040, a charging management module 1050, a power management module 1051, a battery 1052, an internal memory 1060, a memory management module 1080, and an audio module 1070, etc.

[0140] It is understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the wearable device. In other embodiments of the present application, the wearable device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0141] The processor 1010 may include one or more processing units. Different processing units may be independent devices or integrated into one or more processors. A memory may also be provided in the processor 1010 for storing instructions and data. In one implementation, for example, the processor 1010 may perform related data processing work, thereby implementing the various embodiments described later.

[0142] The wireless communication function of the wearable device can be implemented by an antenna, an antenna, a mobile communication module 1020, a wireless communication module 1030, a modem, and a baseband processor. In addition, the charging management module 1050 is used to receive charging input from a charger. The power management module 1051 is used to connect the battery 1052, the charging management module 1050 and the processor 1010.

[0143] The wearable device implements the display function through a GPU, a display screen 1040, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 1040 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. For example, the relevant implementation of the interface display introduced in the above embodiments can be performed by the GPU, the display screen 1040, and the application processor.

[0144] The wearable device can implement audio functions such as music playing and recording through the audio module 1070, speakers, receivers, and application processors.

[0145] In the embodiment of the present application, the wearable device may further include a memory management module 1080. The memory management module 1080 may cooperate with the processor 1010 to implement a memory management method for the wearable device, or in some implementations, the memory management module 1080 may be a part of the processor 1010, or its functions may be implemented by the processor 1010. The memory management module 1080 may process memory application and memory release requests of applications in the wearable device together with the operating system.

[0146] Exemplarily, the system of the wearable device in the embodiment of the present application may be a lightweight Internet of Things operating system (LiteOS) system, or the software system of the wearable device in the embodiment of the present application may also be an Android system. For example, the software architecture of the wearable device may be described by taking the LiteOS system with a layered architecture as an example. The embodiment of the present application does not specifically limit the software system of the wearable device.

[0147] The software system of the wearable device may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture, etc. The embodiment of the present application takes a system of a layered architecture as an example to exemplify the software structure of the wearable device.

[0148] For example, taking a wearable device as a smart watch, Fig.11 A schematic diagram of the software structure of a smart watch provided in an embodiment of the present application.

[0149] like Fig.11 As shown, the layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the software architecture of the smart watch can be divided into five layers, from top to bottom: application (Application, APP) layer, system service (Framework) layer, algorithm layer, hardware abstraction layer (HAL), and kernel (Kernel) layer.

[0150] The application layer may include a series of applications, such as a watch face application, a sports record application, a call application, a secure payment application, and a workout application.

[0151] The application layer also includes a memory management function, which can be used to provide the memory management method in the embodiment of the present application to third-party applications. For example, in some implementations, the third-party application can apply for and register with the memory management function to use the memory management method provided in the embodiment of the present application during operation.

[0152] The system service layer is used to provide system support for the application programs in the application layer. For example, the system service layer may include modules such as step counting service, heart rate service, calorie service, heart health service, etc.

[0153] The algorithm layer is used to provide algorithm support for the system service layer. For example, the algorithm layer may include: heart rate algorithm, dimming algorithm, sleep algorithm, safety algorithm, and wearing algorithm.

[0154] In the hardware abstraction layer, all hardware operations required by the upper layer of the system need to call the HAL-related application programming interface (Application Programming Interface, API). The software architecture layer of each hardware device has some standardized functions, and the HAL layer can be used to implement these functions.

[0155] The hardware abstraction layer may include: an interface corresponding to a C++ library, a storage interface, a display interface, a touch interface, a Bluetooth interface, and a Global Positioning System (GPS) interface.

[0156] The kernel layer can be a layer between hardware and software. The kernel refers to a system software that provides hardware abstraction layer, disk and file system control, multitasking and other functions. Among them, the kernel is the core of an operating system and the most basic part of the operating system. It is responsible for managing the system's processes, memory, device drivers, files and network systems, etc., and determines the performance and stability of the system. It is a part of the software that provides secure access to computer hardware for many applications. This access is limited, and the kernel determines when and how long a program can operate on a certain part of the hardware. The kernel layer can be the operating system kernel (OS Kernel).

[0157] Based on the above content, the method provided in the embodiment of the present application will be explained below with reference to the accompanying drawings.

[0158] First combine Figure 12 to Figure 14 A memory management method provided in an embodiment of the present application is described. Fig.12 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 1 , Fig.13 Schematic diagram of the memory management architecture provided in the embodiment of the present application Figure 1 , Fig.14 A schematic diagram of the implementation of the memory area and memory block provided in the embodiment of the present application.

[0159] Before explaining the method flow, first combine Fig.13Briefly describe the overall architecture. Fig.13 As shown, in the wearable device, three parts may be included, namely, a third-party application, a memory management module, and a memory space, wherein the third-party application may also be referred to as a first application. The first application may interact with the memory management module, and the memory management module may interact with the memory space. In addition, after the memory management module completes the memory allocation for the first application, the first application may also operate and process the corresponding memory area.

[0160] Reference below Fig.12 The steps of the memory management method in are described in detail:

[0161] S1201. In response to starting a first application, allocate a plurality of memory areas corresponding to respective preset capacities to the first application.

[0162] In some implementations, the first application may be associated or registered with the memory management module, and when the first application is started, the first application may actively send information to the memory management module to indicate its startup status. Alternatively, the memory management module may actively monitor whether the first application is started.

[0163] When the first application is started, the memory management module will apply for multiple memory areas in batches at one time. Each memory area corresponds to its own preset capacity, such as 8B, 16B, 32B, etc., where B represents Byte, that is, one byte. Each memory area contains multiple memory blocks of the same size, and the capacity of the memory block is equal to the preset capacity of the corresponding memory area. It can be understood that since multiple memory areas are applied for in batches when the first application is started, the execution efficiency is very fast.

[0164] like Fig.14 As shown, a structure of a memory area and its memory block is shown. In the memory space, the memory area allocated by the memory management module for the first application can be called a memory area of ​​preset capacity, which is isolated from other memory spaces to a certain extent. The memory area of ​​preset capacity includes multiple memory areas, such as memory area A, memory area B, memory area C, and memory area D. The number and size of memory blocks contained in different memory areas may be different. The memory blocks contained in memory area A are all 8B in size, the memory blocks contained in memory area B are all 16B in size, and so on. In addition, in some implementations, the memory blocks in each memory area are arranged according to a certain rule and have good locality, so that the execution efficiency can be improved during actual operation processing.

[0165] S1202. In response to a first request of a first application, determine a first memory area from among multiple memory areas, and determine a first memory block from among multiple memory blocks in the first memory area.

[0166] During the running of the first application, whether it is interface rendering, interaction with users, data processing, etc., a large amount of memory application is involved. Here, the memory application request of the first application is also referred to as the first request.

[0167] In response to the first request, the memory management module determines a memory area from multiple memory areas as the first memory area. In principle, the preset capacity of the first memory area should be greater than or equal to the capacity of the memory application included in the first request. For example, assuming that the first application needs to apply for 10B of memory capacity, then a memory area with a preset capacity of 8B cannot be selected, but a memory area with a preset capacity of 16B or 32B can be selected, otherwise the 10B object cannot be accommodated.

[0168] Furthermore, a first memory block needs to be determined in the determined first memory area. It is understandable that the first memory block needs to be a memory block in an idle state, that is, a memory block not occupied by other objects of the first application or occupied by other applications.

[0169] It should be noted that the above process of determining the first memory area and the first memory block is very fast. Different from the Best Fit algorithm in the wearable device introduced above, which needs to maintain the linked list data structure in the process of managing memory, the memory area and memory block involved in the memory management method provided in the embodiment of the present application will not change in data structure during the memory application process, which is more efficient. In addition, more comparisons on memory management efficiency will be described in detail below.

[0170] S1203. Return address information of the first memory block to the first application to allocate the first memory block to the first application.

[0171] After the first memory block is determined, the address information of the first memory block can be returned to the first application, so that the memory block is allocated for the first request of the first application. In some implementations, the returned address information can include the start address and end address of the first memory block, or can also include the start address and memory capacity of the first memory block.

[0172] On the basis of the above introduction, the memory management method is further summarized and described below. In an embodiment of the present application, when the first application is started, multiple memory areas are allocated through the memory management module, each memory area contains multiple memory blocks of the same size, and the sizes of memory blocks corresponding to different memory areas are different. When the first application needs to apply for memory, the memory management module can select a suitable memory area from the multiple memory areas as the first memory area according to the size of the memory capacity in the memory application request, and then select an idle memory block in the first memory area as the first memory block. Then return the address information of the first memory block to the first application to complete the memory application process.

[0173] In this process, multiple memory areas are allocated in batches in advance. When processing memory application requests, it is only necessary to determine the memory area in combination with the request information, and further determine the free memory blocks in the memory area. Compared with some other memory management methods, such as the Best Fit method described above, this process is more efficient and can cope with a large number of memory applications in a short period of time. In addition, due to the locality brought by the fixed size and regular arrangement of memory blocks in the memory area, and the invariance of the data structure of the memory area during the memory management process, the efficiency of memory application execution can be higher and the process time can be shorter. In this way, even if a large number of memory applications appear in a short period of time, they can be processed quickly. In addition, different preset capacities are set for different memory areas instead of a uniform size, so that a reasonable choice can be made according to the actual memory capacity applied for, avoiding the waste of memory resources.

[0174] Based on the above embodiments, Figures 15 to 19 The memory management method provided in the embodiment of the present application is described in detail. Fig.15 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 2 , Fig.16 Schematic diagram of the memory management architecture provided in the embodiment of the present application Figure 2 , Fig.17 A schematic diagram of an implementation of a configuration file for memory management provided in an embodiment of the present application, Fig.18 A schematic diagram of implementing memory application provided in an embodiment of the present application, Fig.19 A schematic diagram of the implementation of memory application and release provided in an embodiment of the present application.

[0175] like Fig.16As shown, the architectural relationship between the modules involved in the embodiments of the present application is shown. The first application in the wearable device can interact with the memory management module, and the memory management module can interact with the operating system of the wearable device, and can also operate and manage the corresponding memory space. It can be understood that the operating system of the wearable device can naturally control and operate the memory space, and after the first application applies for the memory, it can also operate the corresponding memory area. This architectural diagram is only used to show the simple relationship between the modules, and omits some parts that are not related to the memory management method provided in the embodiments of the present application. It does not represent a complete real architecture and will not be repeated here.

[0176] refer to Fig.15 Steps in the process:

[0177] S1501. In response to starting a first application, obtain first configuration information corresponding to the first application.

[0178] In the embodiment of the present application, different applications in the wearable device may correspond to different configuration information. The first configuration information corresponding to the first application may be used to instruct the memory management module how to allocate a memory area for the first application.

[0179] In some implementations, the first configuration information may be stored in the data space of the wearable device in the form of a file. One application corresponds to one file, and the name of the file may be mapped one-to-one with the application. For example, the file name is the name of the application, or the file name is an ID that is bound to the application. In this way, when the first application is started, the memory management model can directly locate the configuration file in the corresponding data space quickly and read the configuration information from the configuration file.

[0180] In other implementations, the configuration information of multiple applications may be recorded in one file. Fig.17 As shown, Fig.17 A configuration information table is shown in the table, and the column names from left to right are ID, application name, capacity 8B, capacity 16B and capacity 1024B, etc. Among them, ID can be understood as the application number, which is unique and non-repetitive. Capacity 8B means the number of memory blocks that need to be set in the memory area with a preset capacity of 8B. Similarly, capacity 16B, capacity 1024B, etc. are also deduced by analogy. For example, application A with ID 1, 100 memory blocks need to be set in the memory area with a preset capacity of 8B, 400 memory blocks need to be set in the memory area with a preset capacity of 16B, and 50 memory blocks need to be set in the memory area with a preset capacity of 1024B. When the first application is started, the memory management module can start Fig.17 In the configuration information table shown, locate the row where the application is located, and read the relevant information as the first configuration information.

[0181] For more details of this step, please refer to the previous embodiment. Fig.12 S1201 is not described in detail here.

[0182] S1502. Allocate a plurality of memory areas corresponding to respective preset capacities to the first application according to first configuration information corresponding to the first application.

[0183] After obtaining the first configuration information of the first application, the memory management module allocates corresponding memory space to the first application according to the relevant information recorded in the first configuration information, including the number of memory areas, the preset capacity of each memory area, and the number of corresponding memory blocks.

[0184] In some implementations, the memory management module will allocate memory space to the information of each memory area in the first configuration information. First, the memory management module will calculate according to the first configuration information to obtain the total capacity of the memory space that needs to be applied for allocation. For example, the number of memory blocks corresponding to the memory area with a preset capacity of 8B in the first configuration information is 100, so theoretically at least 800B of memory space is required. In addition, it is also possible to consider more memory capacity required to manage the memory area. Assuming that each memory block requires an additional 1B of memory capacity, the memory area with a preset capacity of 8B will eventually require 900B of memory space. By analogy, assuming that the number of memory blocks corresponding to the memory area with a preset capacity of 16B in the first configuration information is 20, then in the end it may be necessary to apply for more memory space than 320B, such as 340B.

[0185] After determining the actual memory space that needs to be allocated according to the first configuration information, the memory management module can apply to the operating system of the wearable device for allocation of the corresponding memory space. In some implementations, the memory management module can apply to the operating system for allocation of memory space according to different memory areas, that is, apply in multiple times, so that a continuous memory space is applied for each time. In other implementations, assuming that the total memory capacity that needs to be allocated to multiple memory areas is relatively small, it is also possible to directly apply to the operating system for memory space at one time. In the above implementations, since it is a batch application for memory space to the operating system, the speed is very fast.

[0186] S1503: In response to a first request of a first application, obtain a first requested capacity included in the first request.

[0187] In the embodiment of the present application, the memory management module, corresponding to the first request of the memory application of the first application, will obtain the first application capacity from the first request, and the first application capacity is the size of the memory space that the first application wants to apply for. For example, in the first request, the first application capacity can be 7KB, 23B, etc. The first application capacity can be used to provide indication information for the subsequent memory management module to determine the target memory area in multiple memory areas.

[0188] The related technologies and methods for obtaining the first application capacity in the first request belong to the scope of the prior art and will not be described in detail here.

[0189] S1504: When the first application capacity is less than or equal to a preset threshold, determine a first memory area from multiple memory areas.

[0190] The preset in this step can be understood as the maximum value of the preset capacity corresponding to the multiple memory areas, that is, the maximum memory capacity of the memory block in the memory area. For example, considering that the memory space of a general wearable device is limited, in some implementations, the preset threshold can be set to 1024B, that is, the size of the memory block with the largest memory capacity in the multiple memory areas is 1024B.

[0191] Assuming that the first application capacity is less than or equal to the preset threshold, it means that there is a chance to allocate a memory block that meets the first application capacity among the multiple memory areas allocated to the first application. Fig.18 The corresponding process is explained in Fig.18 In (a), a suitable memory area will be selected from multiple memory areas according to the first application capacity as the first memory area. Assuming that 30B of memory space needs to be applied for here, the preset capacities of memory area A and memory area B are 8B and 16B respectively, both of which are less than the applied 30B. In the memory areas with preset capacities greater than 30B, that is, memory area C and memory area D, since the preset capacity of memory area C of 32B is closer to the first application capacity of 30B, in order to avoid wasting memory space, memory area C is selected as the first memory area.

[0192] The above method can also be explained in another way, that is, each memory area will correspond to a preset capacity, and will also correspond to a capacity range that can accept memory requests, and the preset capacity is equal to the maximum value of the memory capacity range. For example, a memory area with a preset capacity of 8B has a memory capacity range of 0-8B. A memory area with a preset capacity of 16B has a memory capacity range of 8-16B, and so on. In this way, when facing the first request capacity in the first request, it can be directly matched according to the capacity range of each memory area.

[0193] In some implementations, other more complex memory area selection methods may be used. Fig.18 For example, in (a), the information contained in each memory area, in addition to its corresponding preset capacity, also includes an overall status information, that is, whether there are any free memory blocks in the current memory area. Assuming that all memory blocks in memory area C are occupied at this time, then naturally no more allocation can be made. Therefore, if there are still free memory blocks in memory area D at this time, it is possible to consider allocating the corresponding memory blocks in memory area D for the first request, and use memory area D as the first memory area.

[0194] S1505. Determine, among multiple memory blocks in the first memory area, a memory block in an idle state as a first memory block.

[0195] After determining the first memory area, it is also necessary to determine the first memory block. Fig.18 As shown in (b), each memory block in each memory area can be in a state of being occupied by an application or in an idle state. In memory area C, the first memory block from top to bottom is in an occupied state, and the second memory block is in an idle state. Therefore, the second memory block can be used as the first memory block, and the corresponding memory address information is returned to the first application. The memory address information may include the starting address and the ending address of the memory block.

[0196] Further, after determining the first memory block, the memory management module returns its address information to the first application. For more information, please refer to the above embodiment. Fig.12 S1203 is not described in detail here.

[0197] S1506: In response to the second request of the first application, mark the first memory block as idle.

[0198] It is understandable that a complete memory management method not only processes memory application requests, but also needs to process memory release requests. During the operation of the first application, when the program corresponding to a certain block of memory is completed, it needs to be released. The memory management module responds to the memory release request of the first application to process the corresponding memory block and re-mark the corresponding memory block as idle, wherein the memory release request can also be called a second request.

[0199] In some implementations, the second request includes address information of the memory block to be released, for example, the start address and end address of the memory block, or the start address and capacity of the memory block, etc. The memory management module can locate the corresponding memory area and the memory block therein through the relevant information included in the second request, and then set it to an idle state.

[0200] The method for determining the memory area and memory block described in the embodiment of the present application can also be called a Slab algorithm. In the Slab algorithm, a memory area can be called a Slab. In order to further understand that this method can better cope with a large number of memory requests in a short period of time in an application in a wearable device, the following is combined with Fig.19 to explain in detail.

[0201] like Fig.19 As shown, in some implementations, the structure of a memory area can be similar to Fig.19 The structure shown in (a) in the figure. On the right side of the memory area in the figure, there are multiple memory blocks that are arranged closely in a regular pattern, which belong to the memory block space in the memory area. On the left side of the memory area in the figure, it can also include an information array, and the size of the information array is equal to the number of memory blocks in the memory area. For example, if there are 5 memory blocks in the memory area, then the size of the information array is also 5. The 0-4 above the information array can represent the address index of the information array. The value in the information array is also 0-4 in the initial state, which is consistent with the corresponding address index. In addition, it also includes a flag variable, which defaults to 0 and points to the value of the address index 0.

[0202] Assume that the first application has applied for three memory blocks in the memory area, then Fig.19 As shown in (b), the address information of memory block 1, memory block 2 and memory block 3 in the memory area is returned to the first application. At this time, these three memory blocks are in an occupied state. At the same time, the mark variable also changes to 3, pointing to the value with address index 3. The above changes can be explained in sequence from a single memory application, that is, at the beginning, the memory blocks in the entire memory area are in an idle state. At this time, the mark variable points to the value with address index 0, which is also 0. When responding to a memory application and needing to determine the first memory block from the memory area, the memory block corresponding to the value pointed to by the mark variable, that is, memory block 0, can be used as the first memory block, and the address information is returned. At the same time, the mark variable is increased by one and right-shifted to point to the value with address index 0. When the memory block needs to be allocated again next time, the memory block corresponding to the value pointed to by the mark variable can be used as the first memory block this time. At this time, since the value pointed to by the mark variable is 1, the address information of memory block 1 is returned. By analogy, we can get Fig.19 The situation shown in (b).

[0203] After allocating 3 memory blocks from the memory area to the first application, assuming that the first application now releases memory block 2, you can see the following Fig.19The screen shown in (c) is shown. Memory block 1 in the memory area is now in an idle state. The mark variable is reduced by one, and it moves leftward to point to the value of address index 2, and the value is modified to 1, corresponding to memory block 1. Further, assuming that the memory block is still requested from the memory area, then according to the mark variable, the address index is 2, the value is 1, and the address information of the corresponding memory block 1 is returned. Then the mark variable is shifted right, the address index is 3, the value is 3, and the address information of the corresponding memory block 3 is returned. Finally, the mark variable is shifted right and points to the value of address index 4.

[0204] Here is a summary of the above-mentioned Slab algorithm, that is, in addition to containing multiple memory blocks, a memory area also contains information for managing multiple memory blocks. For example, the values ​​0-4 in the above-mentioned information array correspond to memory blocks 0-4 respectively. The value pointed to by the mark variable and the value to its right can be considered as the memory block that is currently in an idle state. Every time you need to determine a free memory block from the memory area and return the address information, you can directly use the memory block corresponding to the value pointed to by the mark variable as the first memory block, and then shift the mark variable to the right. When releasing the memory block, you can shift the mark variable to the left, and modify the value pointed to by the mark variable to the value corresponding to the released memory block.

[0205] That is to say, when applying for and releasing memory blocks in the memory area, you only need to adjust the mark variable and the information array each time. Specifically, the mark variable is shifted to the right when the memory is applied, and the mark variable is shifted to the left and the corresponding value is modified when the memory is released, without involving more changes. The data structure of the entire memory area is fixed, and the process of determining the memory block is fast. From the perspective of time complexity, it can theoretically reach O(1), which is a constant level complexity. Compared with the complexity of the Best Fit algorithm O(log n) mentioned above, since the time for a single memory application or release is much shorter, it can also be well dealt with when a large amount of memory is applied or released in a short period of time in wearable devices.

[0206] S1507: In response to closing the first application, releasing the memory area allocated to the first application.

[0207] When the first application is closed, the first application may send a corresponding instruction to the memory management module, or the memory management module may directly monitor whether the first application is closed. When the user finishes using the first application and closes it, the memory management module returns the memory space allocated to the operating system of the wearable device in S1501 to the operating system without affecting the normal operation of other applications.

[0208] In summary, the memory management method provided in the embodiment of the present application will allocate multiple memory areas to the first application according to the first configuration information when the first application is started, and each memory area contains multiple memory blocks of the same capacity. When the first application applies for memory, the memory management module will determine the memory area of ​​the corresponding capacity interval according to the memory capacity required to be applied, and then further select the memory block in the idle state from the memory area and return the memory address.

[0209] In this process, firstly, multiple memory areas are allocated according to the first configuration information, and the first configuration information is determined according to the memory usage information of the first application during actual operation, so that the allocated multiple memory areas and the memory blocks therein can meet the memory demand of the first application during operation. In general, when the first application wants to apply for a memory block with a memory capacity less than a preset threshold, it will not find a suitable memory block in multiple memory areas.

[0210] Then, since the memory blocks in the memory area are of the same size and are arranged in a regular pattern, combined with some specific algorithms, such as the above-mentioned memory block determination method, the memory block application and release process can be completed with a time complexity of O(1). This can ensure high efficiency of the processing process when facing the high frequency of memory application and release in wearable devices. In this way, the application in the wearable device will not become slow or stuck due to the long memory application and release process, which can significantly improve the user experience.

[0211] Based on the above embodiments, Figure 20 to Figure 23 Another memory management method provided in an embodiment of the present application is described in detail. Fig. 20 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 3 , Fig.21 A schematic diagram of a memory log of an application running process provided in an embodiment of the present application, Fig. 22 A schematic diagram of implementing the peak memory usage statistics during the application running process provided in the embodiment of the present application, Fig.23 A schematic diagram of a curve showing memory usage changing over time during the running of an application provided in an embodiment of the present application.

[0212] In the above-mentioned embodiments, it is mainly explained how to construct multiple memory areas and the process of processing the memory application or memory release request of the first application. In the embodiments of the present application, the process of obtaining the first configuration information will be explained in detail. The memory management method provided in the embodiments of the present application can be used as a part or supplement of the above-mentioned embodiments, or it can be executed separately.

[0213] refer to Fig. 20Steps in the process:

[0214] S2001. Obtain memory usage information of a first application during its operation.

[0215] During the running process of the first application, memory requests and memory releases will be performed repeatedly. Such related information may be referred to as memory usage information. The memory usage information may be recorded in a log file in some form.

[0216] like Fig.21 As shown, a log file of memory usage information is displayed. In this log file, there are multiple fields, including timestamp, instruction type, parameter 1 and parameter 2, etc. Each record in the log corresponds to a memory request or memory release behavior of the first application. Among them, the timestamp indicates the time when the behavior occurred, accurate to milliseconds, and the instruction type can also be called the request type, indicating whether the behavior belongs to memory request or memory release. Parameter 1 and parameter 2 can be further used to describe the relevant information of memory request or memory release. In Fig.21 In the command, parameter 1 can be used to indicate the size of the memory capacity applied or released at the time, and parameter 2 can indicate the address information of the memory block applied or released at the time. For example, according to a record in the log file, it can be known that it occurred at 08:12:04.050, the instruction type was memory application, the size of the memory applied was 7B, and the memory block address finally returned was address a.

[0217] It should be noted that Fig.21 The log file shown for representing memory usage information is only for example and reference, and is not limited to these fields and corresponding formats. For example, the timestamp can be in other formats, and in some implementations, the timestamp may not be included. It only needs to be recorded in chronological order to clearly define the sequence of each memory application or release behavior. In addition, the address information of parameter 2 may also be considered to be omitted, and is not necessarily required. In short, it is understandable that the memory usage information during the operation of the first application can be recorded in some form for subsequent production of the first configuration information.

[0218] Furthermore, the log file recording the memory usage information of the first application can start recording from the time the first application is started once until the first application is closed. Then, when the first application is started again, the memory management method described in the above embodiment can be executed.

[0219] In some implementations, the memory usage information of the application can be obtained by the relevant R&D personnel of the wearable device, and due to the professionalism of the R&D personnel, the log file can be recorded only once. That is, the R&D personnel record the memory usage of multiple applications in advance, and there is no need to record it again when the user actually uses it.

[0220] In some implementations, when a user actually uses an application, the memory usage information of the application is recorded. Considering that different users may have different habits, it is possible to record the user's multiple uses and combine them as the user's application memory usage. For example, when a user uses an application once, he may close it shortly after opening it. If only the memory usage information of a single use is used, there may be deviations.

[0221] In other implementations, the memory usage information of the application may be re-recorded regularly or irregularly, and updated accordingly. For example, the memory usage information of an application may be re-recorded every month. Alternatively, the memory usage information may be re-recorded the next time the application is used after being updated. In this way, the memory usage information of the application may be kept updated for a long time, and better adapted to specific applications and users.

[0222] S2002: for any first interval among the preset multiple intervals, determine the occupancy quantities corresponding to the multiple moments in the running process based on the memory usage information.

[0223] After obtaining the memory usage information of the application, you can divide it into multiple intervals based on the memory usage information. The intervals are intervals of memory capacity. For example, 0B-8B, 8B-16B, 16B-32B, etc. The number of intervals and the specific interval range can be determined based on the actual memory usage information, and can also be determined based on the hardware conditions of the wearable device. For example, considering that the memory space of the wearable device is small, and high-frequency memory application or release behavior is usually concentrated in small memory blocks, a maximum capacity threshold can be pre-defined, such as 1024B, and the range of the interval cannot exceed the capacity threshold.

[0224] After determining multiple intervals, it is necessary to combine the memory usage information to separately count the information of each interval. For example, for the 8B-16B interval, the records of the memory usage information, where the memory block capacity corresponding to the memory application or memory release belongs to the interval range, can be separated, and then the number of memory blocks occupied by the application in the 8B-16B interval range at each moment, or each memory application or memory release behavior, can be counted.

[0225] For ease of understanding, here we combine Fig. 22To illustrate. Fig. 22 As shown, this is the table corresponding to the first interval, for example, the first interval is 8B-16B. The table contains multiple fields, namely, timing, timestamp, instruction type, cumulative application, cumulative release, and current occupation. Among them, timing, timestamp and instruction type can refer to the previous Fig.21 The meanings of the related memory are basically the same, so I will not go into details here. The meaning of the cumulative application field is how many times the memory has been applied for in each timing in the interval of 8B-16B as the application runs. Similarly, the meaning of the cumulative release field is how many times the memory has been released in each timing in the interval of 8B-16B as the application runs. The meaning of the currently occupied field is how many memory blocks are occupied by the application at each timing in the interval of 8B-16B. For the calculation of the currently occupied column, you can start from the first row and perform the calculation step by step, adding one when applying for memory and subtracting one when releasing memory. You can also get it directly by subtracting the value of the cumulative release column from the value of the cumulative application column.

[0226] S2003. Determine the maximum value among the occupancy quantities corresponding to the multiple moments to obtain the target quantity corresponding to the first interval.

[0227] from Fig. 22 As you can see, the values ​​of the cumulative applications and cumulative release columns gradually increase as the application runs, while the value of the current usage column fluctuates. Fig. 22 In the row corresponding to sequence 11, that is, when the timestamp is 08:12:10.510, the instruction type is application, the cumulative number of applications is 8, and the cumulative number of releases is 3, the current maximum value of 5 appears, which can also be called the peak value of the number of memory blocks occupied.

[0228] The peak value is used as the target number of the first interval, which means that during the running of the first application, the memory is continuously requested and released, and the maximum number of memory blocks in the first interval are occupied. The target number can be used to instruct the memory management module how to allocate the memory area and the memory blocks therein for the first application.

[0229] In order to show the relevant content more intuitively, refer to the curve Fig.23 .like Fig.23 As shown, the horizontal axis of the coordinate axis is time, which can be understood as the time the application runs after it is started. The vertical axis of the coordinate axis is the number of memory blocks used, that is, the number of memory blocks occupied by the first application at each time in the first interval, and the peak value of the highest point of the entire curve is taken as the target number.

[0230] S2004. For any first interval among the multiple intervals, determine a preset capacity corresponding to the first interval.

[0231] In the embodiment of the present application, the preset capacity of each memory area corresponds to the range of the memory capacity. For example, if the range of a memory capacity range is 0B-8B, then the corresponding preset capacity is 8B, and so on, if the range of the memory capacity range is 8B-16B, then the corresponding preset capacity is 16B.

[0232] S2005. Determine that the number of memory blocks associated with the preset capacity corresponding to the first interval is equal to the target number corresponding to the first interval, so as to generate first configuration information.

[0233] After the above process steps, a configuration information corresponding to the first interval can be finally obtained, which can be called the first configuration information. The first configuration information includes which memory areas of preset capacity need to be allocated when the first application is started, and how many memory blocks need to be set in each memory area. Since the first configuration information is obtained based on the memory usage information of the actual operation of the first application, it includes the peak value of the number of memory blocks occupied within each memory capacity interval. Therefore, allocating multiple memory areas to the first application according to the first configuration information can meet the memory usage requirements of the first application during normal operation.

[0234] In some implementations, considering that some applications have different frequencies of memory application or memory release in different stages during the process of running after startup, the first configuration information can also be adjusted and improved. For example, some applications may only have a large number of small memory blocks applied and released for a period of time after the application is just started, and in the subsequent continuous operation, the memory application and release at the peak will no longer appear, and the overall trend is stable. Then, the first configuration information can be divided into multiple stages in combination with the actual memory usage information of the application, and different numbers of memory blocks can be set in different stages. For example, for some applications, the peak value of the number of occupied memory blocks can be used as the number of memory blocks in the memory area within a period of time after the application is just started. After a period of time, the number of memory blocks in the memory area can be reduced in some way. In this way, on the one hand, the memory usage requirements of the application can be met, and the efficiency problems caused by the application and release of a large number of small memory blocks in a short period of time can be solved. On the other hand, valuable memory resources in wearable devices can be further saved.

[0235] After the first configuration information is generated, it can be stored in the data space of the wearable device in a certain manner. For more information, please refer to the above embodiment. Fig.15 The S1501 will not be described in detail here.

[0236] The following is a summary based on the above description: The embodiment of the present application describes how to generate first configuration information that provides instructions for applying for and allocating multiple memory areas for a memory management module. After the first application is started once, its memory usage information is recorded. Then, multiple memory capacity intervals are divided, and for each interval, statistics are performed in combination with the memory usage information to obtain the number of memory blocks occupied by the first application at each moment in the interval. Finally, the maximum value of the number of memory blocks occupied at each moment corresponding to each interval is taken as the target number, which is included in the first configuration information to indicate the number of memory blocks in each memory area.

[0237] The first configuration information obtained in this way can accurately reflect the limit of the first application's memory usage requirements during operation. According to the first configuration information, the corresponding memory area and memory block are allocated to the first application, so that when the first application needs to apply for a smaller memory block, it can always find a suitable free memory block from multiple memory areas and return the memory address. It can also greatly improve the number of hits and the hit rate of memory applications. The meaning of hit here means that the request release of a certain memory application of the first application can return the memory block address from the multiple memory areas allocated according to the first configuration information. For example, assuming that 95 of the 100 memory application requests of the first application can be allocated to memory blocks from the above-mentioned multiple memory areas, then it can be said that the number of hits is 95 times and the hit rate is 95%.

[0238] It is understandable that the increase in the number of hits and the hit rate means that more memory application and memory release processes use the memory management method provided by the embodiment of the present application. Since the execution efficiency of the memory management method provided by the embodiment of the present application is very high, the time spent on memory application and memory release can be significantly shortened as a whole, thereby enhancing the operating performance of the first application.

[0239] Next, based on the above-mentioned embodiments, Fig.24 Another memory management method provided in an embodiment of the present application is described in detail. Fig.24 Schematic diagram of the memory management method provided in the embodiment of the present application Figure 4 .

[0240] In the embodiments of the present application, the provided memory management method will be described from an overall perspective, and the application for memory and the release of memory will be described separately.

[0241] First reference Fig.24 The content shown in (a) shows the steps of applying for memory:

[0242] S2401. Apply for memory.

[0243] This step may correspond to the above embodiment. Fig.15 S1503, that is, the memory management module responds to the memory application request of the first application and starts to execute steps related to memory application. For more details, please refer to the above embodiments, which will not be described here.

[0244] S2402: Determine whether the application requirements are met. If yes, execute S2403; otherwise, execute S2405.

[0245] In this step, after receiving the request for memory from the first application, the memory management module will determine whether it can return the address information of the appropriate memory block to the first application based on the memory capacity information contained in the request and the current status of multiple memory areas.

[0246] In some implementations, the memory capacity included in the memory application request may be compared with the preset memory area, that is, the maximum object capacity that can be accommodated. If the requested memory capacity is greater than the preset capacity, it means that this memory application is a large memory application, and S2405 is executed.

[0247] Further, assuming that the requested memory capacity is less than or equal to the preset capacity, the corresponding memory area is determined according to the applied memory capacity, and the applied memory capacity is within the interval range of the memory area. Then, it is determined whether there are any free memory blocks in the memory area. If there are no free memory blocks at this time, that is, they are all occupied, then it is also possible to jump and execute S2405, otherwise execute S2403.

[0248] S2403. Select a memory block.

[0249] After determining that a memory block can be selected from the memory area, the memory block can be determined in the manner described in the previous embodiment. For related content, please refer to Fig.15 The contents of the corresponding parts of S1504 and S1505 will not be repeated here.

[0250] S2404. Return the memory address.

[0251] If the memory management module allocates a memory block to the first application, after selecting a free memory block in the memory area, the corresponding address information can be returned to the first application. Or if it is processed by the operating system, the operating system returns the address information of the memory block to the first application. For related content, please refer to the previous embodiment. Fig.12 The S1203 and related technologies will not be described in detail here.

[0252] S2405: Operating system performs processing.

[0253] When the memory management module determines that the memory capacity requirement in the memory application request is not met in multiple memory areas, the request will be transferred to the operating system of the wearable device for processing.

[0254] It should be noted that the memory management method proposed in the embodiment of the present application can also be regarded as a memory management method based on the operating system of the wearable device. When the first application is started, the memory management module will first apply for a memory space of corresponding memory capacity from the operating system of the wearable device according to the first configuration information. The memory capacity of the memory space can at least accommodate the above-mentioned multiple memory areas and multiple memory blocks therein, and may also include other information for maintaining memory areas and memory blocks. The memory management module can apply for memory from the operating system multiple times or once according to the situation. After the operating system allocates multiple memory areas corresponding to the first application to the memory management module, this part of the memory space can be regarded as occupied by the memory management module for operation and processing by the memory management module, and the rest of the memory space on the wearable device is still managed by the operating system.

[0255] In some implementations, the operating system of the wearable device can adopt, or partially adopt the Best Fit or similar memory management method introduced above. In other words, the memory management method of the operating system can serve as a backup or guarantee for the memory management method provided in the embodiment of the present application. When faced with a request for a memory application with a large memory capacity, since it exceeds the preset threshold, it can be allocated by the operating system. Such memory application requests are generally not too frequent, so they will not bring too much performance bottleneck. Or in some extreme cases, during the subsequent use of the application, the frequency of memory applications in a short period of time becomes higher, exceeding the number in the first configuration information. At this time, the operating system can also process the excess memory application without affecting the normal operation of the application.

[0256] Correspondingly, refer to the following Fig.24 The content shown in (b) in the figure shows the steps of releasing memory:

[0257] S2406. Release memory.

[0258] This step can refer to the previous embodiment Fig.15 The relevant contents of S1506 will not be repeated here.

[0259] S2407. Determine whether it falls within the management scope.

[0260] It is understandable that during the operation of the first application, for example, when a function is completed, some of its related memory will be released. In the request for memory release, the relevant information of the released memory block will be protected, for example, the address information of the memory block can be protected. The memory management module responds to the request for memory release, obtains the address information of the memory block therein, and can determine whether its address segment belongs to a memory block in the allocated multiple memory areas. Assuming that the memory block belongs to the multiple memory areas allocated by the memory management module, execute S2408, otherwise it means that the memory block is allocated by the operating system and should be processed by the operating system, and then execute S2410.

[0261] S2408. Execute release processing.

[0262] In this step, after determining that the first application belongs to the management scope of the memory management module, the corresponding memory block is released. The specific process can be referred to in the above embodiment. Fig.15 The contents related to S1506 will not be repeated here.

[0263] S2409, release completed.

[0264] Finally, the release process of the memory block returned by the first application is completed. If the memory block belongs to the memory space managed by the memory management module, it will continue to be maintained. If the memory block was originally allocated to the first application by the operating system, it will follow the processing of the operating system of the wearable device.

[0265] S2410, operating system performs processing.

[0266] Similar to S2405 above, assuming that the operating system of the wearable device adopts the Best Fit memory management method, when releasing memory, the linked list can be adjusted according to the actual situation, including adding new nodes to the linked list or modifying existing node information. For the corresponding content, please refer to the relevant technology, which will not be repeated here.

[0267] Here is a summary of the above content: In the embodiment of the present application, the processes of memory application and memory release of the first application are described from an overall perspective. In the process of memory application, the memory management module will first determine whether the requirements of the memory application can be met, and if it cannot be met, it will be handed over to the operating system for processing. Similarly, in the process of memory release, the memory management module will first determine whether the released memory block belongs to one of the multiple memory areas allocated for the first application. If it does not belong, it will also be transferred to the operating system for processing. It can be understood that for a large number of memory applications or releases in a short period of time, most of them belong to small memory capacity, so most of them are processed by the memory management module, that is, a hit is achieved. The remaining small part of memory application and memory release is processed by the operating system. Since the frequency of this part is low, it will not form an obvious performance bottleneck. In this way, the memory management method proposed in the embodiment of the present application is combined with the operating system of the wearable device itself, so that the whole set of methods is more complete, which is sufficient to handle various memory applications or release requests of the application during operation.

[0268] It should be noted that the module names involved in the embodiments of the present application can be defined as other names as long as the functions of each module can be achieved, and there is no specific restriction on the names of the modules.

[0269] The memory management method of the embodiment of the present application has been described above, and the device for executing the above method provided by the embodiment of the present application is described below. Those skilled in the art can understand that the method and the device can be combined and referenced with each other, and the relevant device provided by the embodiment of the present application can execute the steps in the above memory management method.

[0270] The memory management method provided in the embodiment of the present application can be applied to electronic devices with information processing functions. The electronic devices include wearable devices, and the specific device form of the wearable devices can refer to the above related descriptions, which will not be repeated here.

[0271] In one implementation, an embodiment of the present application provides an electronic device, Fig.25 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.

[0272] like Fig.25 As shown, the electronic device 2500 includes: a processor 2501 and a memory 2502; the memory 2502 stores computer-executable instructions; the processor 2501 executes the computer-executable instructions stored in the memory 2502, so that the electronic device 2500 executes the above method.

[0273] When the memory 2502 is independently provided, the electronic device further includes a bus 2503 for connecting the memory 2502 and the processor 2501 .

[0274] The embodiment of the present application provides a chip. The chip includes a processor, and the processor is used to call a computer program in a memory to execute the technical solution in the above embodiment. Its implementation principle and technical effect are similar to those of the above related embodiments, and will not be repeated here.

[0275] The embodiments of the present application also provide a computer-readable storage medium. The computer-readable storage medium stores a computer program. The above method is implemented when the computer program is executed by the processor. The method described in the above embodiment can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. If implemented in software, the function can be stored as one or more instructions or codes on a computer-readable medium or transmitted on a computer-readable medium. Computer-readable media can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium that can be accessed by a computer.

[0276] In one possible implementation, a computer-readable medium may include RAM, ROM, compact disc read-only memory (CD-ROM) or other optical disk storage, disk storage or other magnetic storage devices, or any other medium that is intended to carry or store the required program code in the form of instructions or data structures and can be accessed by a computer. Moreover, any connection is appropriately referred to as a computer-readable medium. For example, if a coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL) or wireless technology (such as infrared, radio and microwave) is used to transmit software from a website, server or other remote source, the coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology such as infrared, radio and microwave are included in the definition of medium. Disks and optical disks as used herein include optical disks, laser disks, optical disks, digital versatile disks (DVD), floppy disks and Blu-ray disks, where disks usually reproduce data magnetically, while optical disks reproduce data optically using lasers. Combinations of the above should also be included in the scope of computer-readable media.

[0277] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed, the computer executes the above method.

[0278] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable device to generate a machine, so that the instructions executed by the processing unit of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0279] The above specific implementation methods further illustrate the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific implementation methods of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the present invention should be included in the scope of protection of the present invention.

Claims

1. A memory management method, characterized in that: Applied to a wearable device, the method includes: In response to starting a first application, allocating a plurality of memory areas each corresponding to a preset capacity to the first application, wherein the memory area includes a plurality of memory blocks with the same capacity, and the capacity of the memory blocks in the memory area is equal to the preset capacity; In response to a first request of the first application, determining a first memory area among the multiple memory areas, and determining a first memory block among the multiple memory blocks of the first memory area; Returning address information of the first memory block to the first application to allocate the first memory block to the first application.

2. The method according to claim 1, characterized in that In response to starting the first application, allocating a plurality of memory areas corresponding to respective preset capacities to the first application includes: In response to starting a first application, obtaining first configuration information corresponding to the first application, the first configuration information including allocation quantities associated with each of the plurality of preset capacities; According to the first configuration information corresponding to the first application, memory areas corresponding to the plurality of preset capacities are allocated to the first application, and the number of memory blocks included in the memory area corresponding to any one of the preset capacities is equal to the allocated number.

3. The method according to claim 2, characterized in that The method further comprises: generating the first configuration information according to memory usage information of the first application during operation; The memory usage information includes multiple memory application information and multiple memory release information. The memory application information includes the capacity of the memory block applied for by the first application and the time of application. The memory release information includes the capacity of the memory block released by the first application and the time of release.

4. The method according to claim 3, characterized in that The generating the first configuration information according to the memory usage information of the first application during operation includes: For any first interval among a plurality of preset intervals, determining, based on memory usage information of the first application during operation, the amount of memory occupied by the first application at each of multiple moments in the operation, where the amount of memory occupied is the number of memory blocks whose capacity falls within the first interval and is occupied by the first application; Determining a maximum value among the occupancy counts corresponding to the multiple moments to obtain a target count corresponding to the first interval; The first configuration information is generated according to the target quantities corresponding to each of the multiple intervals.

5. The method according to claim 4, characterized in that The generating the first configuration information according to the target quantities corresponding to the plurality of intervals includes: For any first interval among the multiple intervals, determining the preset capacity corresponding to the first interval, wherein the maximum value of the first interval is equal to the preset capacity; Determine that the number of memory blocks associated with the preset capacity corresponding to the first interval is equal to the target number corresponding to the first interval, so as to generate the first configuration information.

6. The method according to any one of claims 1 to 5, characterized in that The step of determining a first memory area from among the plurality of memory areas in response to the first request of the first application includes: In response to a first request of the first application, obtaining a first requested capacity included in the first request; When the first application capacity is less than or equal to a preset threshold, a first memory area is determined among the multiple memory areas, wherein the first memory area is the memory area among the multiple memory areas, wherein the difference between the corresponding preset capacity and the first application capacity is the smallest.

7. The method according to claim 6, characterized in that Determining a first memory block from a plurality of memory blocks in the first memory area includes: Among the multiple memory blocks in the first memory area, a memory block in an idle state is determined to be the first memory block.

8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: In response to a second request of the first application, the first memory block is marked as being in an idle state, wherein the first memory block marked as being in an idle state belongs to the first memory area.

9. The method according to any one of claims 1 to 8, characterized in that The method further comprises: In response to closing the first application, the memory area allocated to the first application is released.

10. An electronic device, characterized in that: The electronic device includes: one or more processors and memory; The memory is coupled to the one or more processors, and the memory is used to store computer program code, where the computer program code includes computer instructions. The one or more processors call the computer instructions to enable the electronic device to execute the method according to any one of claims 1 to 9.

11. A chip system, characterized in that: The chip system is applied to an electronic device, and the chip system includes one or more processors, and the one or more processors are used to call computer instructions so that the electronic device executes the method as described in any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that The computer-readable storage medium comprises computer instructions, and when the computer instructions are executed on an electronic device, the electronic device is caused to perform the method according to any one of claims 1 to 9.

13. A computer program product, characterized in that The computer program product comprises a computer program code, and when the computer program code is run on an electronic device, the electronic device is caused to perform the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Quick-speed application EMS memory method

    CN101140531A

  • Configuration method and device for built-in system memory pool

    CN101937398A

  • Real-time event management method for intelligent electronic equipment

    CN101944119A

  • Method and device for managing small pieces of memories

    CN106201910A

  • Small object memory management method and device, electronic equipment and computer readable medium

    CN110780823A

Cited By

  • Memory management method and device, equipment and medium

    CN120973506A

  • Memory management method, apparatus, device, and medium

    CN120973506B

  • Memory management method and device and storage medium

    CN121455675A