[go: up one dir, main page]

CN105808219A - Memory space allocation method and apparatus - Google Patents

Memory space allocation method and apparatus Download PDF

Info

Publication number
CN105808219A
CN105808219A CN201410849680.4A CN201410849680A CN105808219A CN 105808219 A CN105808219 A CN 105808219A CN 201410849680 A CN201410849680 A CN 201410849680A CN 105808219 A CN105808219 A CN 105808219A
Authority
CN
China
Prior art keywords
programming language
language layer
layer
memory
data
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN201410849680.4A
Other languages
Chinese (zh)
Other versions
CN105808219B (en
Inventor
严欣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
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 China Mobile Communications Group Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN201410849680.4A priority Critical patent/CN105808219B/en
Publication of CN105808219A publication Critical patent/CN105808219A/en
Application granted granted Critical
Publication of CN105808219B publication Critical patent/CN105808219B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Memory System (AREA)

Abstract

本发明涉及计算机技术领域,尤其涉及一种内存空间分配方法及装置,用以突破应用程序的内存限制,提高应用程序的可用内存。本发明实施例提供的内存空间分配方法应用于安装有Android操作系统的终端,包括:在运行应用的过程中,生成第一编程语言层(Java层)的待存储数据;在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,为所述待存储数据分配基于第二编程语言层(Native层)的内存空间;在所述第二编程语言层,将所述待存储数据写入分配的所述内存空间。这样,当应用在第一编程语言层的可用内存占比低于设定阈值后,可在第二编程语言层为该应用分配内存空间,从而减少了发生内存耗尽的几率。

The invention relates to the field of computer technology, in particular to a method and device for allocating memory space, which are used to break through the memory limitation of application programs and increase the available memory of application programs. The memory space allocation method provided by the embodiment of the present invention is applied to a terminal installed with an Android operating system, including: generating data to be stored in the first programming language layer (Java layer) during the process of running the application; After the proportion of the memory that can be used by the first programming language layer is lower than the set threshold, the memory space based on the second programming language layer (Native layer) is allocated for the data to be stored; at the second programming language layer, the The data to be stored is written into the allocated memory space. In this way, when the available memory ratio of the application in the first programming language layer is lower than the set threshold, memory space can be allocated for the application in the second programming language layer, thereby reducing the probability of memory exhaustion.

Description

一种内存空间分配方法及装置Method and device for allocating memory space

技术领域technical field

本发明涉及计算机技术领域,尤其涉及一种内存空间分配方法及装置。The invention relates to the technical field of computers, in particular to a memory space allocation method and device.

背景技术Background technique

目前,安卓(Android)应用程序在运行中是基于Java语言层进行数据存储的,在该语言层进行数据存储时会有一定的内存限制,一般限制大小为16MB或24MB。当应用程序涉及到多媒体资源的资源处理时,会消耗大量的内存资源,很容易超过该内存限制,引发应用程序可用内存耗尽(OutOfMemory,OOM),导致程序异常退出。At present, Android (Android) applications store data based on the Java language layer during operation. There is a certain memory limit when data is stored in this language layer, and the general size limit is 16MB or 24MB. When the application program involves resource processing of multimedia resources, it will consume a large amount of memory resources, and it is easy to exceed the memory limit, causing the application program to run out of available memory (OutOfMemory, OOM), causing the program to exit abnormally.

现有的解决方案一般采用缓存、压缩图像、降低图像质量等手段来减少内存占用。这些减少内存占用的方式都是基于对应用程序输出的待存储数据进行处理来实现的,无法从本质上提高应用程序的可用内存。Existing solutions generally use methods such as caching, compressing images, and reducing image quality to reduce memory usage. These methods of reducing memory usage are all based on processing the data to be stored output by the application program, and cannot essentially improve the available memory of the application program.

发明内容Contents of the invention

本发明实施例提供一种内存空间分配方法及装置,用以突破应用程序的内存限制,提高应用程序的可用内存。Embodiments of the present invention provide a method and device for allocating memory space, which are used to break through the memory limitation of application programs and increase the available memory of application programs.

本发明实施例提供一种内存空间分配方法,该方法应用于安装有安卓Android操作系统的终端,包括:The embodiment of the present invention provides a memory space allocation method, the method is applied to a terminal installed with an Android operating system, including:

在运行应用的过程中,生成第一编程语言层的待存储数据;所述第一编程语言层为Java层;In the process of running the application, the data to be stored in the first programming language layer is generated; the first programming language layer is the Java layer;

在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,为所述待存储数据分配基于第二编程语言层的内存空间;所述第二编程语言层为Native层;After determining that the proportion of memory currently available to the application at the first programming language layer is lower than a set threshold, allocate a memory space based on a second programming language layer for the data to be stored; the second programming language layer is Native layer;

在所述第二编程语言层,将所述待存储数据写入分配的所述内存空间。At the second programming language layer, write the data to be stored into the allocated memory space.

可选地,在所述第二编程语言层,将所述待存储数据写入分配的所述内存空间之后,还包括:Optionally, at the second programming language layer, after writing the data to be stored into the allocated memory space, it further includes:

在所述第二编程语言层,将分配的所述内存空间转换为字符串形式的句柄反馈到第一编程语言层,并保存该句柄与所述内存空间的对应关系;At the second programming language layer, the allocated memory space is converted into a character string handle and fed back to the first programming language layer, and the corresponding relationship between the handle and the memory space is saved;

在所述第一编程语言层,当需要从内存中读取所述待存储数据时,将包括所述句柄的内存访问指令指示给所述第二编程语言层;In the first programming language layer, when the data to be stored needs to be read from the memory, indicate the memory access instruction including the handle to the second programming language layer;

在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,将所述句柄对应的内存空间中的数据反馈到所述第一编程语言层。At the second programming language layer, according to the stored correspondence between the handle and the memory space, the data in the memory space corresponding to the handle is fed back to the first programming language layer.

可选地,将所述句柄对应的内存空间中的数据反馈到所述第一编程语言层之后,还包括:Optionally, after feeding back the data in the memory space corresponding to the handle to the first programming language layer, the method further includes:

在所述第一编程语言层,将包括所述句柄的内存释放指令指示给所述第二编程语言层;Indicating, at the first programming language layer, a memory release instruction including the handle to the second programming language layer;

在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,删除所述句柄对应的内存空间中的数据。In the second programming language layer, delete the data in the memory space corresponding to the handle according to the stored correspondence between the handle and the memory space.

可选地,在所述第二编程语言层,将所述待存储数据写入分配的所述内存空间,包括:Optionally, at the second programming language layer, writing the data to be stored into the allocated memory space includes:

在所述第二编程语言层,将所述待存储数据进行序列化处理后后写入分配的所述内存空间;In the second programming language layer, serialize the data to be stored and then write it into the allocated memory space;

在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,将所述句柄对应的内存空间中的数据反馈到所述第一编程语言层,包括:At the second programming language layer, according to the stored correspondence between the handle and the memory space, the data in the memory space corresponding to the handle is fed back to the first programming language layer, including:

在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,将所述句柄对应的内存空间中的数据进行反序列化处理后反馈到所述第一编程语言层。At the second programming language layer, according to the stored correspondence between the handle and the memory space, the data in the memory space corresponding to the handle is deserialized and then fed back to the first programming language layer.

可选地,在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,为所述待存储数据分配基于第二编程语言层的内存空间,包括:Optionally, after it is determined that the proportion of memory currently available to the application at the first programming language layer is lower than a set threshold, allocating the memory space based on the second programming language layer for the data to be stored includes:

在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,通过定义的第一编程语言层的存储接口,调用定义的第二编程语言层的存储接口,为所述待存储数据分配基于第二编程语言层的内存空间。After determining that the proportion of memory currently available to the application in the first programming language layer is lower than the set threshold, call the defined storage interface of the second programming language layer through the defined storage interface of the first programming language layer, for The allocation of the data to be stored is based on the memory space of the second programming language layer.

本发明实施例提供一种内存空间分配装置,该装置应用于安装有安卓Android操作系统的终端,包括:An embodiment of the present invention provides a memory space allocation device, which is applied to a terminal installed with an Android operating system, including:

生成模块,用于在运行应用的过程中,生成第一编程语言层的待存储数据;所述第一编程语言层为Java层;A generating module, configured to generate data to be stored in the first programming language layer during the running of the application; the first programming language layer is the Java layer;

分配模块,用于在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,为所述待存储数据分配基于第二编程语言层的内存空间;所述第二编程语言层为Native层;An allocation module, configured to allocate a memory space based on a second programming language layer for the data to be stored after determining that the proportion of memory currently available to the application at the first programming language layer is lower than a set threshold; the second The second programming language layer is the Native layer;

写入模块,用于在所述第二编程语言层,将所述待存储数据写入分配的所述内存空间。A writing module, configured to write the data to be stored into the allocated memory space at the second programming language layer.

本发明实施例在采用Android操作系统运行应用的过程中,生成Java层的待存储数据后,若该应用当前在Java层能够利用的内存占比低于设定阈值,则为待存储数据分配基于Native层的内存空间,并在Native层,将待存储数据写入分配的内存空间。可见,本发明实施例使应用的可用内存不仅限于Java层,当应用在Java层的可用内存占比低于设定阈值后,可在Native(通过C或C++语言实现)层为该应用分配内存空间,从而极大地减少了发生OOM的几率,大大提高了应用的健壮性。In the embodiment of the present invention, in the process of using the Android operating system to run the application, after the data to be stored in the Java layer is generated, if the current memory ratio that the application can use in the Java layer is lower than the set threshold, the data to be stored is allocated based on The memory space of the Native layer, and in the Native layer, write the data to be stored into the allocated memory space. It can be seen that the embodiment of the present invention makes the available memory of the application not limited to the Java layer. When the proportion of the available memory of the application in the Java layer is lower than the set threshold, memory can be allocated for the application in the Native (implemented by C or C++ language) layer. Space, thus greatly reducing the chance of OOM, greatly improving the robustness of the application.

附图说明Description of drawings

图1为本发明实施例一提供的内存空间分配方法流程图;FIG. 1 is a flow chart of a memory space allocation method provided by Embodiment 1 of the present invention;

图2为本发明实施例二提供的内存空间分配方法流程图;FIG. 2 is a flow chart of a memory space allocation method provided by Embodiment 2 of the present invention;

图3为本发明实施例提供的内存空间分配装置结构示意图。FIG. 3 is a schematic structural diagram of a memory space allocation device provided by an embodiment of the present invention.

具体实施方式detailed description

本发明实施例的基本思想是:在采用Android操作系统运行应用的过程中,生成Java层的待存储数据后,若该应用当前在Java层能够利用的内存占比低于设定阈值,则为待存储数据分配基于Native层的内存空间,并在Native层,将待存储数据写入分配的内存空间。可见,本发明实施例使应用的可用内存不仅限于Java层,当应用在Java层的可用内存占比低于设定阈值后,可在Native(通过C或C++语言实现)层为该应用分配内存空间,从而极大地减少了发生OOM的几率,大大提高了应用的健壮性。The basic idea of the embodiment of the present invention is: in the process of using the Android operating system to run the application, after the data to be stored in the Java layer is generated, if the current memory ratio that the application can use in the Java layer is lower than the set threshold, then the The data to be stored is allocated based on the memory space of the Native layer, and the data to be stored is written into the allocated memory space in the Native layer. It can be seen that the embodiment of the present invention makes the available memory of the application not limited to the Java layer. When the proportion of the available memory of the application in the Java layer is lower than the set threshold, memory can be allocated for the application in the Native (implemented by C or C++ language) layer. Space, thus greatly reducing the chance of OOM, greatly improving the robustness of the application.

下面结合说明书附图对本发明实施例作进一步详细描述。The embodiments of the present invention will be further described in detail below in conjunction with the accompanying drawings.

如图1所示,为本发明实施例一提供的内存空间分配方法流程图,该方法应用于安装有安卓(Android)操作系统的终端,包括以下步骤:As shown in Figure 1, it is a flow chart of a memory space allocation method provided by Embodiment 1 of the present invention. The method is applied to a terminal with an Android operating system installed, and includes the following steps:

S101:在运行应用的过程中,生成第一编程语言层的待存储数据;所述第一编程语言层为Java层。S101: During the process of running the application, generate data to be stored in a first programming language layer; the first programming language layer is a Java layer.

比如,安卓(Android)应用程序是基于Java语言实现的,在运行过程中,需要在Java层将数据写入内存。这里的Java层即所述第一编程语言层。For example, an Android (Android) application program is implemented based on the Java language, and data needs to be written into memory at the Java layer during operation. The Java layer here is the first programming language layer.

S102:在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,为所述待存储数据分配基于第二编程语言层的内存空间;所述第二编程语言层为Native层。S102: After determining that the proportion of memory currently available to the application in the first programming language layer is lower than a set threshold, allocate a memory space based on a second programming language layer for the data to be stored; the second programming language The layer is the Native layer.

比如,在Java层监测内存消耗;具体的,可以在Java层定义一个接口如StringSaveObject(Object),当Java层需要存储数据时,调用该接口,通过使用ActivityManager的getProcessMemoryInfo方法获取Java层内存消耗。For example, monitor memory consumption at the Java layer; specifically, you can define an interface such as StringSaveObject(Object) at the Java layer. When the Java layer needs to store data, call this interface, and obtain the Java layer memory consumption by using the getProcessMemoryInfo method of ActivityManager.

在具体实施中,当确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,可以通过定义的第一编程语言层的存储接口,调用定义的第二编程语言层的存储接口,为所述待存储数据分配基于第二编程语言层的内存空间。In a specific implementation, when it is determined that the memory ratio currently available to the application at the first programming language layer is lower than the set threshold, the defined second programming language can be invoked through the defined storage interface of the first programming language layer The storage interface of the layer allocates the memory space based on the second programming language layer for the data to be stored.

比如,通过Java-Native界面(JavaNativeInterface,JNI)定义Java层的存储接口NativestringputToNative(Objectobj);定义Native层的存储接口jstringandroid_jni_putToNative(JNIEnv*env,jobjectobject;在Java层发现可用内存占比低于设定阈值(比如20%)时,通过Java层的存储接口调用Native层的存储接口(即JNI接口),在Native层为应用分配内存。For example, define the storage interface NativestringputToNative(Objectobj) of the Java layer through the Java-Native interface (JavaNativeInterface, JNI); define the storage interface jstringandroid_jni_putToNative of the Native layer (JNIEnv*env, jobjectobject; find that the proportion of available memory in the Java layer is lower than the set threshold (for example, 20%), the storage interface of the Native layer (ie, the JNI interface) is invoked through the storage interface of the Java layer, and memory is allocated for the application at the Native layer.

S103:在所述第二编程语言层,将所述待存储数据写入分配的所述内存空间。S103: At the second programming language layer, write the data to be stored into the allocated memory space.

该步骤中,当在Native层为应用的待存储数据分配好内存空间后,将待存储数据写入分配好的Native层内存空间。In this step, after the memory space for the application data to be stored is allocated in the Native layer, the data to be stored is written into the allocated Native layer memory space.

下面通过一个具体的实施例对本发明思想作进一步详细描述。The idea of the present invention will be further described in detail through a specific embodiment below.

如图2所示,为本发明实施例二提供的内存空间分配方法流程图,包括以下步骤:As shown in FIG. 2, it is a flow chart of the memory space allocation method provided by Embodiment 2 of the present invention, including the following steps:

S201:在运行应用的过程中,生成第一编程语言层的待存储数据。S201: During the process of running the application, generate data to be stored in the first programming language layer.

具体地,针对基于Java语言的安卓应用,在应用运行中,生成Java层的待存储数据。Specifically, for an Android application based on the Java language, the data to be stored in the Java layer is generated during the running of the application.

S202:在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,通过定义的第一编程语言层的存储接口,调用定义的第二编程语言层的存储接口,为所述待存储数据分配基于第二编程语言层的内存空间。S202: After determining that the proportion of memory currently available to the application in the first programming language layer is lower than the set threshold, call the defined storage interface of the second programming language layer through the defined storage interface of the first programming language layer , allocating memory space based on the second programming language layer for the data to be stored.

具体地,当Java层需要存储数据时,调用定义的内存监测接口StringSaveObject(Object),通过使用ActivityManager的getProcessMemoryInfo方法获取Java层内存消耗。Specifically, when the Java layer needs to store data, call the defined memory monitoring interface StringSaveObject (Object), and obtain the memory consumption of the Java layer by using the getProcessMemoryInfo method of the ActivityManager.

在JAVA层发现可用内存占比低于设定阈值(比如20%)时,通过JAVA层的存储接口NativestringputToNative(Objectobj)调用Native层的存储接口jstringandroid_jni_putToNative(JNIEnv*env,jobjectobject,在Native层为应用分配内存。When the JAVA layer finds that the proportion of available memory is lower than the set threshold (such as 20%), the storage interface jstringandroid_jni_putToNative(JNIEnv*env, jobjectobject) of the Native layer is called through the storage interface NativestringputToNative(Objectobj) of the JAVA layer, and the application is allocated in the Native layer. Memory.

S203:在所述第二编程语言层,将所述待存储数据进行序列化处理后写入分配的所述内存空间;并,将分配的所述内存空间转换为字符串形式的句柄反馈到第一编程语言层,并保存该句柄与所述内存空间的对应关系。S203: At the second programming language layer, serialize the data to be stored and write it into the allocated memory space; and convert the allocated memory space into a character string handle and feed it back to the second programming language layer A programming language layer, and save the corresponding relationship between the handle and the memory space.

具体地,在Native层,使用序列化(Serializable)接口将待存储数据进行序列化处理,然后使用new操作分配Native内存,将序列化后的数据存储到Native内存,将Native内存地址转化为字符串(string)后作为句柄(Handle)返回给Java层。在Native层,通过JNI建立句柄和内存空间的对应关系表,其中保存句柄和内存空间的对应关系,内存空间具体可以用保存的内存起始地址(Native地址)和内存长度来表示。Specifically, in the Native layer, use the Serializable interface to serialize the data to be stored, then use the new operation to allocate Native memory, store the serialized data in Native memory, and convert the Native memory address into a string (string) and return it to the Java layer as a handle (Handle). In the Native layer, the correspondence table between the handle and the memory space is established through JNI, which stores the correspondence between the handle and the memory space. The memory space can be represented by the stored memory start address (Native address) and memory length.

S204:在所述第一编程语言层,当需要从内存中读取所述待存储数据时,将包括所述句柄的内存访问指令指示给所述第二编程语言层。S204: At the first programming language layer, when the data to be stored needs to be read from the memory, indicate a memory access instruction including the handle to the second programming language layer.

具体地,在Java层定义访问接口NativeObjectgetFromNative(Stringhandle),通过该访问接口调用Native层访问接口,使用返回的句柄访问之前写入Native层内存的存储数据,Specifically, define the access interface NativeObjectgetFromNative(Stringhandle) in the Java layer, call the Native layer access interface through this access interface, and use the returned handle to access the stored data written in the Native layer memory before,

S205:在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,将所述句柄对应的内存空间中的数据进行反序列化处理后反馈到所述第一编程语言层。S205: At the second programming language layer, according to the stored correspondence between the handle and the memory space, deserialize the data in the memory space corresponding to the handle and feed it back to the first programming language layer.

具体地,在Native层,通过JNI,查询保存的句柄和内存空间的对应关系表,查找到该句柄对应的Native内存空间,读取该内存空间中的数据,并调用Java的Serializable接口对读取的数据进行反序列化处理后返回给Java层。Specifically, in the Native layer, through JNI, query the correspondence table between the stored handle and the memory space, find the Native memory space corresponding to the handle, read the data in the memory space, and call the Serializable interface of Java to read The data is deserialized and returned to the Java layer.

S206:在所述第一编程语言层,将包括所述句柄的内存释放指令指示给所述第二编程语言层。S206: At the first programming language layer, instruct the second programming language layer to release a memory instruction including the handle.

具体地,当需要释放内存时,Java层使用返回的句柄调用释放接口释放在Native层的存储内容。Specifically, when the memory needs to be released, the Java layer uses the returned handle to call the release interface to release the storage content in the Native layer.

S207:在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,删除所述句柄对应的内存空间中的数据。S207: At the second programming language layer, delete data in the memory space corresponding to the handle according to the stored correspondence between the handle and the memory space.

具体地,通过JNI,查询保存的句柄和内存空间的对应关系表,查找到该句柄对应的Native内存空间,使用delete操作释放查找到的Native内存空间。Specifically, through JNI, query the correspondence table between the stored handle and the memory space, find the Native memory space corresponding to the handle, and use the delete operation to release the found Native memory space.

采用本发明实施例,可在Native(通过C或C++语言实现)层为应用分配内存空间,从而可以减少发生OOM的几率,提高应用的健壮性。比如,当基于Java语言的应用使用了大量的图片,为了操作流畅,需要保存大量的位图(bitmap)数据,此时Java层可用内存受限,可以采用本发明实施例,将大量的bitmap数据通过定义的存储接口保存在Native层内存中。By adopting the embodiment of the present invention, the memory space can be allocated for the application at the Native (implemented by C or C++ language) layer, thereby reducing the probability of OOM and improving the robustness of the application. For example, when an application based on the Java language uses a large number of pictures, in order to operate smoothly, a large amount of bitmap (bitmap) data needs to be saved. At this time, the available memory of the Java layer is limited, and the embodiment of the present invention can be used to store a large amount of bitmap data. Stored in the Native layer memory through the defined storage interface.

基于同一发明构思,本发明实施例中还提供了一种与内存空间分配方法对应的内存空间分配装置,由于该装置解决问题的原理与本发明实施例内存空间分配方法相似,因此该装置的实施可以参见方法的实施,重复之处不再赘述。Based on the same inventive concept, the embodiment of the present invention also provides a memory space allocation device corresponding to the memory space allocation method. Since the problem-solving principle of the device is similar to the memory space allocation method of the embodiment of the present invention, the implementation of the device Reference can be made to the implementation of the method, and repeated descriptions will not be repeated.

如图3所示,为本发明实施例提供的内存空间分配装置结构示意图,该装置应用于安装有安卓Android操作系统的终端,包括:As shown in FIG. 3, it is a schematic structural diagram of a memory space allocation device provided by an embodiment of the present invention. The device is applied to a terminal installed with an Android operating system, including:

生成模块31,用于在运行应用的过程中,生成第一编程语言层的待存储数据;所述第一编程语言层为Java层;A generating module 31, configured to generate data to be stored in a first programming language layer during the running of the application; the first programming language layer is a Java layer;

分配模块32,用于在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,为所述待存储数据分配基于第二编程语言层的内存空间;所述第二编程语言层为Native层;The allocation module 32 is configured to allocate a memory space based on the second programming language layer for the data to be stored after determining that the current memory ratio that can be used by the application in the first programming language layer is lower than a set threshold; The second programming language layer is Native layer;

写入模块33,用于在所述第二编程语言层,将所述待存储数据写入分配的所述内存空间。The writing module 33 is configured to write the data to be stored into the allocated memory space at the second programming language layer.

可选地,所述写入模块33还用于,在将所述待存储数据写入分配的所述内存空间之后,在所述第二编程语言层,将分配的所述内存空间转换为字符串形式的句柄反馈到第一编程语言层,并保存该句柄与所述内存空间的对应关系;Optionally, the writing module 33 is further configured to, after writing the data to be stored into the allocated memory space, at the second programming language layer, convert the allocated memory space into characters The handle in string form is fed back to the first programming language layer, and the corresponding relationship between the handle and the memory space is saved;

所述装置还包括:The device also includes:

读取模块34,用于在所述第一编程语言层,当需要从内存中读取所述待存储数据时,将包括所述句柄的内存访问指令指示给所述第二编程语言层;在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,将所述句柄对应的内存空间中的数据反馈到所述第一编程语言层。The reading module 34 is used to indicate the memory access instruction including the handle to the second programming language layer when the data to be stored needs to be read from the memory at the first programming language layer; The second programming language layer feeds back the data in the memory space corresponding to the handle to the first programming language layer according to the stored correspondence between the handle and the memory space.

可选地,所述装置还包括:Optionally, the device also includes:

内存释放模块35,用于在所述第一编程语言层,将包括所述句柄的内存释放指令指示给所述第二编程语言层;在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,删除所述句柄对应的内存空间中的数据。The memory release module 35 is used to indicate the memory release instruction including the handle to the second programming language layer at the first programming language layer; at the second programming language layer, according to the saved handle and memory Space correspondence, delete the data in the memory space corresponding to the handle.

可选地,所述写入模块33具体用于:在所述第二编程语言层,将所述待存储数据进行序列化处理后后写入分配的所述内存空间;Optionally, the writing module 33 is specifically configured to: at the second programming language layer, serialize the data to be stored and write it into the allocated memory space;

所述读取模块34具体用于:在所述第二编程语言层,根据保存的句柄与内存空间的对应关系,将所述句柄对应的内存空间中的数据进行反序列化处理后反馈到所述第一编程语言层。The reading module 34 is specifically configured to: at the second programming language layer, according to the stored correspondence between the handle and the memory space, deserialize the data in the memory space corresponding to the handle and feed it back to the Describe the first programming language layer.

可选地,所述分配模块32具体用于:Optionally, the allocation module 32 is specifically configured to:

在确定所述应用当前在第一编程语言层能够利用的内存占比低于设定阈值后,通过定义的第一编程语言层的存储接口,调用定义的第二编程语言层的存储接口,为所述待存储数据分配基于第二编程语言层的内存空间。After determining that the proportion of memory currently available to the application in the first programming language layer is lower than the set threshold, call the defined storage interface of the second programming language layer through the defined storage interface of the first programming language layer, for The allocation of the data to be stored is based on the memory space of the second programming language layer.

本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that the embodiments of the present invention may be provided as methods, systems, or computer program products. Accordingly, the present invention can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.

本发明是参照根据本发明实施例的方法、装置(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each procedure and/or block in the flowchart and/or block diagram, and a combination of procedures and/or blocks in the flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a An apparatus for realizing the functions specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions The device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in the flow chart or blocks of the flowchart and/or the block or blocks of the block diagrams.

尽管已描述了本发明的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本发明范围的所有变更和修改。While preferred embodiments of the invention have been described, additional changes and modifications to these embodiments can be made by those skilled in the art once the basic inventive concept is appreciated. Therefore, it is intended that the appended claims be construed to cover the preferred embodiment as well as all changes and modifications which fall within the scope of the invention.

显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and equivalent technologies thereof, the present invention also intends to include these modifications and variations.

Claims (10)

1. a memory headroom distribution method, it is characterised in that the method is applied to be provided with the terminal of Android Android operation system, including:
In the process running application, generate the data to be stored of the first programming language layer;Described first programming language layer is Java layer;
Determining that internal memory accounting that described application currently can utilize at the first programming language layer is lower than after setting threshold value, for the described data to be stored distribution memory headroom based on the second programming language layer;Described second programming language layer is Native layer;
At described second programming language layer, by the described memory headroom of described data to be stored write distribution.
2. the method for claim 1, it is characterised in that at described second programming language layer, after the described memory headroom of described data to be stored write distribution, also include:
At described second programming language layer, the handle that the described memory headroom of distribution is converted to character string forms is fed back to the first programming language layer, and preserves the corresponding relation of this handle and described memory headroom;
At described first programming language layer, when needs read described data to be stored from internal memory, the internal storage access instruction including described handle is indicated to described second programming language layer;
At described second programming language layer, the corresponding relation according to the handle preserved with memory headroom, by the data feedback in memory headroom corresponding for described handle to described first programming language layer.
3. method as claimed in claim 2, it is characterised in that after the data feedback in memory headroom corresponding for described handle to described first programming language layer, also include:
At described first programming language layer, the internal memory including described handle is released order and is indicated to described second programming language layer;
At described second programming language layer, the corresponding relation according to the handle preserved with memory headroom, delete the data in the memory headroom that described handle is corresponding.
4. method as claimed in claim 2 or claim 3, it is characterised in that at described second programming language layer, by the described memory headroom of described data to be stored write distribution, including:
At described second programming language layer, described data to be stored are carried out the described memory headroom of write distribution after after serializing process;
At described second programming language layer, the corresponding relation according to the handle preserved with memory headroom, by the data feedback in memory headroom corresponding for described handle to described first programming language layer, including:
At described second programming language layer, the corresponding relation according to the handle preserved with memory headroom, after the data in memory headroom corresponding for described handle are carried out unserializing process, feed back to described first programming language layer.
5. the method for claim 1, it is characterised in that determining that internal memory accounting that described application currently can utilize at the first programming language layer is lower than after setting threshold value, for the described data to be stored distribution memory headroom based on the second programming language layer, including:
Determining that internal memory accounting that described application currently can utilize at the first programming language layer is lower than after setting threshold value, the memory interface of the first programming language layer by defining, the memory interface of the second programming language layer of call definition, distributes the memory headroom based on the second programming language layer for described data to be stored.
6. a memory headroom distributor, it is characterised in that this device is applied to be provided with the terminal of Android Android operation system, including:
Generation module, for, in the process running application, generating the data to be stored of the first programming language layer;Described first programming language layer is Java layer;
Distribution module, for determining that internal memory accounting that described application currently can utilize at the first programming language layer is lower than after setting threshold value, for the described data to be stored distribution memory headroom based on the second programming language layer;Described second programming language layer is Native layer;
Writing module, at described second programming language layer, by the described memory headroom of described data to be stored write distribution.
7. device as claimed in claim 6, it is characterized in that, said write module is additionally operable to, after by the described memory headroom of described data to be stored write distribution, at described second programming language layer, the handle that the described memory headroom of distribution is converted to character string forms is fed back to the first programming language layer, and preserves the corresponding relation of this handle and described memory headroom;
Described device also includes:
Read module, at described first programming language layer, when needs read described data to be stored from internal memory, being indicated to described second programming language layer by the internal storage access instruction including described handle;At described second programming language layer, the corresponding relation according to the handle preserved with memory headroom, by the data feedback in memory headroom corresponding for described handle to described first programming language layer.
8. device as claimed in claim 7, it is characterised in that described device also includes:
Internal memory release module, at described first programming language layer, releasing order the internal memory including described handle and be indicated to described second programming language layer;At described second programming language layer, the corresponding relation according to the handle preserved with memory headroom, delete the data in the memory headroom that described handle is corresponding.
9. as claimed in claim 7 or 8 device, it is characterised in that said write module specifically for: at described second programming language layer, described data to be stored are carried out the described memory headroom of write distribution after after serializing process;
Described read module specifically for: at described second programming language layer, the corresponding relation according to the handle preserved with memory headroom, feed back to described first programming language layer after the data in memory headroom corresponding for described handle are carried out unserializing process.
10. device as claimed in claim 6, it is characterised in that described distribution module specifically for:
Determining that internal memory accounting that described application currently can utilize at the first programming language layer is lower than after setting threshold value, the memory interface of the first programming language layer by defining, the memory interface of the second programming language layer of call definition, distributes the memory headroom based on the second programming language layer for described data to be stored.
CN201410849680.4A 2014-12-29 2014-12-29 A kind of memory headroom distribution method and device Active CN105808219B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410849680.4A CN105808219B (en) 2014-12-29 2014-12-29 A kind of memory headroom distribution method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410849680.4A CN105808219B (en) 2014-12-29 2014-12-29 A kind of memory headroom distribution method and device

Publications (2)

Publication Number Publication Date
CN105808219A true CN105808219A (en) 2016-07-27
CN105808219B CN105808219B (en) 2019-06-25

Family

ID=56421518

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410849680.4A Active CN105808219B (en) 2014-12-29 2014-12-29 A kind of memory headroom distribution method and device

Country Status (1)

Country Link
CN (1) CN105808219B (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106776500A (en) * 2016-12-12 2017-05-31 中国航空工业集团公司西安航空计算技术研究所 A kind of character library data texturing management method
CN107145451A (en) * 2017-05-09 2017-09-08 深圳市茁壮网络股份有限公司 A kind of JavaScript object storage, recovery method and device
CN107168887A (en) * 2017-05-09 2017-09-15 深圳市茁壮网络股份有限公司 A kind of JavaScript object storage, recovery method and device
CN108132816A (en) * 2016-12-01 2018-06-08 腾讯科技(深圳)有限公司 The method and apparatus that local ccf layer calls are realized in
CN108958943A (en) * 2018-07-25 2018-12-07 北京小米移动软件有限公司 Memory release method and device
CN110362311A (en) * 2019-06-18 2019-10-22 阿里巴巴集团控股有限公司 For assisting the method and device of bitmap Object Memory Allocation
CN110633141A (en) * 2019-06-25 2019-12-31 北京无限光场科技有限公司 Memory management method and device of application program, terminal equipment and medium
CN111966603A (en) * 2020-09-04 2020-11-20 网易(杭州)网络有限公司 Memory leak detection method and device, readable storage medium and electronic equipment
CN112114962A (en) * 2020-09-04 2020-12-22 北京达佳互联信息技术有限公司 Method and device for allocating memory
CN112925654A (en) * 2019-12-05 2021-06-08 腾讯科技(深圳)有限公司 Picture decoding method and device, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102779074A (en) * 2012-06-18 2012-11-14 中国人民解放军国防科学技术大学 Internal memory resource distribution method based on internal memory hole mechanism
CN103455433A (en) * 2013-08-19 2013-12-18 曙光信息产业股份有限公司 Memory management method and system
CN103914366A (en) * 2013-01-05 2014-07-09 腾讯科技(深圳)有限公司 Method and device for automatically monitoring application memory information
CN103970545A (en) * 2014-05-26 2014-08-06 天津七一二通信广播有限公司 LTE Modem method adopting JNI invoking mode and used in Android system
CN104182320A (en) * 2013-05-23 2014-12-03 联想(北京)有限公司 Method and device for monitoring leakage of memory

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102779074A (en) * 2012-06-18 2012-11-14 中国人民解放军国防科学技术大学 Internal memory resource distribution method based on internal memory hole mechanism
CN103914366A (en) * 2013-01-05 2014-07-09 腾讯科技(深圳)有限公司 Method and device for automatically monitoring application memory information
CN104182320A (en) * 2013-05-23 2014-12-03 联想(北京)有限公司 Method and device for monitoring leakage of memory
CN103455433A (en) * 2013-08-19 2013-12-18 曙光信息产业股份有限公司 Memory management method and system
CN103970545A (en) * 2014-05-26 2014-08-06 天津七一二通信广播有限公司 LTE Modem method adopting JNI invoking mode and used in Android system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
YULONGFEI: "Android进程的内存管理分析", 《HTTP://BLOG.CSDN.NET/GEMMEM/ARTICLE/DETAILS/8920039》 *

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108132816A (en) * 2016-12-01 2018-06-08 腾讯科技(深圳)有限公司 The method and apparatus that local ccf layer calls are realized in
CN108132816B (en) * 2016-12-01 2020-12-18 腾讯科技(深圳)有限公司 Method and device for realizing local framework layer calling in application
CN106776500A (en) * 2016-12-12 2017-05-31 中国航空工业集团公司西安航空计算技术研究所 A kind of character library data texturing management method
CN107168887B (en) * 2017-05-09 2020-09-04 深圳市茁壮网络股份有限公司 JavaScript object storage and recovery method and device
CN107145451A (en) * 2017-05-09 2017-09-08 深圳市茁壮网络股份有限公司 A kind of JavaScript object storage, recovery method and device
CN107168887A (en) * 2017-05-09 2017-09-15 深圳市茁壮网络股份有限公司 A kind of JavaScript object storage, recovery method and device
CN107145451B (en) * 2017-05-09 2020-09-25 深圳市茁壮网络股份有限公司 JavaScript object storage and recovery method and device
CN108958943A (en) * 2018-07-25 2018-12-07 北京小米移动软件有限公司 Memory release method and device
CN108958943B (en) * 2018-07-25 2021-02-09 北京小米移动软件有限公司 Memory release method and device
CN110362311A (en) * 2019-06-18 2019-10-22 阿里巴巴集团控股有限公司 For assisting the method and device of bitmap Object Memory Allocation
CN110362311B (en) * 2019-06-18 2023-03-14 创新先进技术有限公司 Method and device for assisting bitmap object memory allocation
CN110633141A (en) * 2019-06-25 2019-12-31 北京无限光场科技有限公司 Memory management method and device of application program, terminal equipment and medium
CN112925654A (en) * 2019-12-05 2021-06-08 腾讯科技(深圳)有限公司 Picture decoding method and device, computer equipment and storage medium
CN112925654B (en) * 2019-12-05 2024-01-30 腾讯科技(深圳)有限公司 Picture decoding method, device, computer equipment and storage medium
CN111966603A (en) * 2020-09-04 2020-11-20 网易(杭州)网络有限公司 Memory leak detection method and device, readable storage medium and electronic equipment
CN112114962A (en) * 2020-09-04 2020-12-22 北京达佳互联信息技术有限公司 Method and device for allocating memory
CN111966603B (en) * 2020-09-04 2024-01-19 网易(杭州)网络有限公司 Memory leakage detection method and device, readable storage medium and electronic equipment

Also Published As

Publication number Publication date
CN105808219B (en) 2019-06-25

Similar Documents

Publication Publication Date Title
CN105808219B (en) A kind of memory headroom distribution method and device
US9465734B1 (en) Coalition based memory management
US11360884B2 (en) Reserved memory in memory management system
CN102662775B (en) A kind of Way of Process Communication and device
CN102770841A (en) Method and apparatus for generating a minimal boot image
CN108196937B (en) Method and device for processing character string object, computer equipment and storage medium
CN102750364B (en) Method, compiler and system for distributing memory address space for image files
US11016886B2 (en) Multi-ring shared, traversable, and dynamic advanced database
US9875181B2 (en) Method and system for processing memory
US8751724B2 (en) Dynamic memory reconfiguration to delay performance overhead
US8296542B2 (en) Dynamic memory allocation for applications
CN105874439A (en) Memory pool management method for sharing memory pool by different computing units, and related computer readable medium and memory pool management device
JP2018525724A (en) Automatic memory management using a memory management device
CN102779076B (en) The method and apparatus of interprocess communication in a kind of browser
CN108563507A (en) A kind of EMS memory management process, device, equipment and readable storage medium storing program for executing
US9766940B2 (en) Enabling dynamic job configuration in mapreduce
US20140149709A1 (en) Method and system for dynamically updating data fields of buffers
US9442835B1 (en) Dynamic memory allocation using suballocation of cell blocks
CN106547603B (en) Method and device for reducing garbage collection time of golang language system
JP4984303B2 (en) Dynamic linking and dynamic loading of post-processing kernel
CN110673797A (en) Logical volume copying method in distributed block storage service
US20120011330A1 (en) Memory management apparatus, memory management method, program therefor
US20220171742A1 (en) Electronic device and method for controlling electronic device
CN115509763B (en) Fingerprint calculation method and device
US11494348B2 (en) System and method for using object references as a data type

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant