WO2022120522A1 - Memory space allocation method and device, and storage medium - Google Patents

Memory space allocation method and device, and storage medium Download PDF

Info

Publication number
WO2022120522A1
WO2022120522A1 PCT/CN2020/134258 CN2020134258W WO2022120522A1 WO 2022120522 A1 WO2022120522 A1 WO 2022120522A1 CN 2020134258 W CN2020134258 W CN 2020134258W WO 2022120522 A1 WO2022120522 A1 WO 2022120522A1
Authority
WO
WIPO (PCT)
Prior art keywords
subspace
memory
memory space
target
space
Prior art date
Application number
PCT/CN2020/134258
Other languages
French (fr)
Chinese (zh)
Inventor
沈桂旭
刘延昭
董岚
Original Assignee
深圳市大疆创新科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市大疆创新科技有限公司 filed Critical 深圳市大疆创新科技有限公司
Priority to CN202080067360.7A priority Critical patent/CN114556309A/en
Priority to PCT/CN2020/134258 priority patent/WO2022120522A1/en
Publication of WO2022120522A1 publication Critical patent/WO2022120522A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Memory System (AREA)

Abstract

A memory space allocation method and device, and a storage medium. The method comprises: acquiring a memory allocation request for discrete memory spaces; determining at least one target memory space, corresponding to the memory allocation request, among the discrete memory spaces, wherein the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are mutually exclusive; and according to the memory allocation request, determining at least one target subspace at a lower layer of each target memory space in the at least one target memory space, wherein the target subspace is in an unallocated state, and any two subspaces in the at least one target subspace are mutually exclusive. According to the technical solution provided by the present embodiment, flexible memory allocation can be effectively performed on discrete memory spaces, the obtained target memory spaces are mutually exclusive, and the obtained target subspaces are also mutually exclusive, so that the size of the space occupied by data resources is effectively reduced, and the improvement of the memory allocation efficiency is facilitated.

Description

内存空间的分配方法、装置及存储介质Memory space allocation method, device and storage medium 技术领域technical field
本发明实施例涉及内存分配技术领域,尤其涉及一种内存空间的分配方法、装置及存储介质。Embodiments of the present invention relate to the technical field of memory allocation, and in particular, to a memory space allocation method, device, and storage medium.
背景技术Background technique
现有技术中,在进行内存分配操作时,可以采用内存链表的方式或者比特位映射关系(Bit map)的方式进行内存分配。其中,在采用内存链表的方式进行内存分配操作时,由于存在内部链表结构,导致待分配的部分内存空间被占用,此外,内部的分配及释放、合并的算法本身也会有一定的运行开销,因此,使得上述内存分配方法无法应用于资源敏感系统上,极大地会影响了内存分配的效率。而Bit map的内存分配方法主要是针对连续空间进行内存分配,无法保证分配后的内存空间之间互斥,此时,在利用上述所分配的内存空间进行数据运算时,容易出现数据运算报错,甚至无法实现正常的数据运算操作。In the prior art, when performing a memory allocation operation, memory allocation may be performed in a memory linked list manner or a bit map manner. Among them, when the memory allocation operation is performed in the form of a memory linked list, due to the existence of an internal linked list structure, part of the memory space to be allocated is occupied. In addition, the internal allocation, release and merging algorithms themselves will also have a certain running overhead. Therefore, the above-mentioned memory allocation method cannot be applied to a resource-sensitive system, which greatly affects the efficiency of memory allocation. The memory allocation method of Bitmap mainly allocates memory for continuous space, and cannot guarantee mutual exclusion between allocated memory spaces. Even normal data operation operations cannot be realized.
发明内容SUMMARY OF THE INVENTION
本发明实施例提供一种内存空间的分配方法、装置及存储介质,可以针对离散内存空间实现内存分配操作,同时支持对多块互斥空间的内存分配操作,资源信息占用小,内存分配效率高,适用于资源敏感平台。The embodiments of the present invention provide a memory space allocation method, device, and storage medium, which can realize memory allocation operations for discrete memory spaces, and support memory allocation operations for multiple mutually exclusive spaces, with small resource information occupation and high memory allocation efficiency. , for resource-sensitive platforms.
本发明实施例的第一方面,提供了一种内存空间的分配方法,包括:A first aspect of the embodiments of the present invention provides a method for allocating memory space, including:
获取针对离散化内存空间的内存分配请求;Get the memory allocation request for the discretized memory space;
在所述离散化内存空间中,确定与所述内存分配请求相对应的至少一个目标内存空间,所述目标内存空间为未分配状态,且所述至少一个目标内存 空间中的任意两个目标内存空间之间互斥;In the discretized memory space, at least one target memory space corresponding to the memory allocation request is determined, the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are in an unallocated state. mutual exclusion between spaces;
根据所述内存分配请求,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所述目标子空间为未分配状态,且所述至少一个目标子空间中的任意两个子空间之间互斥。According to the memory allocation request, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and any target subspace in the at least one target subspace is in an unallocated state. The two subspaces are mutually exclusive.
本发明实施例的第二方面,提供了一种内存空间的分配装置,包括:In a second aspect of the embodiments of the present invention, a device for allocating memory space is provided, including:
存储器,用于存储计算机程序;memory for storing computer programs;
处理器,用于运行所述存储器中存储的计算机程序以实现:A processor for running a computer program stored in the memory to achieve:
获取针对离散化内存空间的内存分配请求;Get the memory allocation request for the discretized memory space;
在所述离散化内存空间中,确定与所述内存分配请求相对应的至少一个目标内存空间,所述目标内存空间为未分配状态,且所述至少一个目标内存空间中的任意两个目标内存空间之间互斥;In the discretized memory space, at least one target memory space corresponding to the memory allocation request is determined, the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are in an unallocated state. mutual exclusion between spaces;
根据所述内存分配请求,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所述目标子空间为未分配状态,且所述至少一个目标子空间中的任意两个子空间之间互斥。According to the memory allocation request, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and any target subspace in the at least one target subspace is in an unallocated state. The two subspaces are mutually exclusive.
本发明实施例的第三方面,提供了一种计算机可读存储介质,所述存储介质为计算机可读存储介质,该计算机可读存储介质中存储有程序指令,所述程序指令用于实现上述第一方面所述的内存空间的分配方法。In a third aspect of the embodiments of the present invention, a computer-readable storage medium is provided, where the storage medium is a computer-readable storage medium, and program instructions are stored in the computer-readable storage medium, and the program instructions are used to implement the above The method for allocating the memory space described in the first aspect.
本发明实施例提供的技术方案,有效地实现了能够灵活地对离散内存空间进行内存分配,具体的,通过获取到针对离散化内存空间的内存分配请求,而后可以基于内存分配请求获得与内存分配请求相对应的目标内存空间和位于目标内存空间下层的目标子空间,所获得的目标内存空间和目标子空间之间互斥,由于不存在内部链表结构,因此有效地降低了数据资源所需要占用的空间大小,有利于提高内存分配效率,从而使得该方法适合于资源敏感系统的内存分配,进一步提高了该方法的实用性和适用范围。The technical solution provided by the embodiments of the present invention effectively realizes that the memory allocation can be flexibly performed on the discrete memory space. Specifically, by obtaining the memory allocation request for the discrete memory space, the memory allocation request can be obtained and allocated based on the memory allocation request. The corresponding target memory space and the target subspace located at the lower level of the target memory space are requested, and the obtained target memory space and the target subspace are mutually exclusive. Since there is no internal linked list structure, the required occupation of data resources is effectively reduced. The size of the space is beneficial to improve the efficiency of memory allocation, so that the method is suitable for memory allocation of resource-sensitive systems, and further improves the practicability and scope of application of the method.
附图说明Description of drawings
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present invention more clearly, the following briefly introduces the accompanying drawings used in the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative labor.
图1为现有技术中提供的一种内存空间的结构示意图;1 is a schematic structural diagram of a memory space provided in the prior art;
图2为现有技术中提供的一种针对连续内存空间进行内存分配时的内存链表示意图;2 is a schematic diagram of a memory linked list when memory allocation is performed for a continuous memory space provided in the prior art;
图3为本发明实施例提供的一种内存空间的分配方法的流程示意图;3 is a schematic flowchart of a method for allocating memory space according to an embodiment of the present invention;
图4为本发明实施例提供的离散化内存空间中包括多个内存空间的示意图;4 is a schematic diagram of a discretized memory space provided by an embodiment of the present invention including multiple memory spaces;
图5为本发明实施例提供的内存空间中包括多个子空间的示意图;5 is a schematic diagram of a memory space including multiple subspaces according to an embodiment of the present invention;
图6为本发明实施例提供的在所述离散化内存空间中,确定与所述内存分配请求相对应的至少一个目标内存空间的流程示意图;6 is a schematic flowchart of determining at least one target memory space corresponding to the memory allocation request in the discretized memory space according to an embodiment of the present invention;
图7为本发明实施例提供的根据所述内存分配请求,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间的流程示意图;7 is a schematic flowchart of determining at least one target subspace below each target memory space in the at least one target memory space according to the memory allocation request according to an embodiment of the present invention;
图8为本发明实施例提供的另一种内存空间的分配方法的流程示意图;8 is a schematic flowchart of another method for allocating memory space provided by an embodiment of the present invention;
图9为本发明实施例提供的根据所述内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息的流程示意图;9 is a schematic flowchart of determining division configuration information for performing a space division operation on a memory space according to the memory allocation request according to an embodiment of the present invention;
图10为本发明实施例提供的又一种内存空间的分配方法的流程示意图;10 is a schematic flowchart of another method for allocating memory space provided by an embodiment of the present invention;
图11为本发明应用实施例提供的一种内存空间的分配方法的流程示意图一;11 is a schematic flowchart 1 of a method for allocating memory space provided by an application embodiment of the present invention;
图12为本发明应用实施例提供的一种内存空间的分配方法的流程示意图二;12 is a second schematic flowchart of a method for allocating memory space provided by an application embodiment of the present invention;
图13为本发明实施例提供的一种内存空间的分配装置的结构示意图。FIG. 13 is a schematic structural diagram of an apparatus for allocating a memory space according to an embodiment of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
除非另有定义,本文所使用的所有的技术和科学术语与属于本发明的技术领域的技术人员通常理解的含义相同。本文中在本发明的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本发明。Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terms used herein in the description of the present invention are for the purpose of describing specific embodiments only, and are not intended to limit the present invention.
在通篇说明书及权利要求当中所提及的“包括”为一开放式用语,故应解释成“包括但不限定于”。“大致”是指在可接收的误差范围内,本领域技术人员能够在一定误差范围内解决所述技术问题,基本达到所述技术效果。The "including" mentioned throughout the specification and claims is an open-ended term, so it should be interpreted as "including but not limited to". "Approximately" means that within an acceptable error range, those skilled in the art can solve the technical problem within a certain error range, and basically achieve the technical effect.
此外,“连接”一词在此包含任何直接及间接的连接手段。因此,若文中描述一第一装置连接于一第二装置,则代表所述第一装置可直接连接于所述第二装置,或通过其它装置间接地连接至所述第二装置。Furthermore, the term "connected" herein includes any direct and indirect means of connection. Therefore, if it is described herein that a first device is connected to a second device, it means that the first device can be directly connected to the second device or indirectly connected to the second device through another device.
应当理解,本文中使用的术语“及/或、和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。It should be understood that the term "and/or, and/or" used herein is only an association relationship for describing associated objects, indicating that three kinds of relationships may exist. In addition, the character "/" in this document generally indicates that the related objects are an "or" relationship.
为了便于理解本申请的技术方案,下面对现有技术进行简要说明:In order to facilitate the understanding of the technical solutions of the present application, the prior art is briefly described below:
在计算机系统中,常见的内存空间包括:代码区、静态区、堆(heap)、栈(stack)等,其中,如图1所示,代码区和静态区可以采用静态存储方式,在程序编译时,代码区和静态区可以由系统分配固定的地址和存储空间,在程序运行过程中,代码区和静态区中数据存储的地址和存储空间保持不变。堆和栈可以采用动态存储方式,在程序运行的过程中,可以动态地对内存空间进行分配与释放。栈区由编译器自动进行分配和释放,主要用于存放临时变量和局部变量,堆区则一般由程序员控制分配与释放,在程序运行中,可以动态地申请指定大小的内存空间或释放空间。In a computer system, common memory spaces include: code area, static area, heap, stack, etc. Among them, as shown in Figure 1, the code area and static area can be stored in a static manner. When the code area and the static area are allocated fixed addresses and storage space by the system, during the running of the program, the address and storage space of the data stored in the code area and the static area remain unchanged. The heap and stack can be stored dynamically, and the memory space can be allocated and released dynamically during the running of the program. The stack area is automatically allocated and released by the compiler. It is mainly used to store temporary variables and local variables. The heap area is generally allocated and released by the programmer. During the program operation, you can dynamically apply for a memory space of a specified size or release space. .
针对连续的内存堆空间,可以采用动态内存分配(memory allocation, 简称malloc)的方法进行内存分配,其具体的实现原理主要是要维护一个内存链表,如图2所示,其中,内存链表中可以包括:元数据区(meta data)和数据区(data),元数据区用于记录数据块的大小、占用状态以及链表指针等信息,data为数据区,用于存储相关数据。当存在内存空间申请时,可以搜索内存链表中空闲的数据区进行分配。For the continuous memory heap space, the dynamic memory allocation (memory allocation, malloc for short) method can be used for memory allocation. The specific implementation principle is to maintain a memory linked list, as shown in Figure 2. Among them, the memory linked list can be Including: metadata area (meta data) and data area (data), the metadata area is used to record the size, occupancy status and linked list pointer and other information of the data block, data is the data area, used to store related data. When there is a memory space application, the free data area in the memory linked list can be searched for allocation.
另一种可以简单实现内存分配的方式为:将内存空间划分为子空间块,而后为每个子空间块提供1bit的标识位,从而可以构成比特位映射关系(bit map),而后可以通过与子空间块相对应的标识位(0、1)来记录整个内存空间的占用情况。如下表1所示,可以将内存空间划分为n个子空间块,若以标识位“0”表示空闲,标识位“1”表示占用,则通过下表1可知,上述内存空间的第4个子空间块和第5个子空间块被占用,此时,则不可对上述被占用的子空间块进行占用,而其他子空间块处于空闲状态,进而可以对其他子空间块可以进行分配。Another way to easily realize memory allocation is to divide the memory space into subspace blocks, and then provide each subspace block with a 1-bit identification bit, so that a bit map can be formed. The identification bits (0, 1) corresponding to the space block are used to record the occupancy of the entire memory space. As shown in Table 1 below, the memory space can be divided into n subspace blocks. If the flag bit "0" indicates idle and the flag bit "1" indicates occupation, it can be seen from Table 1 below that the fourth subspace of the above memory space The block and the fifth subspace block are occupied. At this time, the above occupied subspace block cannot be occupied, and other subspace blocks are in an idle state, so that other subspace blocks can be allocated.
00 00 00 11 11 00 ............ 00
表1Table 1
由上述陈述内容可知,在采用内存链表的方式进行内存分配时,能够满足内存的准确分配。但是,由于存在内部链表结构,导致部分待分配的内存空间被占用,此外,内部的分配及释放、合并的算法本身也会有一定的运行开销,因此,使得上述内存分配方法无法应用于资源敏感系统上,适用性受限。It can be seen from the above statement that when memory is allocated by means of a memory linked list, accurate allocation of memory can be satisfied. However, due to the existence of an internal linked list structure, part of the memory space to be allocated is occupied. In addition, the internal allocation, release, and merging algorithms themselves also have a certain operating overhead. Therefore, the above memory allocation method cannot be applied to resource-sensitive applications. On the system, the applicability is limited.
相比较而言,Bit map的内存分配方法可以在占用资源很小的情况下,高效地实现内存分配操作,然而,Bit map的内存分配方法主要是针对连续空间进行内存分配,无法保证分配后的内存空间之间互斥,此时,在利用上述所分配的内存空间进行数据运算时,容易出现数据运算报错,甚至无法实现正常的数据运算操作。In comparison, Bitmap's memory allocation method can efficiently implement memory allocation operations with a small footprint. However, Bitmap's memory allocation method mainly allocates memory for continuous space, and cannot guarantee the allocated memory. The memory spaces are mutually exclusive. At this time, when using the allocated memory space for data operation, data operation errors are likely to occur, and even normal data operation operations cannot be realized.
另外,随着芯片运算技术的飞速发展,向量运算的能力也不断提升,越 来越多出现与之相对应的向量存储空间。向量存储空间具有如下特点:由多个独立空间块(block)组成,每个block的内部地址连续,任意两个block之间的地址离散。向量运算中的各个操作数来自不同block,由此产生了一种新的地址空间分配需求是:同时分配多块block级互斥空间。In addition, with the rapid development of chip computing technology, the ability of vector computing has also been continuously improved, and more and more vector storage spaces corresponding to it have appeared. The vector storage space has the following characteristics: it consists of multiple independent space blocks (blocks), the internal addresses of each block are continuous, and the addresses between any two blocks are discrete. Each operand in the vector operation comes from different blocks, resulting in a new address space allocation requirement: allocate multiple blocks of block-level mutual exclusion space at the same time.
因此,为了能够实现灵巧地对离散内存空间进行内存分配,同时支持对多块互斥空间的内存分配操作,资源信息占用小,内存分配效率高,适适用于资源敏感系统。本实施例提供了一种内存空间的分配方法、装置及存储介质,其中,分配方法通过获取针对离散化内存空间的内存分配请求,而后可以基于内存分配请求在离散化内存空间中确定至少一个未分配的目标内存空间,并且,至少一个目标内存空间中任意两个目标内存空间之间互斥,在确定至少一个目标内存空间之后,由于目标内存空间可以包括至少一个子空间,在获取到内存分配请求之后,则可以基于内存分配请求来确定位于每个目标内存空间下层的至少一个未分配的目标子空间,并且所获得的任意两个子空间之间互斥。Therefore, in order to dexterously allocate memory to discrete memory spaces and support memory allocation operations for multiple mutually exclusive spaces, the resource information occupies less space, and the memory allocation efficiency is high, which is suitable for resource-sensitive systems. The present embodiment provides a memory space allocation method, device, and storage medium, wherein the allocation method obtains a memory allocation request for the discretized memory space, and then determines at least one unidentified memory space in the discretized memory space based on the memory allocation request. The allocated target memory space, and any two target memory spaces in at least one target memory space are mutually exclusive. After at least one target memory space is determined, since the target memory space can include at least one subspace, after the memory allocation is obtained After the request, at least one unallocated target subspace located under each target memory space may be determined based on the memory allocation request, and any two obtained subspaces are mutually exclusive.
本实施例提供的上述技术方案,有效地实现了能够灵活地对离散内存空间进行内存分配,适用于获得与内存分配请求相对应的目标内存空间和位于目标内存空间下层的目标子空间,所获得的目标内存空间和目标子空间之间互斥,由于不存在需要占用内存空间的内部链表结构,因此有效地降低了数据资源所需要占用的空间大小,有利于提高内存分配效率,从而使得该方法适合于资源敏感系统的内存分配,进一步提高了该方法的实用性和适用范围。The above technical solution provided in this embodiment effectively realizes that memory allocation can be performed on discrete memory spaces flexibly, and is suitable for obtaining the target memory space corresponding to the memory allocation request and the target subspace located at the lower level of the target memory space. The target memory space and the target subspace are mutually exclusive. Since there is no internal linked list structure that needs to occupy the memory space, the size of the space occupied by the data resources is effectively reduced, which is beneficial to improve the efficiency of memory allocation, so that the method The memory allocation suitable for resource-sensitive systems further improves the practicability and scope of the method.
下面结合附图,对本发明的一些实施方式作详细说明。在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。Some embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Those skilled in the art may combine and combine the different embodiments or examples described in this specification, as well as the features of the different embodiments or examples, without conflicting each other.
图3为本发明实施例提供的一种内存空间的分配方法的流程示意图;参考附图3所示,本实施例提供了一种内存空间的分配方法,该方法的执行 主体可以为内存空间的分配装置,可以理解的是,该内存空间的分配装置可以实现为软件、或者软件和硬件的组合,具体的,该方法可以包括:FIG. 3 is a schematic flowchart of a method for allocating memory space provided by an embodiment of the present invention; with reference to FIG. 3 , this embodiment provides a method for allocating memory space, and the execution body of the method may be a memory space allocation method. It can be understood that the allocation device for the memory space can be implemented as software or a combination of software and hardware. Specifically, the method can include:
步骤S301:获取针对离散化内存空间的内存分配请求。Step S301: Obtain a memory allocation request for the discretized memory space.
步骤S302:在离散化内存空间中,确定与内存分配请求相对应的至少一个目标内存空间,目标内存空间为未分配状态,且至少一个目标内存空间中的任意两个目标内存空间之间互斥。Step S302: In the discretized memory space, determine at least one target memory space corresponding to the memory allocation request, the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are mutually exclusive .
步骤S303:根据内存分配请求,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,目标子空间为未分配状态,且至少一个目标子空间中的任意两个子空间之间互斥。Step S303: According to the memory allocation request, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and there is a gap between any two subspaces in the at least one target subspace. mutually exclusive.
下面对上述各个步骤的具体实现方式和实现效果进行详细说明:The specific implementation methods and implementation effects of the above-mentioned steps are described in detail below:
步骤S301:获取针对离散化内存空间的内存分配请求。Step S301: Obtain a memory allocation request for the discretized memory space.
其中,离散化内存空间可以包括多个独立空间块(block),如图4所示,多个独立空间块可以包括:block0、block1、block2......blockN,而上述每个block的内部地址连续,任意两个block之间的地址离散。The discretized memory space may include multiple independent space blocks (blocks), as shown in FIG. 4 , the multiple independent space blocks may include: block0, block1, block2...blockN, and the above-mentioned blocks of each block The internal addresses are continuous, and the addresses between any two blocks are discrete.
当用户针对离散化内存空间存在内存分配需求时,则可以生成内存分配请求,可以理解的是,上述内存分配请求可以在用于实现内存空间分配操作的分配装置中生成,或者,上述的内存分配请求可以在第三设备中生成,其中,第三设备与分配装置通信连接,分配装置通过第三装置即可获取到针对离散化内存空间的内存分配请求。具体的,一种针对内存分配请求的获取方式可以为:用户可以对分配装置输入执行操作,以根据执行操作生成内存分配请求;或者,另一种针对内存分配请求的获取方式可以为:用户可以对第三设备输入执行操作,从而使得第三设备可以生成内存分配请求,而后将内存分配请求发送至分配装置,从而使得分配装置可以准确地获取到内存分配请求。When the user has a memory allocation requirement for the discretized memory space, a memory allocation request can be generated. It can be understood that the above-mentioned memory allocation request can be generated in an allocation device for implementing a memory space allocation operation, or, the above-mentioned memory allocation The request may be generated in a third device, wherein the third device is connected in communication with the allocation device, and the allocation device can obtain the memory allocation request for the discretized memory space through the third device. Specifically, an acquisition method for a memory allocation request may be: a user may input an operation to the allocation device to generate a memory allocation request according to the execution operation; or, another acquisition method for a memory allocation request may be: the user may An operation is performed on the input of the third device, so that the third device can generate a memory allocation request, and then send the memory allocation request to the allocation device, so that the allocation device can accurately obtain the memory allocation request.
当然的,本领域技术人员也可以采用其他的方式来获得内存分配请求,只要能够保证对内存分配请求进行获取的准确可靠性即可,在此不再赘述。Of course, those skilled in the art can also obtain the memory allocation request in other ways, as long as the accuracy and reliability of the memory allocation request can be ensured, which will not be repeated here.
需要注意的是,离散化内存空间中所包括的空间块可以对应有不同的内存分配状态,内存分配状态可以包括:用于标识空间块处于未被分配的空闲状态和用于标识空间块处于已被分配的占用状态。而上述所获得的内存分配请求用于在离散化内存空间中确定满足需求的处于空闲状态的空间块,以便针对所分配的空间块进行相对应的数据处理操作,上述的数据处理操作可以包括:数据写入操作、数据读取操作、数据删除操作等等。It should be noted that the space blocks included in the discretized memory space may correspond to different memory allocation states, and the memory allocation states may include: used to identify that the space block is in an unallocated idle state and used to identify that the space block is in an already allocated state. The assigned occupancy status. The memory allocation request obtained above is used to determine a space block in an idle state that meets the requirements in the discretized memory space, so that a corresponding data processing operation is performed for the allocated space block. The above data processing operation may include: Data write operations, data read operations, data delete operations, etc.
步骤S302:在离散化内存空间中,确定与内存分配请求相对应的至少一个目标内存空间,目标内存空间为未分配状态,且至少一个目标内存空间中的任意两个目标内存空间之间互斥。Step S302: In the discretized memory space, determine at least one target memory space corresponding to the memory allocation request, the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are mutually exclusive .
其中,在获取到内存分配请求之后,则可以基于内存分配请求对离散化内存空间进行分析处理,以确定与内存分配请求相对应的至少一个目标内存空间。在一些实例中,在所确定的目标内存空间为离散化空间时,至少一个目标内存空间中每个目标内存空间中的地址信息连续,且至少一个目标内存空间中任意两个目标内存空间之间的地址信息离散;另外,所确定的目标内存空间可以为未分配状态,且至少一个目标内存空间中的任意两个目标内存空间互斥,以通过所确定的未分配的目标内存空间进行相对应的数据运算操作。Wherein, after the memory allocation request is acquired, the discrete memory space may be analyzed and processed based on the memory allocation request to determine at least one target memory space corresponding to the memory allocation request. In some instances, when the determined target memory space is a discretized space, the address information in each target memory space in the at least one target memory space is continuous, and there is a gap between any two target memory spaces in the at least one target memory space. The address information is discrete; in addition, the determined target memory space may be in an unallocated state, and any two target memory spaces in at least one target memory space are mutually exclusive, so as to correspond to the determined unallocated target memory space data manipulation operations.
另外,本实施例对于确定与内存分配请求相对应的至少一个目标内存空间的具体实现方式不做限定,本领域技术人员可以根据具体的应用需求和设计需求进行设置,例如:在确定内存分配请求之后,可以确定与内存分配请求相对应的请求空间大小;而后可以确定离散化内存空间中每个内存空间所对应的分配状态,基于每个内存空间所对应的分配状态,在离散化内存空间中,可以基于内存分配请求来确定满足请求空间大小的、处于未分配状态的内存空间,而后将上述的内存空间确定为与内存分配请求相对应的至少一个目标内存空间,从而有效地实现了对至少一个目标内存空间进行确定的准确可靠性。In addition, this embodiment does not limit the specific implementation of determining at least one target memory space corresponding to the memory allocation request, and those skilled in the art can set according to specific application requirements and design requirements, for example: when determining the memory allocation request After that, the size of the request space corresponding to the memory allocation request can be determined; then the allocation state corresponding to each memory space in the discretized memory space can be determined, and based on the allocation state corresponding to each memory space, in the discretized memory space , the unallocated memory space that satisfies the requested space size can be determined based on the memory allocation request, and then the above-mentioned memory space is determined as at least one target memory space corresponding to the memory allocation request, thereby effectively realizing at least one target memory space. The exact reliability of a target memory space to be determined.
当然的,本领域技术人员也可以采用其他的方式来确定与内存分配请求相对应的至少一个目标内存空间,只要能够保证对与内存分配请求相对应的至少一个目标内存空间进行确定的准确可靠性即可,在此不再赘述。Of course, those skilled in the art can also use other methods to determine the at least one target memory space corresponding to the memory allocation request, as long as the accuracy and reliability of the determination of the at least one target memory space corresponding to the memory allocation request can be guaranteed. That is, it will not be repeated here.
步骤S303:根据内存分配请求,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,目标子空间为未分配状态,且至少一个目标子空间中的任意两个子空间之间互斥。Step S303: According to the memory allocation request, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and there is a gap between any two subspaces in the at least one target subspace. mutually exclusive.
其中,对于目标内存空间而言,每个目标内存空间下层还可以包括一个或多个目标子空间,如图5所示,目标内存空间block0中可以包括多个子空间块,标内存空间block1中也可以包括多个子空间块,目标内存空间blockN中也可以包括多个子空间块。Among them, for the target memory space, the lower layer of each target memory space may also include one or more target subspaces. As shown in Figure 5, the target memory space block0 may include multiple subspace blocks, and the target memory space block1 also includes Multiple subspace blocks may be included, and the target memory space blockN may also include multiple subspace blocks.
此外,上述目标内存空间中所包括的子空间的分配状态可以包括空闲状态和占用状态,为了方便获取并确定子空间的分配状态,针对子空间可以设置有用于标识子空间的分配状态标识,例如,在子空间处于空闲状态时,则可以将子空间的分配状态标识确定为“0”;在子空间处于占用状态时,则可以将子空间的分配状态标识确定为“1”;当然的,本领域技术人员也可以采用其他的分配状态标识来标识子空间的分配状态,在此不再赘述。In addition, the allocation state of the subspace included in the above target memory space may include an idle state and an occupied state. In order to facilitate the acquisition and determination of the allocation state of the subspace, an allocation state identifier for identifying the subspace may be set for the subspace, for example , when the subspace is in an idle state, the allocation status flag of the subspace can be determined to be "0"; when the subspace is in an occupied state, the allocation status flag of the subspace can be determined to be "1"; of course, Those skilled in the art may also use other allocation status identifiers to identify the allocation status of the subspace, which will not be repeated here.
具体实现时,针对不同的内存分配请求可以包括不同的目标内存空间需求,针对不同的目标内存空间需求可以确定不同的目标内存空间,而在不同的目标内存空间中,内存分配请求中还可以有与不同的内存分配请求相对应的不同大小的子空间需求。因此,在获取到内存分配请求之后,则可以基于内存分配请求来确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所确定的至少一个目标子空间可以为未分配状态,且至少一个目标子空间中的任意两个子空间之间互斥,从而有效地保证了对至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间进行确定的准确可靠性。During specific implementation, different target memory space requirements may be included for different memory allocation requests, and different target memory spaces may be determined for different target memory space requirements, and in different target memory spaces, memory allocation requests may also include Different sized subspace requirements corresponding to different memory allocation requests. Therefore, after the memory allocation request is obtained, at least one target subspace below each target memory space in the at least one target memory space may be determined based on the memory allocation request, and the determined at least one target subspace may be in an unallocated state , and any two subspaces in the at least one target subspace are mutually exclusive, thereby effectively ensuring the accuracy and reliability of determining at least one target subspace below each target memory space in the at least one target memory space.
本实施例提供的内存空间的分配方法,通过获取针对离散化内存空间的 内存分配请求,并在离散化内存空间中确定与内存分配请求相对应的至少一个目标内存空间,而后根据内存分配请求来确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,从而有效地实现了能够灵活地对离散内存空间进行内存分配,获得与内存分配请求相对应的目标内存空间和位于目标内存空间下层的目标子空间,所获得的目标内存空间和目标子空间之间互斥,这样有利于降低数据资源所需要占用的空间大小,同时也便于提高内存分配效率,从而使得该方法可以适合于资源和性能敏感系统平台,进一步提高了该方法的实用性和适用范围。In the method for allocating memory space provided by this embodiment, the memory allocation request for the discretized memory space is obtained, and at least one target memory space corresponding to the memory allocation request is determined in the discretized memory space, and then according to the memory allocation request Determine at least one target subspace below each target memory space in at least one target memory space, thereby effectively realizing memory allocation to discrete memory spaces flexibly, and obtaining the target memory space corresponding to the memory allocation request and the target memory space located in the target memory space. The target subspace at the lower level of the memory space is mutually exclusive between the obtained target memory space and the target subspace, which is conducive to reducing the size of the space occupied by data resources and improving the efficiency of memory allocation, so that this method can be suitable for It is suitable for resource- and performance-sensitive system platforms, which further improves the practicability and applicability of the method.
图6为本发明实施例提供的在离散化内存空间中,确定与内存分配请求相对应的至少一个目标内存空间的流程示意图;在上述实施例的基础上,继续参考附图6所示,本实施例对于确定与内存分配请求相对应的至少一个目标内存空间的具体实现方式不做限定,本领域技术人员可以根据具体的应用需求和设计需求进行设置,较为优选的,本实施例中的在离散化内存空间中,确定与内存分配请求相对应的至少一个目标内存空间可以包括:6 is a schematic flowchart of determining at least one target memory space corresponding to a memory allocation request in a discretized memory space according to an embodiment of the present invention; The embodiment does not limit the specific implementation of determining at least one target memory space corresponding to the memory allocation request, and those skilled in the art can set it according to specific application requirements and design requirements. In the discretized memory space, determining at least one target memory space corresponding to the memory allocation request may include:
步骤S601:基于内存分配请求获取内存互斥表,内存互斥表中包括:在离散化内存空间中的待分配内存空间以及待分配内存空间的空间分配状态。Step S601: Obtain a memory mutual exclusion table based on the memory allocation request, where the memory mutual exclusion table includes: the memory space to be allocated in the discretized memory space and the space allocation status of the memory space to be allocated.
步骤S602:在离散化内存空间中,根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间。Step S602: In the discretized memory space, determine at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table.
其中,针对离散化内存空间可以对应有一内存互斥表,该内存互斥表中可以包括在离散化内存空间中的待分配内存空间以及待分配内存空间的空间分配状态。The discretized memory space may correspond to a memory mutual exclusion table, and the memory mutual exclusion table may include the to-be-allocated memory space in the discretized memory space and the space allocation state of the to-be-allocated memory space.
在一些实例中,对于与离散化内存空间相对应的内存互斥表而言,其可以存储在静态区域或者动态区域中,以在获取到内存分配请求之后,通过访问上述的静态区域或者动态区域即可获取到与离散化内存空间相对应的内存互斥表。In some instances, for the memory mutex table corresponding to the discretized memory space, it can be stored in a static area or a dynamic area, so that after the memory allocation request is obtained, by accessing the above-mentioned static area or dynamic area The memory mutex table corresponding to the discretized memory space can be obtained.
在另一些实例中,内存互斥表可以为临时生成的变量信息,在获取到内 存分配请求之后,则可以基于内存分配请求临时生成内存互斥表,以基于所生成的内存互斥表进行相对应的内存分配操作。可以理解的是,在内存分配操作完毕之后,所生成的内存互斥表可以被删除或者丢弃。In other instances, the memory mutex table may be temporarily generated variable information, and after the memory allocation request is obtained, the memory mutex table may be temporarily generated based on the memory allocation request, so as to perform a comparison based on the generated memory mutex table. The corresponding memory allocation operation. It can be understood that after the memory allocation operation is completed, the generated memory mutex table can be deleted or discarded.
可以理解的是,对于内存互斥表的具体获取方式并不限于上述例举的实现方式,本领域技术人员还可以采用其他的方式来获取内存互斥表,只要能够保证对内存互斥表进行获取的准确可靠性即可。It can be understood that the specific acquisition method for the memory mutual exclusion table is not limited to the above-mentioned implementation methods, and those skilled in the art can also use other methods to obtain the memory mutual exclusion table, as long as the memory mutual exclusion table can be guaranteed. The accuracy and reliability obtained can be obtained.
在获取到内存互斥表之后,则可以在离散化内存空间中,根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间。在一些实例中,在离散化内存空间中,根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间可以包括:确定与内存分配请求相对应的请求空间大小;在离散化内存空间中,按照预设分配顺序识别出与请求空间大小相对应的未分配的至少一个内存空间;将上述所确定的未分配的至少一个内存空间确定为与内存分配请求相对应的至少一个目标内存空间。After the memory mutual exclusion table is obtained, in the discretized memory space, at least one target memory space corresponding to the memory allocation request may be determined according to the memory mutual exclusion table. In some instances, in the discretized memory space, determining at least one target memory space corresponding to the memory allocation request according to the memory mutex table may include: determining the size of the request space corresponding to the memory allocation request; in the discretized memory space , identify at least one unallocated memory space corresponding to the size of the requested space according to the preset allocation order; determine the at least one unallocated memory space determined above as at least one target memory space corresponding to the memory allocation request .
具体的,在获取到内存分配请求之后,则可以对内存分配请求进行分析处理,以确定与内存分配请求相对应的请求空间大小,该请求空间大小与内存分配需求相对应,可以理解的是,不同的内存分配需求可以对应有不同的请求空间大小。Specifically, after the memory allocation request is obtained, the memory allocation request can be analyzed and processed to determine the size of the requested space corresponding to the memory allocation request. The size of the requested space corresponds to the memory allocation requirement. It is understandable that, Different memory allocation requirements can correspond to different request space sizes.
在获取到请求空间大小之后,则可以在离散化内存空间中,按照预设分配顺序识别出与请求空间大小相对应的未分配的至少一个内存空间,可以理解的是,至少一个内存空间所对应的空间大小可以大于或等于请求空间大小。在确定未分配的至少一个内存空间之后,则可以将所确定的未分配的至少一个内存空间确定为与内存分配请求相对应的至少一个目标内存空间,从而有效地保证了对至少一个目标内存空间进行确定的准确可靠性。After the requested space size is obtained, at least one unallocated memory space corresponding to the requested space size can be identified in the discretized memory space according to the preset allocation order. It can be understood that the at least one memory space corresponding to The space size can be greater than or equal to the requested space size. After the at least one unallocated memory space is determined, the determined at least one unallocated memory space may be determined as the at least one target memory space corresponding to the memory allocation request, thereby effectively guaranteeing the at least one target memory space The accuracy and reliability of the determination.
当然的,本领域技术人员也可以采用其他的方式来实现在离散化内存空间中,根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间,只要能够保证对至少一个目标内存空间进行确定的准确可靠性即可,在此不 再赘述。Of course, those skilled in the art can also use other methods to determine at least one target memory space corresponding to the memory allocation request in the discretized memory space according to the memory mutual exclusion table, as long as the at least one target memory space can be guaranteed. The accuracy and reliability of the determination are sufficient, and details are not described herein again.
举例来说,离散化内存空间中包括:空间A、空间B、空间C和空间D,在获取到内存分配请求之后,则可以基于内存分配请求来确定与离散化内存空间相对应的内存互斥表,该内存互斥表中可以包括:空间A、空间B、空间C和空间D以及分别与空间A、空间B、空间C和空间D相对应的空间分配状态。假设空间A的空间分配状态为占用状态,空间B的空间分配状态为空闲状态,空间C的空间分配状态为空闲状态,空间D的空间分配状态为占用状态。For example, the discretized memory space includes: space A, space B, space C, and space D. After the memory allocation request is obtained, the memory mutual exclusion corresponding to the discretized memory space can be determined based on the memory allocation request. The memory mutual exclusion table may include: space A, space B, space C, and space D, and space allocation states corresponding to space A, space B, space C, and space D respectively. It is assumed that the space allocation state of space A is occupied state, the space allocation state of space B is idle state, the space allocation state of space C is idle state, and the space allocation state of space D is occupied state.
在获取到内存分配请求之后,可以确定内存分配请求相对应的请求空间大小,在请求空间大小对应于两个待分配的内存空间时,则可以按照预设顺序对上述的离散化内存空间进行分析比对,从而可以识别出与请求空间大小相对应的未分配的至少一个内存空间可以包括空间B和空间C,而后则可以将空间B和空间C确定为与内存分配请求相对应的至少一个目标内存空间,从而有效地保证了对至少一个目标内存空间进行确定的准确可靠性。After the memory allocation request is obtained, the size of the requested space corresponding to the memory allocation request can be determined. When the size of the requested space corresponds to the two memory spaces to be allocated, the above-mentioned discrete memory spaces can be analyzed in a preset order. By comparison, it can be identified that at least one unallocated memory space corresponding to the requested space size can include space B and space C, and then space B and space C can be determined as at least one target corresponding to the memory allocation request memory space, thereby effectively ensuring the accurate reliability of determining at least one target memory space.
本实施例中,通过内存分配请求获取内存互斥表,而后在离散化内存空间中,根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间,这样不仅保证了对至少一个目标内存空间进行确定的准确可靠性,另外,由于内存互斥表可以存储在静态存储区域或者动态存储区域,或者内存互斥表还可以是临时变量,因此,在基于内存互斥表来确定至少一个目标内存空间时,此时的内存互斥表所占用的资源空间小,从而有利于提高内存的分配效率,进一步提高了该方法的实用性。In this embodiment, the memory mutual exclusion table is obtained through the memory allocation request, and then in the discretized memory space, at least one target memory space corresponding to the memory allocation request is determined according to the memory mutual exclusion table, which not only ensures that the at least one target memory space is The accuracy and reliability of memory space determination. In addition, since the memory mutex table can be stored in a static storage area or a dynamic storage area, or the memory mutex table can also be a temporary variable, it is necessary to determine at least one based on the memory mutex table. When the target memory space is used, the resource space occupied by the memory mutex table at this time is small, which is beneficial to improve the memory allocation efficiency and further improves the practicability of the method.
在一些实例中,本实施例中的方法还可以包括:在离散化内存空间中,未识别出与请求空间大小相对应的未分配的至少一个内存空间时,则生成用于标识内存空间分配失败的第一提示信息。In some instances, the method in this embodiment may further include: in the discretized memory space, when at least one unallocated memory space corresponding to the size of the requested space is not identified, generating a memory space for identifying a memory space allocation failure the first prompt message.
具体的,在离散化内存空间中并不存在与内存分配请求中请求空间大小相对应的内存空间时,则无法在离散化内存空间中识别出至少一个目标内存 空间。此时,为了提高该方法使用的稳定可靠性,当在离散化内存空间中未识别出与请求空间大小相对应的未分配的至少一个内存空间时,则可以生成用于标识内存空间分配失败的第一提示信息,以通过第一提示信息来向用户提示此时的内存空间分配操作已失败。Specifically, when there is no memory space corresponding to the size of the requested space in the memory allocation request in the discretized memory space, at least one target memory space cannot be identified in the discretized memory space. At this time, in order to improve the stability and reliability of the method, when at least one unallocated memory space corresponding to the size of the requested space is not identified in the discretized memory space, a message for identifying memory space allocation failure can be generated. The first prompt information is used to prompt the user that the memory space allocation operation at this time has failed through the first prompt information.
举例来说,离散化内存空间中包括:空间A、空间B、空间C和空间D,在获取到内存分配请求之后,则可以基于内存分配请求来确定与离散化内存空间相对应的内存互斥表,该内存互斥表中可以包括:空间A、空间B、空间C和空间D以及分别与空间A、空间B、空间C和空间D相对应的空间分配状态,假设空间A的空间分配状态为占用状态,空间B的空间分配状态为空闲状态,空间C的空间分配状态为空闲状态,空间D的空间分配状态为占用状态。For example, the discretized memory space includes: space A, space B, space C, and space D. After the memory allocation request is obtained, the memory mutual exclusion corresponding to the discretized memory space can be determined based on the memory allocation request. Table, the memory mutual exclusion table can include: space A, space B, space C and space D and space allocation status corresponding to space A, space B, space C and space D respectively, assuming the space allocation status of space A In the occupied state, the space allocation state of the space B is the idle state, the space allocation state of the space C is the idle state, and the space allocation state of the space D is the occupied state.
在获取到内存分配请求之后,可以确定内存分配请求相对应的请求空间大小,在请求空间大小对应于三个待分配的内存空间时,此时,可以按照预设顺序对上述的离散化内存空间进行分析比对,而后可以确定离散化内存空间中并不存在与请求空间大小相对应的未分配的至少一个内存空间。此时,则说明上述的内存分配操作无法实现,进而可以生成用于标识内存空间分配失败的第一提示信息,所生成的第一提示信息可以为声音提示信息、灯光提示信息、信息提示信息等等,以使得用户可以通过第一提示信息及时获知到此时的内存分配操作已失败,进一步提高了该方法使用的灵活可靠性。After the memory allocation request is obtained, the size of the requested space corresponding to the memory allocation request can be determined. When the size of the requested space corresponds to the three memory spaces to be allocated, at this time, the above-mentioned discrete memory spaces can be allocated in a preset order. After analysis and comparison, it can be determined that there is no unallocated at least one memory space corresponding to the size of the requested space in the discretized memory space. At this time, it means that the above-mentioned memory allocation operation cannot be realized, and then the first prompt information for identifying the memory space allocation failure can be generated, and the generated first prompt information can be sound prompt information, light prompt information, information prompt information, etc. etc., so that the user can know in time that the memory allocation operation has failed at this time through the first prompt information, which further improves the flexibility and reliability of the method.
在另一些实例中,在根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间之后,本实施例中的方法还可以包括:对内存互斥表中所包括的至少一个目标内存空间的空间分配状态进行复位,以标识至少一个目标内存空间的空间分配状态为未分配状态。In some other instances, after determining at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table, the method in this embodiment may further include: performing an operation on at least one target memory space included in the memory mutual exclusion table The space allocation state of the space is reset to identify the space allocation state of at least one target memory space as an unallocated state.
其中,对于离散化内存空间中所包括的内存空间而言,在进行一次内存分配操作时,则可以获取到与内存分配请求相对应的至少一个目标内存空间之后,而后则可以基于所确定的目标内存空间进行相对应的数据运算操作, 而在进行数据运算操作完毕之后,该数据运算操作所对应的目标内存空间可以被释放。Among them, for the memory space included in the discretized memory space, when a memory allocation operation is performed, at least one target memory space corresponding to the memory allocation request can be obtained, and then based on the determined target memory space can be obtained. The memory space performs the corresponding data operation operation, and after the data operation operation is completed, the target memory space corresponding to the data operation operation can be released.
基于上述陈述内容可知,为了提高内存分配效率,保证数据运算操作的质量和效率,在根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间之后,则可以对内存互斥表中所包括的至少一个目标内存空间的空间分配状态进行复位,以标识至少一个目标内存空间的空间分配状态为未分配状态,以便下一次获取到内存分配请求时,则可以基于内存分配请求对所有处于未分配状态的内存空间进行内存分配操作,从而有利于提高内存分配操作的质量和效率。Based on the above statement, in order to improve the efficiency of memory allocation and ensure the quality and efficiency of data operation, after determining at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table, the The space allocation state of the included at least one target memory space is reset to identify the space allocation state of the at least one target memory space as an unallocated state, so that the next time a memory allocation request is obtained, all in the memory allocation request can be based on the memory allocation request. The memory space in the unallocated state is used for memory allocation operations, thereby helping to improve the quality and efficiency of memory allocation operations.
图7为本发明实施例提供的根据内存分配请求,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间的流程示意图;在上述实施例的基础上,继续参考附图7所示,本实施例对至少一个目标子空间进行确定的具体实现方式不做限定,本领域技术人员可以根据具体的应用需求和设计需求进行设置,较为优选的,本实施例中的根据内存分配请求,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间可以包括:FIG. 7 is a schematic flowchart of determining at least one target subspace under each target memory space in at least one target memory space according to a memory allocation request according to an embodiment of the present invention; on the basis of the above embodiment, continue to refer to FIG. 7 As shown, this embodiment does not limit the specific implementation manner for determining at least one target subspace, and those skilled in the art can set it according to specific application requirements and design requirements. Preferably, in this embodiment, according to memory allocation The request to determine at least one target subspace below each target memory space in the at least one target memory space may include:
步骤S701:基于内存分配请求获取子空间查找表,子空间查找表中包括:待分配子空间以及待分配子空间的子空间分配状态。Step S701: Obtain a subspace lookup table based on the memory allocation request, where the subspace lookup table includes: the subspace to be allocated and the subspace allocation status of the subspace to be allocated.
步骤S702:根据子空间查找表,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,目标子空间为未分配状态,且至少一个目标子空间中的任意两个子空间之间互斥。Step S702: According to the subspace lookup table, determine at least one target subspace under each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and any two subspaces in the at least one target subspace are determined. mutually exclusive.
其中,内存分配请求中所对应的内存空间需求可以包括针对目标内存空间的空间分配需求和针对位于目标内存空间下层的子空间分配需求。而针对离散化内存空间下层的内存空间,可以对应有一子空间查找表,该子空间查找表中可以包括位于内存空间中的待分配子空间以及待分配子空间的子空间分配状态。The memory space requirements corresponding to the memory allocation request may include space allocation requirements for the target memory space and subspace allocation requirements for the subspace located at the lower level of the target memory space. For the memory space at the lower level of the discretized memory space, there may be a subspace lookup table corresponding to the subspace lookup table, and the subspace lookup table may include the subspace to be allocated in the memory space and the subspace allocation status of the subspace to be allocated.
在一些实例中,与离散化内存空间中所包括的内存空间相对应的子空间查找表而言,其可以存储在静态区域或者动态区域中。这样在获取到内存分配请求之后,可以通过访问上述的静态区域或者动态区域即可获取到与离散化内存空间中所包括的内存空间相对应的子空间查找表。In some instances, the subspace lookup table corresponding to the memory space included in the discretized memory space may be stored in a static region or a dynamic region. In this way, after the memory allocation request is obtained, the subspace lookup table corresponding to the memory space included in the discretized memory space can be obtained by accessing the above-mentioned static area or dynamic area.
在另一些实例中,子空间查找表可以为临时生成的变量信息,在获取到内存分配请求之后,则可以基于内存分配请求来确定临时生成的子空间查找表。具体的,子空间查找表所对应的空间区域大小可以小于或等于所对应的目标内存空间的空间区域大小。可以理解的是,在内存分配操作完毕之后,所生成的子空间查找表可以被删除或者丢弃。In other instances, the subspace lookup table may be temporarily generated variable information, and after the memory allocation request is obtained, the temporarily generated subspace lookup table may be determined based on the memory allocation request. Specifically, the size of the space region corresponding to the subspace lookup table may be smaller than or equal to the size of the space region of the corresponding target memory space. It can be understood that, after the memory allocation operation is completed, the generated subspace lookup table can be deleted or discarded.
可以理解的是,对于子空间查找表的具体获取方式并不限于上述例举的实现方式,本领域技术人员还可以采用其他的方式来获取子空间查找表,只要能够保证对子空间查找表进行获取的准确可靠性即可。It can be understood that the specific acquisition method of the subspace lookup table is not limited to the above-mentioned implementation methods, and those skilled in the art can also obtain the subspace lookup table in other ways, as long as it can ensure that the subspace lookup table is performed. The accuracy and reliability obtained can be obtained.
在获取到子空间查找表之后,则可以在至少一个目标内存空间中每个目标内存空间中,根据子空间查找表来确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所确定的目标子空间可以为未分配状态,且至少一个目标子空间中的任意两个子空间之间互斥。After the subspace lookup table is obtained, in each target memory space in the at least one target memory space, at least one target subspace below each target memory space in the at least one target memory space can be determined according to the subspace lookup table , the determined target subspace may be in an unallocated state, and any two subspaces in at least one target subspace are mutually exclusive.
在一些实例中,根据子空间查找表,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间可以包括:确定与内存分配请求相对应的请求子空间大小;在至少一个目标内存空间中每个目标内存空间中,根据子空间查找表采用位搜索的方式,识别出与请求子空间大小相对应的未分配的至少一个子空间;将上述所确定的未分配的至少一个子空间确定为与内存分配请求相对应的至少一个目标子空间。In some instances, according to the subspace lookup table, determining at least one target subspace below each target memory space in the at least one target memory space may include: determining the size of the request subspace corresponding to the memory allocation request; In each target memory space in the memory space, use a bit search method according to the subspace lookup table to identify at least one unallocated subspace corresponding to the size of the requested subspace; The space is determined to be at least one target subspace corresponding to the memory allocation request.
具体的,在获取到内存分配请求之后,则可以对内存分配请求进行分析处理,以确定与内存分配请求相对应的请求子空间大小,而后可以在至少一个目标内存空间中的每个目标内存空间中,根据子空间查找表采用位搜索的方式,识别出与请求子空间大小相对应的未分配的至少一个子空间;可以理 解的是,至少一个子空间所对应的空间大小可以大于或等于请求子空间大小。在确定未分配的至少一个子空间之后,则可以将所确定的未分配的至少一个子空间确定为与内存分配请求相对应的至少一个目标子空间,从而有效地保证了对至少一个目标子空间进行确定的准确可靠性。Specifically, after the memory allocation request is obtained, the memory allocation request can be analyzed and processed to determine the size of the request subspace corresponding to the memory allocation request, and then the size of each target memory space in the at least one target memory space can be determined. , according to the subspace lookup table, a bit search method is used to identify at least one unallocated subspace corresponding to the requested subspace size; it can be understood that the space size corresponding to at least one subspace may be greater than or equal to the requested subspace. Subspace size. After the unallocated at least one subspace is determined, the determined unallocated at least one subspace can be determined as the at least one target subspace corresponding to the memory allocation request, thereby effectively ensuring that the at least one target subspace is not allocated to the at least one target subspace. The accuracy and reliability of the determination.
当然的,本领域技术人员也可以采用其他的方式来实现根据子空间查找表,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,只要能够保证对至少一个目标子空间间进行确定的准确可靠性即可,在此不再赘述。Of course, those skilled in the art can also use other methods to determine at least one target subspace below each target memory space in the at least one target memory space according to the subspace lookup table, as long as the at least one target subspace can be guaranteed It is sufficient to determine the accuracy and reliability of the time interval, which will not be repeated here.
举例来说,离散化内存空间中某一目标内存空间中可以包括待分配的子空间a1、子空间a2、子空间a3和子空间a4,在获取到内存分配请求之后,则可以基于内存分配请求来确定与离散化内存空间相对应的子空间查找表,该子空间查找表中可以包括:待分配的子空间a1、子空间a2、子空间a3和子空间a4以及分别与子空间a1、子空间a2、子空间a3和子空间a4相对应的子空间分配状态,假设子空间a1的子空间分配状态为占用状态,子空间a2的子空间分配状态为空闲状态,子空间a3的子空间分配状态为空闲状态,子空间a4的子空间分配状态为占用状态。For example, a target memory space in the discretized memory space may include subspace a1, subspace a2, subspace a3, and subspace a4 to be allocated. After the memory allocation request is obtained, it can be based on the memory allocation request. Determine the subspace lookup table corresponding to the discretized memory space, the subspace lookup table may include: subspace a1, subspace a2, subspace a3 and subspace a4 to be allocated, and subspace a1, subspace a2 respectively , the subspace allocation status of subspace a3 and subspace a4, assuming that the subspace allocation status of subspace a1 is occupied, the subspace allocation status of subspace a2 is idle, and the subspace allocation status of subspace a3 is idle state, the subspace allocation state of the subspace a4 is the occupied state.
在获取到内存分配请求之后,可以确定与内存分配请求相对应的请求子空间大小,在请求子空间大小对应于两个待分配的子空间时,则可以识别出与请求空间大小相对应的未分配的至少一个子空间可以包括子空间a2和子空间a3,而后则可以将子空间a2和子空间a3确定为与内存分配请求相对应的至少一个目标子空间,从而有效地保证了对至少一个目标子空间进行确定的准确可靠性。After the memory allocation request is obtained, the size of the requested subspace corresponding to the memory allocation request can be determined. When the size of the requested subspace corresponds to the two subspaces to be allocated, it can be identified that the size of the requested subspace corresponds to the size of the requested space. The allocated at least one subspace can include subspace a2 and subspace a3, and then the subspace a2 and subspace a3 can be determined as at least one target subspace corresponding to the memory allocation request, thereby effectively ensuring that the at least one target subspace is The accuracy and reliability of the determination of the space.
在一些实例中,本实施例中的方法还可以包括:在根据子空间查找表,未确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,则生成用于标识子空间分配失败的第二提示信息。In some instances, the method in this embodiment may further include: when at least one target subspace below each target memory space in the at least one target memory space is not determined according to the subspace lookup table, generating a subspace for identifying the subspace The second prompt message for space allocation failure.
具体的,在目标内存空间中并不存在与内存分配请求中请求子空间大小 相对应的子空间时,则无法在目标内存空间中识别出至少一个目标子空间,为了提高该方法使用的稳定可靠性,当在目标内存空间中未识别出与请求子空间大小相对应的未分配的至少一个目标子空间时,则可以生成用于标识子空间分配失败的第二提示信息,以通过第二提示信息来向用户提示此时的子空间的内存分配操作已失败。Specifically, when a subspace corresponding to the size of the requested subspace in the memory allocation request does not exist in the target memory space, at least one target subspace cannot be identified in the target memory space. In order to improve the stability and reliability of the method When at least one unallocated target subspace corresponding to the size of the requested subspace is not identified in the target memory space, second prompt information for identifying the failure of subspace allocation can be generated to pass the second prompt message to inform the user that the memory allocation operation for the subspace at this time has failed.
举例来说,目标内存空间中包括待分配的子空间a1、子空间a2、子空间a3和子空间a4,在获取到内存分配请求之后,则可以基于内存分配请求来确定与离散化内存空间相对应的子空间查找表,该子空间查找表中可以包括:待分配的子空间a1、子空间a2、子空间a3和子空间a4以及分别与子空间a1、子空间a2、子空间a3和子空间a4相对应的子空间分配状态,假设子空间a1的子空间分配状态为占用状态,子空间a2的子空间分配状态为空闲状态,子空间a3的子空间分配状态为空闲状态,子空间a4的子空间分配状态为占用状态。For example, the target memory space includes subspace a1, subspace a2, subspace a3, and subspace a4 to be allocated. After the memory allocation request is obtained, the corresponding discretized memory space can be determined based on the memory allocation request. The subspace lookup table of the Corresponding subspace allocation status, assuming that the subspace allocation status of subspace a1 is occupied, the subspace allocation status of subspace a2 is idle, the subspace allocation status of subspace a3 is idle, and the subspace of subspace a4 The allocation state is the occupied state.
在获取到内存分配请求之后,可以确定内存分配请求相对应的请求子空间大小,在请求子空间大小对应于三个待分配的子空间时,此时,目标内存空间中并不存在与请求子空间大小相对应的未分配的至少一个子空间,进而则可以确定子空间分配操作失败,并可以生成用于标识子空间分配失败的第二提示信息,所生成的第二提示信息可以为声音提示信息、灯光提示信息、信息提示信息等等,以使得用户可以通过第二提示信息及时获知到此时的子空间内存分配操作已失败,进一步提高了该方法使用的灵活可靠性。After the memory allocation request is obtained, the size of the requested subspace corresponding to the memory allocation request can be determined. When the size of the requested subspace corresponds to the three subspaces to be allocated, at this time, there is no subspace related to the request in the target memory space. at least one unallocated subspace corresponding to the size of the space, and then it can be determined that the subspace allocation operation fails, and second prompt information for identifying the failure of subspace allocation can be generated, and the generated second prompt information can be a sound prompt information, lighting prompt information, information prompt information, etc., so that the user can know in time that the subspace memory allocation operation has failed at this time through the second prompt information, which further improves the flexibility and reliability of the method.
在另一些实例中,在根据子空间查找表,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间之后,本实施例中的方法还可以包括:对子空间查找表中所包括的至少一个目标子空间的子空间分配状态标识进行置位,以标识至少一个目标子空间的子空间分配状态为已分配状态。In some other instances, after determining at least one target subspace below each target memory space in the at least one target memory space according to the subspace lookup table, the method in this embodiment may further include: searching the subspace lookup table for The subspace allocation status flag of the included at least one target subspace is set to indicate that the subspace allocation status of the at least one target subspace is an allocated state.
其中,对于目标内存空间中所包括的内存空间而言,在进行一次内存分配操作时,则可以确定与至少一个目标内存空间中每个目标内存空间下层的 至少一个目标子空间。之后,基于所确定的至少一个目标子空间进行相对应的数据运算操作,而在进行数据运算操作完毕之后,该数据运算操作所对应的目标子空间已经被占用。Wherein, for the memory spaces included in the target memory space, when a memory allocation operation is performed, at least one target subspace below each target memory space in the at least one target memory space can be determined. Afterwards, a corresponding data operation operation is performed based on the determined at least one target subspace, and after the data operation operation is completed, the target subspace corresponding to the data operation operation has been occupied.
此时,为了避免对目标子空间的重复分配,则可以对子空间查找表中所包括的至少一个目标子空间的子空间分配状态标识进行置位,以标识至少一个目标子空间的子空间分配状态为已分配状态,这样可以实现在下一次获取到内存分配请求时,则可以基于内存分配请求对其他处于未分配状态的子空间进行内存分配操作,从而有利于提高内存分配操作的质量和效率。At this time, in order to avoid repeated allocation of the target subspace, the subspace allocation status flag of at least one target subspace included in the subspace lookup table may be set to identify the subspace allocation of the at least one target subspace The state is allocated, so that when the next memory allocation request is obtained, the memory allocation operation can be performed on other subspaces in the unallocated state based on the memory allocation request, which is beneficial to improve the quality and efficiency of the memory allocation operation.
图8为本发明实施例提供的另一种内存空间的分配方法的流程示意图;在上述实施例的基础上,继续参考附图8所示,在基于内存分配请求获取子空间查找表之前,本实施例中的方法还可以包括:FIG. 8 is a schematic flowchart of another method for allocating memory space provided by an embodiment of the present invention; on the basis of the above-mentioned embodiment, and continuing to refer to FIG. 8 , before acquiring a subspace lookup table based on a memory allocation request, this The method in an embodiment may also include:
步骤S801:根据内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息。Step S801 : According to the memory allocation request, determine the division configuration information for performing the space division operation on the memory space.
其中,在获取到内存分配请求之后,可以对内存分配请求进行分析处理,以确定用于对内存空间进行空间划分操作的划分配置信息,具体的,划分配置信息可以包括以下至少之一:划分数量、划分区域大小、划分地址信息。可以理解的是,与内存空间相对应的划分数量、划分区域大小和划分地址信息所对应的具体数值可以根据不同的应用场景和应用需求进行调整。Wherein, after the memory allocation request is obtained, the memory allocation request can be analyzed and processed to determine the division configuration information for performing the space division operation on the memory space. Specifically, the division configuration information may include at least one of the following: the number of divisions: , divide the area size, divide the address information. It can be understood that the number of divisions corresponding to the memory space, the size of the divided area, and the specific values corresponding to the divided address information can be adjusted according to different application scenarios and application requirements.
此外,不同的划分配置信息可以对应有不同的内存划分操作,举例来说,在划分配置信息包括划分数量时,在获取到划分配置信息之后,则可以基于划分数量对内存空间进行均等划分,从而可以获得满足上述划分数量的子空间。在划分配置信息包括划分区域大小时,在获取到划分配置信息之后,则可以基于划分区域大小对内存空间进行划分,从而可以获得满足上述划分区域大小的多个子空间。在划分配置信息包括划分地址信息时,在获取到划分配置信息之后,则可以基于划分地址信息对内存空间进行划分,从而可以获得满足上述划分地址信息的多个子空间。In addition, different partition configuration information may correspond to different memory partition operations. For example, when the partition configuration information includes the number of partitions, after the partition configuration information is obtained, the memory space can be equally divided based on the number of partitions, thereby A subspace satisfying the above-mentioned number of divisions can be obtained. When the division configuration information includes the size of the division area, after the division configuration information is obtained, the memory space may be divided based on the size of the division area, so as to obtain multiple subspaces satisfying the size of the division area. When the division configuration information includes division address information, after the division configuration information is acquired, the memory space may be divided based on the division address information, so that multiple subspaces satisfying the foregoing division address information can be obtained.
另外,用于对内存空间进行空间划分操作的划分配置信息可以是用户针对内存空间进行配置的,在对划分配置信息配置完毕之后,则可以将划分配置信息存储在预设区域中。在获取到内存分配请求之后,则可以基于内存分配请求访问预设区域,从而可以准确、有效地获得用于对内存空间进行空间划分操作的划分配置信息。In addition, the division configuration information for performing the space division operation on the memory space may be configured by the user for the memory space, and after the division configuration information is configured, the division configuration information may be stored in a preset area. After the memory allocation request is obtained, the preset area can be accessed based on the memory allocation request, so that the division configuration information for performing the space division operation on the memory space can be obtained accurately and effectively.
可以理解的是,划分配置信息可以不仅包括上述所限定的配置信息,本领域技术人员可以根据具体的应用需求和设计需求进行设置,例如:划分配置信息还可以包括处理数据大小,此时,在获取到处理数据大小之后,则可以可以基于划分地址信息对内存空间进行划分,以使得在满足数据处理操作的同时,可以使得内存空间的利用最大化。It can be understood that the division configuration information may not only include the above-defined configuration information, and those skilled in the art may set it according to specific application requirements and design requirements. For example, the division configuration information may also include the processing data size. After the processing data size is obtained, the memory space can be divided based on the divided address information, so that the utilization of the memory space can be maximized while satisfying the data processing operation.
举例来说,在内存空间的空间大小为128k时,在每个需要进行处理操作的操作数的数据大小为64k或者小于64k时,则可以基于数据量最大的数据对内存空间进行划分操作,即将内存空间平均划分为128k/64k=2块,从而可以使得每个操作数均可以找到对应的子空间,并且保证了数据处理效率。For example, when the space size of the memory space is 128k, when the data size of each operand that needs to be processed is 64k or less than 64k, the memory space can be divided based on the data with the largest amount of data. The memory space is evenly divided into 128k/64k=2 blocks, so that each operand can find the corresponding subspace, and the data processing efficiency is guaranteed.
相类似的,在内存空间的空间大小为128k时,在每个需要进行处理操作的操作数的数据大小均为4k时,则可以以上述数据大小对上述的内存空间进行划分操作,使得每个所划分的子空间大小为4k,这样在兼顾数据处理效率的同时,还可以避免内存空间的浪费。Similarly, when the space size of the memory space is 128k, and the data size of each operand that needs to be processed is 4k, the above-mentioned memory space can be divided by the above-mentioned data size, so that each The size of the divided subspace is 4k, which can avoid the waste of memory space while taking into account the data processing efficiency.
步骤S802:基于划分配置信息将内存空间划分为多个子空间,并生成与多个子空间相对应的子空间查找表。Step S802: Divide the memory space into multiple subspaces based on the division configuration information, and generate a subspace lookup table corresponding to the multiple subspaces.
在获取到划分配置信息之后,则可以基于划分配置信息将内存空间划分为多个子空间。在一些实例中,同一个内存空间内所包括的多个子空间所对应的空间区域大小可以相同或不同,较为优选的,同一个内存空间内所包括的多个子空间所对应的空间区域大小可以相同。在将内存空间划分为多个子空间之后,可以针对多个子空间生成与多个子空间相对应的子空间查找表,该子空间查找表中可以包括:待分配子空间以及待分配子空间的子空间分配 状态,以便基于子空间查找表实现内存分配操作。After the division configuration information is acquired, the memory space may be divided into multiple subspaces based on the division configuration information. In some instances, the size of the space regions corresponding to the multiple subspaces included in the same memory space may be the same or different. Preferably, the size of the space regions corresponding to the multiple subspaces included in the same memory space may be the same. . After the memory space is divided into multiple subspaces, a subspace lookup table corresponding to the multiple subspaces may be generated for the multiple subspaces, and the subspace lookup table may include: the subspace to be allocated and the subspace of the subspace to be allocated Allocation state to implement memory allocation operations based on subspace lookup tables.
本实施例中,在基于内存分配请求获取子空间查找表之前,通过内存分配请求来确定用于对内存空间进行空间划分操作的划分配置信息,而后基于划分配置信息将内存空间划分为多个子空间,从而有效地实现了可以根据不同的应用场景和应用需求将内存空间划分为多个不同的子空间,并可以生成与多个子空间相对应的子空间查找表,而后便于基于子空间查找表来进行内存分配操作,进一步提高了该方法的实用性和适用范围。In this embodiment, before obtaining the subspace lookup table based on the memory allocation request, the division configuration information for performing the space division operation on the memory space is determined through the memory allocation request, and then the memory space is divided into multiple subspaces based on the division configuration information , which effectively realizes that the memory space can be divided into multiple different subspaces according to different application scenarios and application requirements, and the subspace lookup table corresponding to the multiple subspaces can be generated, and then it is convenient to use the subspace lookup table. Performing memory allocation operations further improves the practicability and applicability of the method.
图9为本发明实施例提供的根据内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息的流程示意图;在上述实施例的基础上,继续参考附图9所示,本实施例对于确定用于对内存空间进行空间划分操作的划分配置信息的具体实现方式不做限定,本领域技术人员可以根据具体的应用场景和设计需求进行设置,较为优选的,本实施例中的根据内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息可以包括:FIG. 9 is a schematic flowchart of determining division configuration information for performing a space division operation on a memory space according to a memory allocation request according to an embodiment of the present invention; on the basis of the foregoing embodiment, continuing to refer to FIG. For example, the specific implementation method for determining the division configuration information used to perform the space division operation on the memory space is not limited, and those skilled in the art can set it according to specific application scenarios and design requirements. For the memory allocation request, the division configuration information for determining the space division operation for the memory space may include:
步骤S901:获取与内存分配请求相对应的至少一个运算数据长度。Step S901: Obtain at least one operation data length corresponding to the memory allocation request.
其中,在获取到内存分配请求之后,则可以对内存分配请求进行分析处理,从而可以获得与内存分配请求相对应的至少一个运算数据长度,可以理解的是,上述的运算数据长度是指需要进行数据运算处理操作时所对应的操作数的数据大小。After the memory allocation request is obtained, the memory allocation request can be analyzed and processed, so that at least one operation data length corresponding to the memory allocation request can be obtained. The data size of the operand corresponding to the data operation processing operation.
另外,本实施例对于获取与内存分配请求相对应的至少一个运算数据长度的具体实现方式不做限定,本领域技术人员可以根据具体的应用需求和设计需求进行设置。在一些实例中,内存分配请求中可以包括运算数据长度,通过对内存分配请求进行特征提取操作,从而可以获得与内存分配请求相对应的至少一个运算数据长度。In addition, this embodiment does not limit the specific implementation of acquiring the length of at least one operation data corresponding to the memory allocation request, and those skilled in the art can set it according to specific application requirements and design requirements. In some instances, the memory allocation request may include an operation data length, and by performing a feature extraction operation on the memory allocation request, at least one operation data length corresponding to the memory allocation request can be obtained.
在另一些实例中,预先设置有不同的内存分配请求与运算数据长度之间的映射关系,在获取到内存分配请求之后,则可以基于上述映射关系来确定与内存分配请求相对应的至少一个运算数据长度。In other instances, mapping relationships between different memory allocation requests and operation data lengths are preset, and after the memory allocation request is acquired, at least one operation corresponding to the memory allocation request can be determined based on the above mapping relationship Data length.
步骤S902:在至少一个运算数据长度中,获得最大的目标运算数据长度。Step S902: In at least one operation data length, obtain the maximum target operation data length.
步骤S903:基于目标运算数据长度,确定用于对内存空间进行空间划分操作的划分配置信息。Step S903: Based on the target operation data length, determine the division configuration information for performing the space division operation on the memory space.
在获取到至少一个运算数据长度之后,则可以将所有的运算数据长度进行分析比较,获得数据量最大的操作数所对应的目标运算数据长度。而后可以对目标运算数据长度进行分析处理,以确定用于对内存空间进行空间划分操作的划分配置信息。在一些实例中,在划分配置信息包括划分数量时,本实施例中的基于目标运算数据长度,确定用于对内存空间进行空间划分操作的划分配置信息可以包括:获取内存空间的总区域大小;基于总区域大小与目标运算数据长度之间的比值,确定用于对内存空间进行空间划分操作的划分数量。After at least one operation data length is acquired, all operation data lengths can be analyzed and compared to obtain the target operation data length corresponding to the operand with the largest amount of data. Then, the length of the target operation data can be analyzed and processed to determine the division configuration information for performing the space division operation on the memory space. In some instances, when the division configuration information includes the division quantity, in this embodiment, based on the target operation data length, determining the division configuration information for performing the space division operation on the memory space may include: obtaining the total area size of the memory space; Based on the ratio between the total area size and the target operation data length, the number of divisions used for the space division operation of the memory space is determined.
具体的,在划分配置信息包括划分数量时,为了能够准确地获取到划分数量,以使得基于划分数量所划分的子空间能够满足数据运算操作,则可以获取内存空间的总区域大小,而后可以获得总区域大小与目标运算数据长度之间的比值,之后则可以对上述的比值进行分析处理,以确定用于对内存空间进行空间划分操作的划分数量。在一些实例中,对比值进行分析处理,确定用于对内存空间进行空间划分操作的划分数量可以包括:对比值进行向上取整操作,之后将进行取整操作之后的数量确定为用于对内存空间进行空间划分操作的划分数量,从而有效地保证了对划分数量进行确定的准确可靠性。Specifically, when the division configuration information includes the division quantity, in order to obtain the division quantity accurately, so that the subspace divided based on the division quantity can satisfy the data operation operation, the total area size of the memory space can be obtained, and then the The ratio between the total area size and the target operation data length, and then the above ratio can be analyzed and processed to determine the number of divisions used for space division operations on the memory space. In some instances, performing analysis processing on the comparison value and determining the number of divisions used for performing the space division operation on the memory space may include: performing an upward rounding operation on the comparison value, and then determining the number after performing the rounding operation as the number used for performing the space division operation on the memory space. The number of divisions of the space for the space division operation, thereby effectively ensuring the accuracy and reliability of determining the number of divisions.
本实施例中,通过获取与内存分配请求相对应的至少一个运算数据长度,而后在至少一个运算数据长度中获得最大的目标运算数据长度,并基于目标运算数据长度来确定用于对内存空间进行空间划分操作的划分配置信息(划分数量),从而有效地保证了对划分配置信息中划分数量进行获取的准确可靠性。In this embodiment, at least one operation data length corresponding to the memory allocation request is obtained, and then the maximum target operation data length is obtained from the at least one operation data length, and the target operation data length is determined based on the target operation data length. The division configuration information (the division quantity) of the space division operation, thereby effectively ensuring the accuracy and reliability of obtaining the division quantity in the division configuration information.
图10为本发明实施例提供的又一种内存空间的分配方法的流程示意图;在上述任意一个实施例的基础上,继续参考附图10所示,本实施例中的方法 还可以包括:Figure 10 is a schematic flowchart of another method for allocating memory space provided by an embodiment of the present invention; on the basis of any of the above-mentioned embodiments, and continuing to refer to Figure 10, the method in this embodiment may also include:
步骤S1001:获取内存释放请求。Step S1001: Obtain a memory release request.
步骤S1002:根据内存释放请求,确定待释放的内存空间以及位于内存空间内待释放的子空间。Step S1002: Determine the memory space to be released and the subspace to be released in the memory space according to the memory release request.
步骤S1003:对内存空间和子空间进行释放操作。Step S1003: Release the memory space and the subspace.
其中,在针对所分配的内存空间执行完相对应的数据运算操作之后,则可以针对内存空间进行内存释放操作,此时可以生成并获得内存释放请求,该内存释放请求用于对进行数据运算操作的内存空间进行释放操作。在获取到内存释放请求之后,则可以对内存释放请求进行分析处理,以确定与内存释放请求相对应的待释放的内存空间以及位于内存空间内待释放的子空间。之后,可以对上述所确定的内存空间和子空间进行释放操作,以可以基于所释放的内存空间和子空间进行其他的数据运算操作,进一步提高了内存分配方法的实用性。Among them, after the corresponding data operation operation is performed on the allocated memory space, a memory release operation can be performed on the memory space, and a memory release request can be generated and obtained at this time, and the memory release request is used to perform the data operation operation on the memory space. The memory space is released. After the memory release request is acquired, the memory release request may be analyzed and processed to determine the memory space to be released and the subspace located in the memory space to be released corresponding to the memory release request. Afterwards, a release operation can be performed on the determined memory space and subspace, so that other data operation operations can be performed based on the released memory space and subspace, which further improves the practicability of the memory allocation method.
在另一些实例中,在对内存空间和子空间进行释放操作之后,本实施例中的方法还可以包括:In other instances, after the release operation is performed on the memory space and the subspace, the method in this embodiment may further include:
步骤S1101:对与内存空间相对应的内存互斥表中已释放的内存空间的空间分配状态进行复位,以标识已释放的内存空间为未分配状态;Step S1101: Reset the space allocation state of the released memory space in the memory mutual exclusion table corresponding to the memory space to identify the released memory space as an unallocated state;
具体的,在对内存空间进行释放操作之后,为了能够及时、可靠地对内存空间进行相对应的数据运算操作,则可以对内存空间相对应的内存互斥表中已释放的内存空间的空间分配状态进行复位,以标识已释放的内存空间为未分配状态,以便在之后的数据运算操作或者内存分配操作过程中可以对未分配的内存空间进行内存分配操作,这样有利于提高空间的利用率,进一步提高了该方法使用的稳定可靠性。Specifically, after the memory space is released, in order to perform the corresponding data operation operation on the memory space in a timely and reliable manner, the space allocation of the released memory space in the memory mutex table corresponding to the memory space can be performed. The state is reset to identify the released memory space as an unallocated state, so that memory allocation operations can be performed on the unallocated memory space during subsequent data operation operations or memory allocation operations, which is conducive to improving space utilization. The stability and reliability of the method are further improved.
步骤S1102:对与子空间相对应的子空间查找表中已释放的子空间的子空间分配状态进行置位,以标识已释放的子空间为未分配状态。Step S1102: Set the subspace allocation state of the released subspace in the subspace lookup table corresponding to the subspace to identify the released subspace as an unallocated state.
相类似的,在对子空间进行释放操作之后,为了能够及时、可靠地对子 空间进行相对应的数据运算操作,则可以对子空间相对应的子空间查找表中已释放的子空间的子空间分配状态进行置位,以标识已释放的子空间为未分配状态,以便在之后的数据运算操作或者内存分配操作过程中可以对未分配的子空间进行内存分配操作,这样有利于提高空间的利用率,进一步提高了该方法使用的稳定可靠性。Similarly, after the subspace is released, in order to perform the corresponding data operation operation on the subspace in a timely and reliable manner, the subspace of the released subspace in the subspace corresponding to the subspace can be searched. The space allocation state is set to identify the released subspace as an unallocated state, so that memory allocation operations can be performed on the unallocated subspace during subsequent data operation operations or memory allocation operations, which is conducive to improving the space availability. The utilization rate is further improved, and the stable reliability of the method is further improved.
具体应用时,参考附图11所示,本应用实施例提供了一种双层空间的内存分配方法,该方法可以针对离散化空间进行内存分配操作,具体的,基于两层内存空间(内存空间以及位于内存空间下层的子空间)所对应的内存互斥表和子空间查找表来进行内存分配操作,同时支持多块互斥空间的内存分配操作,有利于降低资源的占用空间,并可以提高内存的分配效率,从而使得该方法可以适合于资源和性能较为敏感的系统或平台。具体的,该方法可以包括以下步骤:In a specific application, referring to FIG. 11 , this application embodiment provides a memory allocation method for a double-layer space, which can perform a memory allocation operation for a discretized space. Specifically, based on the two-layer memory space (memory space and the subspace located at the lower level of the memory space) corresponding to the memory mutex table and subspace lookup table to perform memory allocation operations, and support the memory allocation operation of multiple mutex spaces, which is conducive to reducing the occupied space of resources and can improve memory Therefore, the method can be suitable for resource- and performance-sensitive systems or platforms. Specifically, the method may include the following steps:
步骤1:获取针对离散化内存空间的内存分配请求。Step 1: Get a memory allocation request for the discretized memory space.
其中,离散化内存空间可以是双层的空间结构,即离散化内存空间可以包括一个或多个内存空间block,多个内存空间可以为:block0、block1、block2......blockN,每个内存空间可以包括多个子空间;并且,上述的每个block可以为独立的存储单元,其内部地址连续,各个block之间的地址离散。在进行向量数据进行运算的应用场景下,每个向量操作数对应有不同的block,在对向量操作数进行分配的过程中,需要保证所分配的各个block之间互斥。The discretized memory space may be a double-layered space structure, that is, the discretized memory space may include one or more memory space blocks, and the multiple memory spaces may be: block0, block1, block2...blockN, each Each memory space may include a plurality of subspaces; and, each of the above blocks may be an independent storage unit, whose internal addresses are continuous, and the addresses between each block are discrete. In the application scenario of performing operations on vector data, each vector operand corresponds to a different block. In the process of allocating vector operands, it is necessary to ensure mutual exclusion between the allocated blocks.
在获取到内存分配请求之后,则可以基于内存分配请求对block和位于block下层的一个或多个子空间进行内存分配操作,从而使得该方法可以实现对内存空间block级别和位于内存空间下层的多个互斥子空间同时进行内存分配操作。After the memory allocation request is obtained, a memory allocation operation can be performed on the block and one or more subspaces located in the lower layer of the block based on the memory allocation request, so that the method can realize the block level of the memory space and multiple subspaces located in the lower layer of the memory space. Mutually exclusive subspaces perform memory allocation operations at the same time.
此外,针对内存空间而言,该方法还可以提供子空间颗粒度的配置接口,这样在进行内存分配操作之前,可以通过上述的配置接口、根据数据处理需 求配置每个block的划分颗粒度。具体的,配置接口可以包括如下:In addition, for the memory space, this method can also provide a configuration interface of subspace granularity, so that before performing the memory allocation operation, the partition granularity of each block can be configured according to the data processing requirements through the above configuration interface. Specifically, the configuration interface may include the following:
(1)颗粒度配置接口“void set_unit_length(size_t byte_len)”,用于配置block内子空间的长度,单位可以为byte。(1) The granularity configuration interface "void set_unit_length(size_t byte_len)" is used to configure the length of the subspace in the block, and the unit can be byte.
(2)block层分配接口“void*malloc_block()”,用于分配空闲block,在成功分配之后,则可以返回block地址,在分配失败之后,则可以返回“NULL”。(2) The block layer allocation interface "void*malloc_block()" is used to allocate free blocks. After successful allocation, the block address can be returned, and after allocation failure, "NULL" can be returned.
(3)block层释放接口“void free_block(void*ptr_block)”,用于释放ptr_block所在的block。(3) The block layer releases the interface "void free_block(void*ptr_block)", which is used to release the block where the ptr_block is located.
(4)子空间分配接口“bool malloc_subspace(size_t len,void*ptr_s)”,用于分配单块长度为len的子空间,在分配成功之后,则赋值ptr_s为子空间的地址,并返回“True”;在分配失败之后,则赋值“NULL”,并返回“False”。(4) The subspace allocation interface "bool malloc_subspace(size_t len, void*ptr_s)" is used to allocate a subspace with a single block length of len. After the allocation is successful, assign ptr_s as the address of the subspace and return "True" "; after the allocation fails, assign "NULL" and return "False".
(5)子空间分配接口“bool malloc_subspace(size_t len1,void*ptr_s1,size_t len2,void*ptr_s2)”,用于同时分配两块长度为len1、len2的block互斥子空间,在分配成功之后,则赋值ptr_s1、ptr_s2为子空间的地址,并返回“True”;在分配失败之后,则赋值“NULL”,并返回“False”。(5) The subspace allocation interface "bool malloc_subspace(size_t len1, void*ptr_s1, size_t len2, void*ptr_s2)" is used to allocate two blocks of mutually exclusive subspaces of length len1 and len2 at the same time. After the allocation is successful, Then assign ptr_s1 and ptr_s2 as the address of the subspace, and return "True"; after the allocation fails, assign "NULL" and return "False".
(6)子空间分配接口“bool malloc_subspace(size_t len1,void*ptr_s1,size_t len2,void*ptr_s2,size_t len3,void*ptr_s3)”,用于同时分配三块长度为len1、len2、len3的block互斥子空间,在分配成功之后,则赋值ptr_s1、ptr_s2、ptr_s3为子空间的地址,并返回“True”;在分配失败之后,则赋值“NULL”,并返回“False”。(6) The subspace allocation interface "bool malloc_subspace(size_t len1, void*ptr_s1, size_t len2, void*ptr_s2, size_t len3, void*ptr_s3)" is used to allocate three blocks of length len1, len2, len3 at the same time. To exclude subspace, after the allocation is successful, assign ptr_s1, ptr_s2, and ptr_s3 as the address of the subspace, and return "True"; after the allocation fails, assign "NULL" and return "False".
(7)子空间分配接口“bool malloc_subspace(size_t len1,void*ptr_s1,size_t len2,void*ptr_s2,size_t len3,void*ptr_s3,size_t len4,void*ptr_s4)”,用于同时分配四块长度为len1、len2、len3、len4的block互斥子空间,在分配成功之后,则赋值ptr_s1、ptr_s2、ptr_s3、 ptr_s4为子空间的地址,并返回“True”;在分配失败之后,则赋值“NULL”,并返回“False”。(7) Subspace allocation interface "bool malloc_subspace(size_t len1, void*ptr_s1, size_t len2, void*ptr_s2, size_t len3, void*ptr_s3, size_t len4, void*ptr_s4)", used to allocate four blocks of length len1 at the same time , len2, len3, len4 block mutually exclusive subspace, after successful allocation, assign ptr_s1, ptr_s2, ptr_s3, ptr_s4 as the address of the subspace, and return "True"; after the allocation fails, assign "NULL", and returns "False".
(8)子空间分配接口“void free_subspace(void*ptr_s,size_t unit_num)”,用于由ptr_s开始,释放unit_num块个子空间,以实现子空间的释放操作。(8) The subspace allocation interface "void free_subspace(void*ptr_s, size_t unit_num)" is used to release unit_num blocks of subspaces starting from ptr_s to realize the release operation of the subspace.
在针对内存空间和内存空间所对应的子空间配置完成之后,则可以根据划分颗粒度为各个block申请分配相对应的内存互斥表和子空间查找表,该内存互斥表用于记录各个block的占用情况,子空间查找表用于记录各block下层所包括的至少一个子空间的占用情况。具体的,在内存互斥表和子空间查找表中,可以用“0”来标识内存空间或者子空间处于未被占用状态,用“1”来标识内存空间或者子空间处于占用状态。After the configuration of the subspace corresponding to the memory space and the memory space is completed, the corresponding memory mutex table and subspace lookup table can be allocated for each block application according to the granularity of division. The memory mutex table is used to record the Occupancy, the subspace lookup table is used to record the occupancy of at least one subspace included in the lower layer of each block. Specifically, in the memory mutual exclusion table and the subspace lookup table, "0" may be used to indicate that the memory space or subspace is in an unoccupied state, and "1" may be used to indicate that the memory space or subspace is in an occupied state.
基于上述的陈述内容,在对block层空间进行内存分配操作时,可以通过子空间查找表查找全部子空间处于未被占用的block,而后则可以对上述处于未被占用的block进行内存分配操作。在对block进行内存分配操作之后,则可以对子空间查找表中的标识进行整体翻转,可以理解的是,上述的内存分配操作满足block互斥的需求,并且在进行内存释放时,可以提供预设接口对整块block的查找表进行复位,有利于完成block的释放操作。Based on the above statement, when performing a memory allocation operation on the block layer space, the subspace lookup table can be used to find unoccupied blocks in all subspaces, and then a memory allocation operation can be performed on the above-mentioned unoccupied blocks. After the memory allocation operation is performed on the block, the identifiers in the subspace lookup table can be flipped as a whole. It can be understood that the above memory allocation operation satisfies the requirement of mutual exclusion of blocks, and can provide a pre-order when the memory is released. Setting the interface to reset the lookup table of the entire block is conducive to completing the block release operation.
在对block层中所包括的子空间进行内存分配操作时,可以通过子空间查找表进行位搜索,从而可以实现空间分配与释放操作;在一些实例中,本实施例提供的同时分配多块互斥子空间的实现方法,可以支持最多4块子空间的同时分配操作。When performing a memory allocation operation on the subspace included in the block layer, a bit search can be performed through the subspace lookup table, so that space allocation and release operations can be implemented; in some instances, this embodiment provides the simultaneous allocation of multiple blocks The implementation method of the exclusive subspace can support simultaneous allocation operations of up to 4 subspaces.
步骤2:基于内存分配请求,利用内存互斥表查找与内存分配请求相对应的至少一个目标内存空间。Step 2: Based on the memory allocation request, use the memory mutual exclusion table to find at least one target memory space corresponding to the memory allocation request.
具体的,可以基于内存分配请求控制预设指针blocki指向block0,即从blcok0开始查找处于未被占用的内存空间,在当前内存分配操作的过程中,当检测到第i个内存空间blocki处于未分配状态时,则可以将blocki确定 为一目标内存空间。Specifically, the preset pointer blocki can be controlled to point to block0 based on the memory allocation request, that is, the unoccupied memory space is searched from blcok0. During the current memory allocation operation, when it is detected that the ith memory space blocki is unallocated In the state, blocki can be determined as a target memory space.
步骤3:在获取到目标内存空间之后,则可以利用子空间查找表来确定与目标内存空间下层的至少一个目标子空间,所确定的至少一个目标子空间即为满足需求的未被占用的子空间。Step 3: After obtaining the target memory space, the subspace lookup table can be used to determine at least one target subspace below the target memory space, and the determined at least one target subspace is the unoccupied subspace that meets the requirements. space.
步骤4:在查找到一空闲的目标子空间之后,可以将该目标子空间所在内存互斥表以及子空间查找表中继续进行下一个子空间的分配操作。Step 4: After finding a free target subspace, the allocation operation of the next subspace can be continued in the memory mutex table and subspace lookup table where the target subspace is located.
步骤5:直至找到所有需要进行内存分配操作的所有子空间都完成分配操作,则结束分配,并复位互斥表。Step 5: Until all the subspaces that need to perform the memory allocation operation are found to complete the allocation operation, the allocation is ended, and the mutex table is reset.
其中,如果在步骤2中,blocki在此次空间分配过程中处于已被分配状态,或者,步骤3中的blocki空闲空间不足时,则移动至后一块block重新进行查找。如果移动至block尾部仍无法满足内存分配需求时,则空间分配操作失败,此时,可以结束内存分配操作,并可以将互斥表及当次已分配的空间进行释放操作。Among them, if in step 2, blocki is in the allocated state in this space allocation process, or, if the free space of blocki in step 3 is insufficient, move to the next block to search again. If moving to the end of the block still cannot meet the memory allocation requirements, the space allocation operation fails. At this time, the memory allocation operation can be ended, and the mutex table and the currently allocated space can be released.
另一方面,在对子空间进行内存分配操作时,可以采用按位搜索的方式来查找与内存分配请求相对应的子空间,具体的,参考附图12所示,该方法可以包括如下步骤:On the other hand, when performing a memory allocation operation on a subspace, a bitwise search method can be used to find the subspace corresponding to the memory allocation request. Specifically, as shown in FIG. 12, the method may include the following steps:
步骤S11:根据空间需求大小及颗粒度,确定待搜索的所有子空间,并初始化用于进行子空间查找操作的位搜索指针bit mask。Step S11: Determine all the subspaces to be searched according to the size and granularity of the space requirement, and initialize the bit search pointer bit mask used for the subspace search operation.
其中,在颗粒度为16byte,空间需求为128byte时,则可以确定bit mask为0b11111111。Among them, when the granularity is 16byte and the space requirement is 128byte, the bit mask can be determined to be 0b11111111.
步骤S12:在bit mask未超过block的查找表长度(总空间大小)的条件下,则可以按照查找表、参考位与“&bit mask”的方式,确定当前子空间区间是否可用。若子空间的标识位为“0”,则表明子空间处于可分配状态,并可以将该子空间的分配表置位,完成内存分配操作。Step S12: Under the condition that the bit mask does not exceed the lookup table length (total space size) of the block, it can be determined whether the current subspace interval is available according to the lookup table, reference bits and "&bit mask". If the identification bit of the subspace is "0", it indicates that the subspace is in an allocatable state, and the allocation table of the subspace can be set to complete the memory allocation operation.
步骤S13:若子空间的标识位为“1”,则表明子空间处于不可分配状态,将bit mask做左移一位的操作,继续查找空闲的子空间内存。Step S13: If the identification bit of the subspace is "1", it indicates that the subspace is in an unallocable state, and the bit mask is shifted to the left by one bit, and the free subspace memory is continued to be searched.
在初始化或移位bit mask之后,若其长度超出查找表的有效长度,则表明无法在该block中查找到满足预设需求的空闲子空间,进而可以结束内存分配操作。After initializing or shifting the bit mask, if its length exceeds the effective length of the lookup table, it indicates that a free subspace that meets the preset requirements cannot be found in the block, and the memory allocation operation can be ended.
在另一些实例中,本实施例中的方法还可以包括内存释放操作,具体的,针对离散化内存空间而言,可以对应有block整体释放及子空间释放两种释放方式。其中,在对整个block进行内存释放操作时,则可以确定入参地址所对应的block,而后对上述所确定的block进行内存释放操作,并将该block的查找表整体复位。在对子空间进行内存释放操作时,则可以通过所提供子空间起始地址及释放颗粒数来确定待释放的子空间,并可以对所确定的子空间进行内存释放操作。In other instances, the method in this embodiment may further include a memory release operation. Specifically, for the discrete memory space, there may be corresponding two release methods of block release as a whole and subspace release. Wherein, when the memory release operation is performed on the entire block, the block corresponding to the input parameter address can be determined, and then the memory release operation is performed on the block determined above, and the lookup table of the block is reset as a whole. When the memory release operation is performed on the subspace, the subspace to be released can be determined by the provided subspace starting address and the number of released particles, and the memory release operation can be performed on the determined subspace.
本应用实施例提供的内存分配方法,有效地实现了能够灵活地对离散内存空间进行内存分配,具体的,通过获取到针对离散化内存空间的内存分配请求,而后可以基于内存分配请求获得与内存分配请求相对应的目标内存空间和位于目标内存空间下层的目标子空间,所获得的目标内存空间和目标子空间之间互斥,由于不存在内部链表结构,因此有效地降低了数据资源所需要占用的空间大小,有利于提高内存分配效率,从而使得该方法适合于资源敏感系统的内存分配,进一步提高了该方法的实用性和适用范围。The memory allocation method provided by this application embodiment effectively realizes that the memory allocation can be flexibly performed on the discrete memory space. Specifically, by obtaining the memory allocation request for the discrete memory space, the memory allocation request can be obtained based on the memory allocation request. The target memory space corresponding to the allocation request and the target subspace located at the lower level of the target memory space are mutually exclusive. The obtained target memory space and the target subspace are mutually exclusive. Since there is no internal linked list structure, the required data resources are effectively reduced. The size of the occupied space is conducive to improving the efficiency of memory allocation, so that the method is suitable for memory allocation of resource-sensitive systems, and the practicability and application scope of the method are further improved.
图13为本发明实施例提供的一种内存空间的分配装置的结构示意图;参考附图13所示,本实施例提供了一种内存空间的分配装置,该分配装置用于执行图3所对应的内存空间的分配方法,具体的,该分配装置可以包括:FIG. 13 is a schematic structural diagram of an apparatus for allocating memory space provided by an embodiment of the present invention; with reference to FIG. 13 , this embodiment provides an apparatus for allocating memory space, and the apparatus for allocating memory space is used to execute the corresponding device shown in FIG. 3 . The memory space allocation method, specifically, the allocation device may include:
存储器12,用于存储计算机程序;a memory 12 for storing computer programs;
处理器11,用于运行存储器12中存储的计算机程序以实现:The processor 11 is used for running the computer program stored in the memory 12 to realize:
获取针对离散化内存空间的内存分配请求;Get the memory allocation request for the discretized memory space;
在离散化内存空间中,确定与内存分配请求相对应的至少一个目标内存空间,目标内存空间为未分配状态,且至少一个目标内存空间中的任意两个 目标内存空间之间互斥;In the discretized memory space, determine at least one target memory space corresponding to the memory allocation request, the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are mutually exclusive;
根据内存分配请求,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,目标子空间为未分配状态,且至少一个目标子空间中的任意两个子空间之间互斥。According to the memory allocation request, at least one target subspace below each target memory space in the at least one target memory space is determined, the target subspace is in an unallocated state, and any two subspaces in the at least one target subspace are mutually exclusive.
其中,内存空间的分配装置的结构中还可以包括通信接口13,用于实现内存空间的分配装置与其他设备或通信网络通信。The structure of the apparatus for allocating memory space may further include a communication interface 13 for enabling the apparatus for allocating memory space to communicate with other devices or a communication network.
在一些实例中,至少一个目标内存空间中每个目标内存空间中的地址信息连续,且至少一个目标内存空间中任意两个目标内存空间之间的地址信息离散。In some instances, the address information in each target memory space in the at least one target memory space is continuous, and the address information between any two target memory spaces in the at least one target memory space is discrete.
在一些实例中,在处理器11在离散化内存空间中,确定与内存分配请求相对应的至少一个目标内存空间时,该处理器11可以用于执行:基于内存分配请求获取内存互斥表,内存互斥表中包括:在离散化内存空间中的待分配内存空间以及待分配内存空间的空间分配状态;在离散化内存空间中,根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间。In some instances, when the processor 11 determines at least one target memory space corresponding to the memory allocation request in the discretized memory space, the processor 11 may be configured to perform: acquiring the memory mutex table based on the memory allocation request, The memory mutual exclusion table includes: the memory space to be allocated in the discretized memory space and the space allocation status of the memory space to be allocated; in the discretized memory space, at least one memory allocation request corresponding to the memory allocation request is determined according to the memory mutual exclusion table. target memory space.
在一些实例中,在处理器11在离散化内存空间中,根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间时,该处理器11可以用于执行:确定与内存分配请求相对应的请求空间大小;在离散化内存空间中,按照预设分配顺序识别出与请求空间大小相对应的未分配的至少一个内存空间;将上述所确定的未分配的至少一个内存空间确定为与内存分配请求相对应的至少一个目标内存空间。In some instances, when the processor 11 is in the discretized memory space and determines at least one target memory space corresponding to the memory allocation request according to the memory mutex table, the processor 11 may be configured to execute: determine the memory allocation request The corresponding request space size; in the discretized memory space, identify at least one unallocated memory space corresponding to the requested space size according to the preset allocation order; determine the above determined unallocated at least one memory space as At least one target memory space corresponding to the memory allocation request.
在一些实例中,本实施例中的处理器11可以用于执行:在离散化内存空间中,未识别出与请求空间大小相对应的未分配的至少一个内存空间时,则生成用于标识内存空间分配失败的第一提示信息。In some instances, the processor 11 in this embodiment may be used to execute: in the discretized memory space, when at least one unallocated memory space corresponding to the size of the requested space is not identified, generate a memory space for identifying the memory The first prompt message for space allocation failure.
在一些实例中,在根据内存互斥表确定与内存分配请求相对应的至少一个目标内存空间之后,本实施例中的处理器11可以用于执行:对内存互斥表中所包括的至少一个目标内存空间的空间分配状态进行复位,以标识至少一 个目标内存空间的空间分配状态为未分配状态。In some instances, after determining at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table, the processor 11 in this embodiment may be configured to perform: The space allocation state of the target memory space is reset to identify the space allocation state of at least one target memory space as an unallocated state.
在一些实例中,在处理器11根据内存分配请求,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,该处理器11可以用于执行:基于内存分配请求获取子空间查找表,子空间查找表中包括:待分配子空间以及待分配子空间的子空间分配状态;根据子空间查找表,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,目标子空间为未分配状态,且至少一个目标子空间中的任意两个子空间之间互斥。In some instances, when the processor 11 determines, according to the memory allocation request, at least one target subspace below each target memory space in the at least one target memory space, the processor 11 may be configured to execute: obtain the subspace based on the memory allocation request A space lookup table, the subspace lookup table includes: the subspace to be allocated and the subspace allocation status of the subspace to be allocated; according to the subspace lookup table, determine at least one target subspace below each target memory space in the at least one target memory space space, the target subspace is unallocated, and any two subspaces in at least one target subspace are mutually exclusive.
在一些实例中,在处理器11根据子空间查找表,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,该处理器11可以用于执行:确定与内存分配请求相对应的请求子空间大小;在至少一个目标内存空间中每个目标内存空间中,根据子空间查找表采用位搜索的方式,识别出与请求子空间大小相对应的未分配的至少一个子空间;将上述所确定的未分配的至少一个子空间确定为与内存分配请求相对应的至少一个目标子空间。In some instances, when the processor 11 determines, according to the subspace lookup table, at least one target subspace below each target memory space in the at least one target memory space, the processor 11 may be configured to perform: determining and requesting a memory allocation The corresponding requested subspace size; in each target memory space in at least one target memory space, use a bit search method according to the subspace lookup table to identify at least one unallocated subspace corresponding to the requested subspace size ; Determine at least one unallocated subspace determined above as at least one target subspace corresponding to the memory allocation request.
在一些实例中,子空间查找表所对应的空间区域大小小于或等于所对应的目标内存空间的空间区域大小。In some examples, the size of the space region corresponding to the subspace lookup table is less than or equal to the size of the space region of the corresponding target memory space.
在一些实例中,本实施例中的处理器11用于执行:在根据子空间查找表,未确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,则生成用于标识子空间分配失败的第二提示信息。In some instances, the processor 11 in this embodiment is configured to execute: when at least one target subspace below each target memory space in the at least one target memory space is not determined according to the subspace lookup table, generate a Second prompt information identifying failure of subspace allocation.
在一些实例中,在根据子空间查找表,确定至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间之后,本实施例中的处理器11用于执行:对子空间查找表中所包括的至少一个目标子空间的子空间分配状态标识进行置位,以标识至少一个目标子空间的子空间分配状态为已分配状态。In some instances, after determining at least one target subspace below each target memory space in the at least one target memory space according to the subspace lookup table, the processor 11 in this embodiment is configured to execute: The subspace allocation status flag of the at least one target subspace included in the subspace is set to indicate that the subspace allocation status of the at least one target subspace is an allocated state.
在一些实例中,在基于内存分配请求获取子空间查找表之前,本实施例中的处理器11用于执行:根据内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息;基于划分配置信息将内存空间划分为多个子空间,并生成与多个子空间相对应的子空间查找表。In some instances, before acquiring the subspace lookup table based on the memory allocation request, the processor 11 in this embodiment is configured to perform: according to the memory allocation request, determine division configuration information for performing a space division operation on the memory space; based on the memory allocation request; The division configuration information divides the memory space into a plurality of subspaces, and generates a subspace lookup table corresponding to the plurality of subspaces.
在一些实例中,划分配置信息包括以下至少之一:划分数量、划分区域大小、划分地址信息。In some instances, the division configuration information includes at least one of the following: division quantity, division area size, division address information.
在一些实例中,同一个内存空间内所包括的多个子空间所对应的空间区域大小相同或不同。In some instances, the space regions corresponding to multiple subspaces included in the same memory space have the same size or different sizes.
在一些实例中,在处理器11根据内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息时,该处理器11用于执行:获取与内存分配请求相对应的至少一个运算数据长度;在至少一个运算数据长度中,获得最大的目标运算数据长度;基于目标运算数据长度,确定用于对内存空间进行空间划分操作的划分配置信息。In some instances, when the processor 11 determines the division configuration information for performing a space division operation on the memory space according to the memory allocation request, the processor 11 is configured to execute: acquiring at least one operation data corresponding to the memory allocation request length; in at least one operation data length, the maximum target operation data length is obtained; based on the target operation data length, the division configuration information for performing the space division operation on the memory space is determined.
在一些实例中,划分配置信息包括:划分数量;在处理器11基于目标运算数据长度,确定用于对内存空间进行空间划分操作的划分配置信息时,该处理器11用于执行:获取内存空间的总区域大小;基于总区域大小与目标运算数据长度之间的比值,确定用于对内存空间进行空间划分操作的划分数量。In some instances, the division configuration information includes: the number of divisions; when the processor 11 determines the division configuration information for performing a space division operation on the memory space based on the target operation data length, the processor 11 is configured to execute: obtain the memory space The total area size of ; based on the ratio between the total area size and the target operation data length, determine the number of divisions used for space division operations on the memory space.
在一些实例中,本实施例中的处理器11用于执行:获取内存释放请求;根据内存释放请求,确定待释放的内存空间以及位于内存空间内待释放的子空间;对内存空间和子空间进行释放操作。In some instances, the processor 11 in this embodiment is configured to perform: acquiring a memory release request; determining the memory space to be released and the subspace to be released in the memory space according to the memory release request; release operation.
在一些实例中,对内存空间和子空间进行释放操作之后,本实施例中的处理器11用于执行:对与内存空间相对应的内存互斥表中已释放的内存空间的空间分配状态进行复位,以标识已释放的内存空间为未分配状态;对与子空间相对应的子空间查找表中已释放的子空间的子空间分配状态进行置位,以标识已释放的子空间为未分配状态。In some instances, after the memory space and the subspace are released, the processor 11 in this embodiment is configured to perform: reset the space allocation state of the released memory space in the memory mutex table corresponding to the memory space , to identify the released memory space as unallocated; set the subspace allocation status of the released subspace in the subspace lookup table corresponding to the subspace to identify the released subspace as unallocated .
图13所示装置可以执行图3-图12所示实施例的方法,本实施例未详细描述的部分,可参考对图3-图12所示实施例的相关说明。该技术方案的执行过程和技术效果参见图3-图12所示实施例中的描述,在此不再赘述。The apparatus shown in FIG. 13 can execute the method of the embodiment shown in FIG. 3-FIG. 12. For parts not described in detail in this embodiment, reference may be made to the related description of the embodiment shown in FIG. 3-FIG. 12. For the execution process and technical effect of the technical solution, refer to the descriptions in the embodiments shown in FIG. 3 to FIG. 12 , which will not be repeated here.
另外,本发明实施例提供了一种计算机存储介质,用于储存电子设备 所用的计算机软件指令,其包含用于执行上述图3-图12所示方法实施例中内存空间的分配方法所涉及的程序。In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions used by an electronic device, which includes the memory space allocation method involved in executing the method embodiment shown in FIG. 3-FIG. 12 above. program.
以上各个实施例中的技术方案、技术特征在与本相冲突的情况下均可以单独,或者进行组合,只要未超出本领域技术人员的认知范围,均属于本申请保护范围内的等同实施例。The technical solutions and technical features in the above embodiments can be used alone or combined in the case of conflict with the present invention, as long as they do not exceed the cognitive scope of those skilled in the art, they all belong to the equivalent embodiments within the protection scope of the present application .
在本发明所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present invention, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the device embodiments described above are only illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be Incorporation may either be integrated into another system, or some features may be omitted, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得计算机处理器(processor)执行本发明 各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁盘或者光盘等各种可以存储程序代码的介质。The integrated unit, if implemented in the form of a software functional unit and sold or used as an independent product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions for causing a computer processor (processor) to perform all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes.
以上所述仅为本发明的实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above descriptions are only the embodiments of the present invention, and are not intended to limit the scope of the present invention. Any equivalent structure or equivalent process transformation made by using the contents of the description and drawings of the present invention, or directly or indirectly applied to other related technologies Fields are similarly included in the scope of patent protection of the present invention.
最后应说明的是:以上各实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述各实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: The technical solutions described in the foregoing embodiments can still be modified, or some or all of the technical features thereof can be equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the technical solutions of the embodiments of the present invention. scope.

Claims (37)

  1. 一种内存空间的分配方法,其特征在于,包括:A method for allocating memory space, comprising:
    获取针对离散化内存空间的内存分配请求;Get the memory allocation request for the discretized memory space;
    在所述离散化内存空间中,确定与所述内存分配请求相对应的至少一个目标内存空间,所述目标内存空间为未分配状态,且所述至少一个目标内存空间中的任意两个目标内存空间之间互斥;In the discretized memory space, at least one target memory space corresponding to the memory allocation request is determined, the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are in an unallocated state. mutual exclusion between spaces;
    根据所述内存分配请求,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所述目标子空间为未分配状态,且所述至少一个目标子空间中的任意两个子空间之间互斥。According to the memory allocation request, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and any target subspace in the at least one target subspace is in an unallocated state. The two subspaces are mutually exclusive.
  2. 根据权利要求1所述的方法,其特征在于,所述至少一个目标内存空间中每个目标内存空间中的地址信息连续,且至少一个目标内存空间中任意两个目标内存空间之间的地址信息离散。The method according to claim 1, wherein the address information in each target memory space in the at least one target memory space is continuous, and the address information between any two target memory spaces in the at least one target memory space is discrete.
  3. 根据权利要求1所述的方法,其特征在于,在所述离散化内存空间中,确定与所述内存分配请求相对应的至少一个目标内存空间,包括:The method according to claim 1, wherein, in the discretized memory space, determining at least one target memory space corresponding to the memory allocation request, comprising:
    基于所述内存分配请求获取内存互斥表,所述内存互斥表中包括:在所述离散化内存空间中的待分配内存空间以及待分配内存空间的空间分配状态;A memory mutual exclusion table is obtained based on the memory allocation request, and the memory mutual exclusion table includes: the memory space to be allocated in the discretized memory space and the space allocation status of the memory space to be allocated;
    在所述离散化内存空间中,根据所述内存互斥表确定与所述内存分配请求相对应的至少一个目标内存空间。In the discretized memory space, at least one target memory space corresponding to the memory allocation request is determined according to the memory mutual exclusion table.
  4. 根据权利要求3所述的方法,其特征在于,在所述离散化内存空间中,根据所述内存互斥表确定与所述内存分配请求相对应的至少一个目标内存空间,包括:The method according to claim 3, wherein, in the discretized memory space, determining at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table, comprising:
    确定与所述内存分配请求相对应的请求空间大小;determining a requested space size corresponding to the memory allocation request;
    在所述离散化内存空间中,按照预设分配顺序识别出与所述请求空间大小相对应的未分配的至少一个内存空间;In the discretized memory space, identify at least one unallocated memory space corresponding to the size of the requested space according to a preset allocation sequence;
    将上述所确定的未分配的至少一个内存空间确定为与所述内存分配请求相对应的至少一个目标内存空间。Determine the at least one unallocated memory space determined above as at least one target memory space corresponding to the memory allocation request.
  5. 根据权利要求4所述的方法,其特征在于,所述方法还包括:The method according to claim 4, wherein the method further comprises:
    在所述离散化内存空间中,未识别出与所述请求空间大小相对应的未分配的至少一个内存空间时,则生成用于标识内存空间分配失败的第一提示信息。In the discretized memory space, when at least one unallocated memory space corresponding to the requested space size is not identified, first prompt information for identifying memory space allocation failure is generated.
  6. 根据权利要求3所述的方法,其特征在于,在根据所述内存互斥表确定与所述内存分配请求相对应的至少一个目标内存空间之后,所述方法还包括:The method according to claim 3, wherein after determining at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table, the method further comprises:
    对所述内存互斥表中所包括的至少一个目标内存空间的空间分配状态进行复位,以标识至少一个目标内存空间的空间分配状态为未分配状态。The space allocation state of the at least one target memory space included in the memory mutual exclusion table is reset to identify the space allocation state of the at least one target memory space as an unallocated state.
  7. 根据权利要求1所述的方法,其特征在于,根据所述内存分配请求,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,包括:The method according to claim 1, wherein determining, according to the memory allocation request, at least one target subspace below each target memory space in the at least one target memory space, comprising:
    基于所述内存分配请求获取子空间查找表,所述子空间查找表中包括:待分配子空间以及待分配子空间的子空间分配状态;Obtain a subspace lookup table based on the memory allocation request, where the subspace lookup table includes: the subspace to be allocated and the subspace allocation status of the subspace to be allocated;
    根据所述子空间查找表,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所述目标子空间为未分配状态,且所述至少一个目标子空间中的任意两个子空间之间互斥。According to the subspace lookup table, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and the at least one target subspace is in an unallocated state. Any two subspaces are mutually exclusive.
  8. 根据权利要求7所述的方法,其特征在于,根据所述子空间查找表,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,包括:The method according to claim 7, wherein determining, according to the subspace lookup table, at least one target subspace below each target memory space in the at least one target memory space, comprising:
    确定与所述内存分配请求相对应的请求子空间大小;determining the size of the request subspace corresponding to the memory allocation request;
    在所述至少一个目标内存空间中每个目标内存空间中,根据所述子空间查找表采用位搜索的方式,识别出与所述请求子空间大小相对应的未分配的至少一个子空间;In each target memory space in the at least one target memory space, use a bit search method according to the subspace lookup table to identify at least one unallocated subspace corresponding to the size of the requested subspace;
    将上述所确定的未分配的至少一个子空间确定为与所述内存分配请求相对应的至少一个目标子空间。The determined unallocated at least one subspace is determined as at least one target subspace corresponding to the memory allocation request.
  9. 根据权利要求8所述的方法,其特征在于,所述子空间查找表所对应的空间区域大小小于或等于所对应的目标内存空间的空间区域大小。The method according to claim 8, wherein the size of the space region corresponding to the subspace lookup table is less than or equal to the size of the space region of the corresponding target memory space.
  10. 根据权利要求7所述的方法,其特征在于,所述方法还包括:The method according to claim 7, wherein the method further comprises:
    在根据所述子空间查找表,未确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,则生成用于标识子空间分配失败的第二提示信息。When at least one target subspace below each target memory space in the at least one target memory space is not determined according to the subspace lookup table, second prompt information for identifying a subspace allocation failure is generated.
  11. 根据权利要求7所述的方法,其特征在于,在根据所述子空间查找表,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间之后,所述方法还包括:The method according to claim 7, characterized in that, after determining at least one target subspace below each target memory space in the at least one target memory space according to the subspace lookup table, the method further comprises: :
    对所述子空间查找表中所包括的至少一个目标子空间的子空间分配状态标识进行置位,以标识至少一个目标子空间的子空间分配状态为已分配状态。The subspace allocation status flag of the at least one target subspace included in the subspace lookup table is set to identify the subspace allocation status of the at least one target subspace as an allocated state.
  12. 根据权利要求7所述的方法,其特征在于,在基于所述内存分配请求获取子空间查找表之前,所述方法还包括:The method according to claim 7, wherein before acquiring the subspace lookup table based on the memory allocation request, the method further comprises:
    根据所述内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息;determining, according to the memory allocation request, division configuration information for performing a space division operation on the memory space;
    基于所述划分配置信息将所述内存空间划分为多个子空间,并生成与所述多个子空间相对应的子空间查找表。The memory space is divided into a plurality of subspaces based on the division configuration information, and a subspace lookup table corresponding to the plurality of subspaces is generated.
  13. 根据权利要求12所述的方法,其特征在于,所述划分配置信息包括以下至少之一:划分数量、划分区域大小、划分地址信息。The method according to claim 12, wherein the division configuration information includes at least one of the following: division quantity, division area size, and division address information.
  14. 根据权利要求12所述的方法,其特征在于,同一个内存空间内所包括的所述多个子空间所对应的空间区域大小相同或不同。The method according to claim 12, wherein the size of the space regions corresponding to the multiple subspaces included in the same memory space is the same or different.
  15. 根据权利要求12所述的方法,其特征在于,根据所述内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息,包括:The method according to claim 12, wherein determining, according to the memory allocation request, division configuration information for performing a space division operation on the memory space, comprising:
    获取与所述内存分配请求相对应的至少一个运算数据长度;obtaining at least one operation data length corresponding to the memory allocation request;
    在所述至少一个运算数据长度中,获得最大的目标运算数据长度;In the at least one operation data length, obtain the maximum target operation data length;
    基于所述目标运算数据长度,确定用于对内存空间进行空间划分操作的 划分配置信息。Based on the length of the target operation data, the division configuration information for performing the space division operation on the memory space is determined.
  16. 根据权利要求15所述的方法,其特征在于,所述划分配置信息包括:划分数量;基于所述目标运算数据长度,确定用于对内存空间进行空间划分操作的划分配置信息,包括:The method according to claim 15, wherein the division configuration information comprises: division quantity; and based on the target operation data length, determining the division configuration information for performing a space division operation on the memory space, comprising:
    获取所述内存空间的总区域大小;Obtain the total area size of the memory space;
    基于所述总区域大小与所述目标运算数据长度之间的比值,确定用于对内存空间进行空间划分操作的划分数量。Based on the ratio between the size of the total area and the length of the target operation data, the number of divisions used to perform a space division operation on the memory space is determined.
  17. 根据权利要求1-16中任意一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-16, wherein the method further comprises:
    获取内存释放请求;Get a memory release request;
    根据所述内存释放请求,确定待释放的内存空间以及位于所述内存空间内待释放的子空间;According to the memory release request, determine the memory space to be released and the subspace to be released in the memory space;
    对所述内存空间和所述子空间进行释放操作。A release operation is performed on the memory space and the subspace.
  18. 根据权利要求17所述的方法,其特征在于,对所述内存空间和所述子空间进行释放操作之后,所述方法还包括:The method according to claim 17, wherein after the release operation is performed on the memory space and the subspace, the method further comprises:
    对与所述内存空间相对应的内存互斥表中已释放的内存空间的空间分配状态进行复位,以标识已释放的内存空间为未分配状态;Reset the space allocation state of the released memory space in the memory mutual exclusion table corresponding to the memory space to identify the released memory space as an unallocated state;
    对与所述子空间相对应的子空间查找表中已释放的子空间的子空间分配状态进行置位,以标识已释放的子空间为未分配状态。The subspace allocation state of the released subspace in the subspace lookup table corresponding to the subspace is set to identify the released subspace as an unallocated state.
  19. 一种内存空间的分配装置,其特征在于,包括:A device for allocating memory space, comprising:
    存储器,用于存储计算机程序;memory for storing computer programs;
    处理器,用于运行所述存储器中存储的计算机程序以实现:A processor for running a computer program stored in the memory to achieve:
    获取针对离散化内存空间的内存分配请求;Get the memory allocation request for the discretized memory space;
    在所述离散化内存空间中,确定与所述内存分配请求相对应的至少一个目标内存空间,所述目标内存空间为未分配状态,且所述至少一个目标内存空间中的任意两个目标内存空间之间互斥;In the discretized memory space, at least one target memory space corresponding to the memory allocation request is determined, the target memory space is in an unallocated state, and any two target memory spaces in the at least one target memory space are in an unallocated state. mutual exclusion between spaces;
    根据所述内存分配请求,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所述目标子空间为未分配状态,且所述至少一个目标子空间中的任意两个子空间之间互斥。According to the memory allocation request, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and any target subspace in the at least one target subspace is in an unallocated state. The two subspaces are mutually exclusive.
  20. 根据权利要求19所述的装置,其特征在于,所述至少一个目标内存空间中每个目标内存空间中的地址信息连续,且至少一个目标内存空间中任意两个目标内存空间之间的地址信息离散。The device according to claim 19, wherein the address information in each target memory space in the at least one target memory space is continuous, and the address information between any two target memory spaces in the at least one target memory space is discrete.
  21. 根据权利要求19所述的装置,其特征在于,在所述处理器在所述离散化内存空间中,确定与所述内存分配请求相对应的至少一个目标内存空间时,所述处理器用于:The apparatus according to claim 19, wherein when the processor determines at least one target memory space corresponding to the memory allocation request in the discretized memory space, the processor is configured to:
    基于所述内存分配请求获取内存互斥表,所述内存互斥表中包括:在所述离散化内存空间中的待分配内存空间以及待分配内存空间的空间分配状态;A memory mutual exclusion table is obtained based on the memory allocation request, and the memory mutual exclusion table includes: the memory space to be allocated in the discretized memory space and the space allocation status of the memory space to be allocated;
    在所述离散化内存空间中,根据所述内存互斥表确定与所述内存分配请求相对应的至少一个目标内存空间。In the discretized memory space, at least one target memory space corresponding to the memory allocation request is determined according to the memory mutual exclusion table.
  22. 根据权利要求21所述的装置,其特征在于,在所述处理器在所述离散化内存空间中,根据所述内存互斥表确定与所述内存分配请求相对应的至少一个目标内存空间时,所述处理器用于:The apparatus according to claim 21, wherein when the processor determines at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table in the discretized memory space , the processor is used to:
    确定与所述内存分配请求相对应的请求空间大小;determining the requested space size corresponding to the memory allocation request;
    在所述离散化内存空间中,按照预设分配顺序识别出与所述请求空间大小相对应的未分配的至少一个内存空间;In the discretized memory space, identify at least one unallocated memory space corresponding to the requested space size according to a preset allocation sequence;
    将上述所确定的未分配的至少一个内存空间确定为与所述内存分配请求相对应的至少一个目标内存空间。Determine the at least one unallocated memory space determined above as at least one target memory space corresponding to the memory allocation request.
  23. 根据权利要求22所述的装置,其特征在于,所述处理器还用于:The apparatus of claim 22, wherein the processor is further configured to:
    在所述离散化内存空间中,未识别出与所述请求空间大小相对应的未分配的至少一个内存空间时,则生成用于标识内存空间分配失败的第一提示信息。In the discretized memory space, when at least one unallocated memory space corresponding to the requested space size is not identified, first prompt information for identifying memory space allocation failure is generated.
  24. 根据权利要求21所述的装置,其特征在于,在根据所述内存互斥表 确定与所述内存分配请求相对应的至少一个目标内存空间之后,所述处理器还用于:The device according to claim 21, wherein after determining at least one target memory space corresponding to the memory allocation request according to the memory mutual exclusion table, the processor is further configured to:
    对所述内存互斥表中所包括的至少一个目标内存空间的空间分配状态进行复位,以标识至少一个目标内存空间的空间分配状态为未分配状态。The space allocation state of at least one target memory space included in the memory mutual exclusion table is reset to identify the space allocation state of the at least one target memory space as an unallocated state.
  25. 根据权利要求19所述的装置,其特征在于,在所述处理器根据所述内存分配请求,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,所述处理器用于:The apparatus according to claim 19, wherein when the processor determines, according to the memory allocation request, at least one target subspace below each target memory space in the at least one target memory space, the The processor is used to:
    基于所述内存分配请求获取子空间查找表,所述子空间查找表中包括:待分配子空间以及待分配子空间的子空间分配状态;Obtain a subspace lookup table based on the memory allocation request, where the subspace lookup table includes: the subspace to be allocated and the subspace allocation status of the subspace to be allocated;
    根据所述子空间查找表,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间,所述目标子空间为未分配状态,且所述至少一个目标子空间中的任意两个子空间之间互斥。According to the subspace lookup table, determine at least one target subspace below each target memory space in the at least one target memory space, the target subspace is in an unallocated state, and the at least one target subspace in the at least one target subspace is in an unallocated state. Any two subspaces are mutually exclusive.
  26. 根据权利要求25所述的装置,其特征在于,在所述处理器根据所述子空间查找表,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,所述处理器用于:The apparatus according to claim 25, wherein when the processor determines, according to the subspace lookup table, at least one target subspace at a lower level of each target memory space in the at least one target memory space, the The processor described above is used to:
    确定与所述内存分配请求相对应的请求子空间大小;determining the size of the request subspace corresponding to the memory allocation request;
    在所述至少一个目标内存空间中每个目标内存空间中,根据所述子空间查找表采用位搜索的方式,识别出与所述请求子空间大小相对应的未分配的至少一个子空间;In each target memory space in the at least one target memory space, using a bit search method according to the subspace lookup table, identify at least one unallocated subspace corresponding to the size of the requested subspace;
    将上述所确定的未分配的至少一个子空间确定为与所述内存分配请求相对应的至少一个目标子空间。The determined unallocated at least one subspace is determined as at least one target subspace corresponding to the memory allocation request.
  27. 根据权利要求26所述的装置,其特征在于,所述子空间查找表所对应的空间区域大小小于或等于所对应的目标内存空间的空间区域大小。The apparatus according to claim 26, wherein the size of the space area corresponding to the subspace lookup table is less than or equal to the size of the space area of the corresponding target memory space.
  28. 根据权利要求25所述的装置,其特征在于,所述处理器还用于:The apparatus of claim 25, wherein the processor is further configured to:
    在根据所述子空间查找表,未确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间时,则生成用于标识子空间分配失败 的第二提示信息。When at least one target subspace below each target memory space in the at least one target memory space is not determined according to the subspace lookup table, second prompt information for identifying a subspace allocation failure is generated.
  29. 根据权利要求25所述的装置,其特征在于,在根据所述子空间查找表,确定所述至少一个目标内存空间中每个目标内存空间下层的至少一个目标子空间之后,所述处理器还用于:The apparatus according to claim 25, wherein after determining, according to the subspace lookup table, at least one target subspace at a lower level of each target memory space in the at least one target memory space, the processor further Used for:
    对所述子空间查找表中所包括的至少一个目标子空间的子空间分配状态标识进行置位,以标识至少一个目标子空间的子空间分配状态为已分配状态。The subspace allocation status flag of the at least one target subspace included in the subspace lookup table is set to identify the subspace allocation status of the at least one target subspace as an allocated state.
  30. 根据权利要求25所述的装置,其特征在于,在基于所述内存分配请求获取子空间查找表之前,所述处理器还用于:The apparatus according to claim 25, wherein before acquiring the subspace lookup table based on the memory allocation request, the processor is further configured to:
    根据所述内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息;determining, according to the memory allocation request, division configuration information for performing a space division operation on the memory space;
    基于所述划分配置信息将所述内存空间划分为多个子空间,并生成与所述多个子空间相对应的子空间查找表。The memory space is divided into a plurality of subspaces based on the division configuration information, and a subspace lookup table corresponding to the plurality of subspaces is generated.
  31. 根据权利要求30所述的装置,其特征在于,所述划分配置信息包括以下至少之一:划分数量、划分区域大小、划分地址信息。The apparatus according to claim 30, wherein the division configuration information includes at least one of the following: division quantity, division area size, and division address information.
  32. 根据权利要求30所述的装置,其特征在于,同一个内存空间内所包括的所述多个子空间所对应的空间区域大小相同或不同。The apparatus according to claim 30, wherein the size of the space regions corresponding to the plurality of subspaces included in the same memory space is the same or different.
  33. 根据权利要求30所述的装置,其特征在于,在所述处理器根据所述内存分配请求,确定用于对内存空间进行空间划分操作的划分配置信息时,所述处理器用于:The apparatus according to claim 30, wherein when the processor determines, according to the memory allocation request, division configuration information for performing a space division operation on the memory space, the processor is configured to:
    获取与所述内存分配请求相对应的至少一个运算数据长度;obtaining at least one operation data length corresponding to the memory allocation request;
    在所述至少一个运算数据长度中,获得最大的目标运算数据长度;In the at least one operation data length, obtain the maximum target operation data length;
    基于所述目标运算数据长度,确定用于对内存空间进行空间划分操作的划分配置信息。Based on the target operation data length, the division configuration information for performing the space division operation on the memory space is determined.
  34. 根据权利要求33所述的装置,其特征在于,所述划分配置信息包括:划分数量;在所述处理器基于所述目标运算数据长度,确定用于对内存空间进行空间划分操作的划分配置信息时,所述处理器用于:The apparatus according to claim 33, wherein the division configuration information comprises: a division quantity; and the processor determines, based on the target operation data length, division configuration information for performing a space division operation on the memory space , the processor is used to:
    获取所述内存空间的总区域大小;Obtain the total area size of the memory space;
    基于所述总区域大小与所述目标运算数据长度之间的比值,确定用于对内存空间进行空间划分操作的划分数量。Based on the ratio between the size of the total area and the length of the target operation data, the number of divisions used to perform the space division operation on the memory space is determined.
  35. 根据权利要求19-34中任意一项所述的装置,其特征在于,所述处理器用于:The apparatus according to any one of claims 19-34, wherein the processor is configured to:
    获取内存释放请求;Get a memory release request;
    根据所述内存释放请求,确定待释放的内存空间以及位于所述内存空间内待释放的子空间;According to the memory release request, determine the memory space to be released and the subspace to be released in the memory space;
    对所述内存空间和所述子空间进行释放操作。A release operation is performed on the memory space and the subspace.
  36. 根据权利要求35所述的装置,其特征在于,对所述内存空间和所述子空间进行释放操作之后,所述处理器用于:The apparatus according to claim 35, wherein after the release operation is performed on the memory space and the subspace, the processor is configured to:
    对与所述内存空间相对应的内存互斥表中已释放的内存空间的空间分配状态进行复位,以标识已释放的内存空间为未分配状态;Reset the space allocation state of the released memory space in the memory mutual exclusion table corresponding to the memory space to identify the released memory space as an unallocated state;
    对与所述子空间相对应的子空间查找表中已释放的子空间的子空间分配状态进行置位,以标识已释放的子空间为未分配状态。The subspace allocation state of the released subspace in the subspace lookup table corresponding to the subspace is set to identify the released subspace as an unallocated state.
  37. 一种计算机可读存储介质,其特征在于,所述存储介质为计算机可读存储介质,该计算机可读存储介质中存储有程序指令,所述程序指令用于实现权利要求1-18中任意一项所述的内存空间的分配方法。A computer-readable storage medium, characterized in that the storage medium is a computer-readable storage medium, and program instructions are stored in the computer-readable storage medium, and the program instructions are used to implement any one of claims 1-18 The allocation method of the memory space described in the item.
PCT/CN2020/134258 2020-12-07 2020-12-07 Memory space allocation method and device, and storage medium WO2022120522A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202080067360.7A CN114556309A (en) 2020-12-07 2020-12-07 Memory space allocation method and device and storage medium
PCT/CN2020/134258 WO2022120522A1 (en) 2020-12-07 2020-12-07 Memory space allocation method and device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/134258 WO2022120522A1 (en) 2020-12-07 2020-12-07 Memory space allocation method and device, and storage medium

Publications (1)

Publication Number Publication Date
WO2022120522A1 true WO2022120522A1 (en) 2022-06-16

Family

ID=81668400

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/134258 WO2022120522A1 (en) 2020-12-07 2020-12-07 Memory space allocation method and device, and storage medium

Country Status (2)

Country Link
CN (1) CN114556309A (en)
WO (1) WO2022120522A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115617531A (en) * 2022-11-16 2023-01-17 沐曦集成电路(上海)有限公司 Method, device, storage medium and equipment for rapidly detecting discrete resources
CN117311997A (en) * 2023-11-29 2023-12-29 苏州元脑智能科技有限公司 Memory management method and device of computing chip and computing chip

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115933994B (en) * 2023-01-09 2023-07-14 苏州浪潮智能科技有限公司 Data processing method and device, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040049650A1 (en) * 2002-09-11 2004-03-11 Jing Ling Dynamic memory allocation for packet interfaces
CN103455433A (en) * 2013-08-19 2013-12-18 曙光信息产业股份有限公司 Memory management method and system
US20140095812A1 (en) * 2012-09-28 2014-04-03 Appli Inc. Obfuscating function resources while reducing stack consumption
CN104182356A (en) * 2014-09-19 2014-12-03 深圳市茁壮网络股份有限公司 Memory management method and device and terminal device
CN106502918A (en) * 2016-09-19 2017-03-15 上海华为技术有限公司 A kind of scheduling memory method and device
CN111475299A (en) * 2020-04-03 2020-07-31 Oppo广东移动通信有限公司 Memory allocation method and device, storage medium and electronic equipment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040049650A1 (en) * 2002-09-11 2004-03-11 Jing Ling Dynamic memory allocation for packet interfaces
US20140095812A1 (en) * 2012-09-28 2014-04-03 Appli Inc. Obfuscating function resources while reducing stack consumption
CN103455433A (en) * 2013-08-19 2013-12-18 曙光信息产业股份有限公司 Memory management method and system
CN104182356A (en) * 2014-09-19 2014-12-03 深圳市茁壮网络股份有限公司 Memory management method and device and terminal device
CN106502918A (en) * 2016-09-19 2017-03-15 上海华为技术有限公司 A kind of scheduling memory method and device
CN111475299A (en) * 2020-04-03 2020-07-31 Oppo广东移动通信有限公司 Memory allocation method and device, storage medium and electronic equipment

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115617531A (en) * 2022-11-16 2023-01-17 沐曦集成电路(上海)有限公司 Method, device, storage medium and equipment for rapidly detecting discrete resources
CN115617531B (en) * 2022-11-16 2023-04-28 沐曦集成电路(上海)有限公司 Method, device, storage medium and equipment for rapidly detecting discrete resources
CN117311997A (en) * 2023-11-29 2023-12-29 苏州元脑智能科技有限公司 Memory management method and device of computing chip and computing chip
CN117311997B (en) * 2023-11-29 2024-02-23 苏州元脑智能科技有限公司 Memory management method and device of computing chip and computing chip

Also Published As

Publication number Publication date
CN114556309A (en) 2022-05-27

Similar Documents

Publication Publication Date Title
WO2022120522A1 (en) Memory space allocation method and device, and storage medium
US11082206B2 (en) Layout-independent cryptographic stamp of a distributed dataset
CN110663019B (en) File system for Shingled Magnetic Recording (SMR)
US8381230B2 (en) Message passing with queues and channels
WO2017107414A1 (en) File operation method and device
KR102290540B1 (en) Namespace/Stream Management
CN110858162B (en) Memory management method and device and server
WO2019001020A1 (en) Storage space arrangement method, apparatus, and system based on distributed system
CN103577345A (en) Methods and structure for improved flexibility in shared storage caching by multiple systems
EP2583181A2 (en) Hierarchical allocation for file system storage device
US10824555B2 (en) Method and system for flash-aware heap memory management wherein responsive to a page fault, mapping a physical page (of a logical segment) that was previously reserved in response to another page fault for another page in the first logical segment
CN107533435B (en) Storage space allocation method and storage equipment
US10310986B1 (en) Memory management unit for shared memory allocation
JP7467593B2 (en) Resource allocation method, storage device, and storage system - Patents.com
WO2015085826A1 (en) Method and apparatus for accessing shared resource
CN107408132B (en) Method and system for moving hierarchical data objects across multiple types of storage
US8543722B2 (en) Message passing with queues and channels
US20140289739A1 (en) Allocating and sharing a data object among program instances
US9697048B2 (en) Non-uniform memory access (NUMA) database management system
US10152258B1 (en) Big block allocation of persistent main memory
US11474938B2 (en) Data storage system with multiple-size object allocator for disk cache
CN115712500A (en) Memory release method, memory recovery method, memory release device, memory recovery device, computer equipment and storage medium
US10168911B1 (en) Defragmentation of persistent main memory
CN114090249A (en) Resource allocation method, device, electronic equipment and storage medium
CN113672171A (en) Distributed object storage method, device and system and metadata server

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20964469

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20964469

Country of ref document: EP

Kind code of ref document: A1