CN104615499A - Picture processing method based on Android platform - Google Patents

Picture processing method based on Android platform Download PDF

Info

Publication number
CN104615499A
CN104615499A CN201510062137.4A CN201510062137A CN104615499A CN 104615499 A CN104615499 A CN 104615499A CN 201510062137 A CN201510062137 A CN 201510062137A CN 104615499 A CN104615499 A CN 104615499A
Authority
CN
China
Prior art keywords
picture
processing method
android platform
android
connection pool
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.)
Pending
Application number
CN201510062137.4A
Other languages
Chinese (zh)
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.)
Inspur Software Group Co Ltd
Original Assignee
Inspur Software 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 Inspur Software Group Co Ltd filed Critical Inspur Software Group Co Ltd
Priority to CN201510062137.4A priority Critical patent/CN104615499A/en
Publication of CN104615499A publication Critical patent/CN104615499A/en
Pending legal-status Critical Current

Links

Abstract

The invention relates to an Android platform based picture processing method, which comprises the following steps: s10: optimizing network reading and presentation of pictures, encapsulating a loading part into an open source framework, and adding the open source framework into an HTTP connection pool for management to realize batch picture reading; s11: adding a local picture cache mechanism, and calculating the weight and the use frequency of each picture by adopting an LRU algorithm so as to dynamically manage cache. The picture processing method based on the Android platform is an architecture mode for reading and displaying on the Android system, and comprises the steps of HTTP connection pool management added in the downloading process, and cache optimization is carried out by using an LRU algorithm after downloading. The resource recovery processing is optimized, OOM is avoided, and when the memory overflows, the resources are recovered in time.

Description

A kind of based on Android platform image processing method
Technical field
The present invention relates to computer operating system technical field, be specifically related to a kind of based on Android platform image processing method.
Background technology
With Mobile solution operating system Android because its professional platform independence is good, application program Environmental Development is rapid, system is increased income and is beneficial to innovation, the numerous hardware configuration of type has multiple choices, add the support of smart mobile phone manufacturer and various places operator, usable range is more and more wider, from mobile phone, to wrist-watch, Set Top Box, POS etc. multiple mobile terminal devices.But because Android is used for mobile terminal, CPU, memory source are restricted, just have when loading a large amount of picture OOM(internal memory overflow) phenomenon occur.So most of APP other modes of many employings when designing get around the interface that many pictures load.
Therefore, for above-mentioned prior art Problems existing, be necessary to develop research in fact, to provide a solution, optimize resource reclaim process, avoid the generation of OOM, when internal memory overflows, carry out the recycling of resource in time.
Summary of the invention
For solving the problem, the object of the present invention is to provide a kind of based on Android platform image processing method, to optimize resource reclaim process, avoiding the generation of OOM, when internal memory overflows, carry out the recycling of resource in time.
For achieving the above object, technical scheme of the present invention is:
A kind of based on Android platform image processing method, comprise the steps:
S10: read by the network of picture, present and be optimized, loading section is packaged into Open Framework, and adds HTTP connection pool management, realizes batch picture and reads;
S11: add local image cache mechanism, adopts lru algorithm to calculate weight, the frequency of utilization of every pictures, with dynamic management buffer memory.
Further, in step S10, after using HTTP connection pool to be downloaded by picture, Android control rewrites onDraw method and carries out presenting of picture.
Further, in step S11, lru algorithm adopts the single linked list of band gauge outfit to store back end, head pointed gauge outfit, last node of tail pointed chained list.
The present invention is based on Android platform image processing method is a kind of framework mode reading in android system, show, and comprises the HTTP connection pool management added in downloading process, uses lru algorithm to carry out cache optimization after downloading.Optimize resource reclaim process, avoid the generation of OOM, when internal memory overflows, carry out the recovery of resource in time.
Term " first ", " second " etc. in instructions of the present invention and claims and above-mentioned accompanying drawing are for distinguishing similar object, and need not be used for describing specific order or precedence.Should be appreciated that the term used like this can exchange in the appropriate case, this is only describe in embodiments of the invention the differentiation mode that the object of same alike result adopts when describing.In addition, term " comprises " and " having " and their any distortion, intention is to cover not exclusive comprising, to comprise the process of a series of unit, method, system, product or equipment being not necessarily limited to those unit, but can comprise clearly do not list or for intrinsic other unit of these processes, method, product or equipment.
Below be described in detail respectively.
With reference to shown in Fig. 1, Fig. 2, the present invention is a kind of based on Android platform image processing method, comprises the steps:
S10: read by the network of picture, present and be optimized, loading section is packaged into Open Framework, and adds HTTP connection pool management, realizes batch picture and reads;
Http agreement is most popular agreement on internet, and the network application of webservices etc. are increasing the demand that Http agreement is supported while, and also strong promotion agreement itself is expanded out from the limitation occasion of browser application.Although java.net has done basic support to the agreement of http from functions such as Gains resources network, it can not meet the requirement of many application to agreement full functionality and dirigibility.
When simple use HttpClient goes to read picture in batches, the plenty of time can be consumed on request connects, set up frequently, close connection, the performance of the great attenuating system of meeting, because become the bottleneck of system performance for the use connected.
Http connection pool make use of the lasting connection performance of Http 1.1 KeepAlive, in Transmission Control Protocol, two machines connect and relate to three-way handshake, more time consuming, particularly when lasting transmission low volume data, can continue to reuse if connected, just can reach larger handling capacity.Also to consider if multiple socket connection can be opened for a Service-Port remove transmission information simultaneously, then can reach the raising of the network bandwidth.The ultimate principle of HTTP connection pool is in internal object pond, safeguard that the HTTP of some connects, and externally exposes HTTP connection acquisition and return method.
After using HTTP connection pool to be downloaded by picture, Android control also rewrites onDraw method and carries out presenting of picture.Particularly, inside onDraw method for drafting, judge whether picture is recovered, if reclaimed, need to arrange acquiescence picture; When adding picture to buffer memory cache, call Runtime.getRuntime () .gc (); GetCacheSize can dynamically arrange the cache size of our actual needs by the internal memory concrete according to mobile phone; When exiting, remember to call and reclaim recycle () method.
S11: add local image cache mechanism, adopt lru algorithm (minimum use page replacement algorithm), calculate the weight of every pictures, frequency of utilization, with dynamic management buffer memory, avoid the phenomenon of OOM to occur.
Lru algorithm is virtual page mobile sms service, for the memory management of operating system, how to save utilize capacity little in save as maximum processes resource be provided, be the important directions of research always.And the virtual memory management of internal memory, be now the most general, the most successful mode, when limited memory, expands a part of external memory as virtual memory, usedly when real internal memory only stores current operation obtains information.This has greatly expanded the function of internal memory undoubtedly, drastically increases the concurrency of computing machine.Virtual paged memory management, be then that process requisite space is divided into multiple page, only deposit current desired page in internal memory, all the other pages put into the way to manage of external memory.But, virtual paged memory management decreases the memory headroom needed for process, bring this shortcoming elongated working time also: in process operational process, inevitably exchange existing in some information deposited in external memory and internal memory, due to the low speed of external memory, the time that this step spends can not ignore.Thus, take measured to the greatest extent algorithm to reduce the number of times reading external memory, reduce the gap with hypothetic algorithm, create various exquisite algorithm, minimum use page replacement algorithm is one of them as far as possible.Frequently use based on using in several the instructions above in several the instructions of the page probably below frequently.The page for a long time do not used conversely speaking, probably can not be used within following long period of time.Therefore, we only need when exchanging at every turn, find that page of minimum use to recall internal memory, namely adopt lru algorithm.
Particularly, lru algorithm adopts the single linked list of band gauge outfit to store back end, head pointed gauge outfit, last node of tail pointed chained list.Back end then have recorded the ID of each cache blocks, stress state, data pointer, next pointer.UnUsedSize variable is separately had to deposit unappropriated cache blocks quantity.When user accesses hit, the back end of correspondence is moved on to queue tail.When user accesses miss, if new data node can be distributed, then distribute, otherwise take a back end from gauge outfit, and unload data.Upgrade the information of the back end obtained, and be added to queue tail.Finally, in order to avoid traveling through whole chained list when searching back end, adding the dictionary of Dictionary, utilizing its hash locating function to improve search efficiency.
Wherein also used buffer lock, buffer memory needs operation two data structure: Hash to show and LRU chained list.Need during multithreading operation cache to lock, more direct way operates Hash table and LRU chained list again after entirety adds a large lock.By optimizing, Hash table and LRU chained list use two different locks, and the granularity of Hash table lock can be reduced to one, each Hash bucket lock.The difficult point of this way needs the inconsistent problem caused of process two kinds of data structures, suppose that sequence of operation is read hash-> del hash item-> del lru item-> read lru item, during last read lru item, the memory block at item place may be recovered or reuse, and generally needs to introduce reference count and considers complicated sequence problem.
Multiple LRU chained list is adopted to show lock granularity to reduce LRU.The lock conflict of Hash table can be solved by the number increasing Hash bucket, and LRU chained list is an entirety, is difficult to decompose.The data of buffer memory can be divided into multiple working set, each item belongs to certain working set, each working set LRU chained list.The subject matter done like this is possible unbalanced, and such as certain working set is awfully hot, and some sees that hotter data also may be eliminated on the whole.
LRU chained list is divided into two parts, first half and latter half, if the item of access is at first half, does nothing.By memory block record access times of each 2MB and a nearest access time, during each reading item, if access times are greater than the mean value of all 2MB memory block access times, upgrade the nearest access time; Otherwise, access times are added 1.The nearest access time according to record eliminates 2MB memory block, and buffer memory reads only needs some atomic operations, does not need to lock, greatly reduces lock granularity.
In the embodiment of the present invention, do not need during cache hit to upgrade LRU chained list immediately, but the item of hit can be kept in thread Buffer, disposable renewal LRU chained list after have accumulated some.
With reference to shown in Fig. 2, LRU buffer memory realizes being divided into two part: Hash to show and LRU chained list, and Hash table is for searching the element in buffer memory, and LRU chained list is used for eliminating.Internal memory often manages in the mode of Slab.Memcache is with Slab mode managing internal memory block, and be divided into the Chunk of different size from the bulk memory of system application 1MB size, the Chunk size of different Slab is followed successively by 80 bytes, 80 * 1.25,80 * 1.25^2, byte etc.When adding item in Memcache, Memcache can select suitable Chunk according to the size of item.
Through the above description of the embodiments, those skilled in the art can be well understood to the mode that the present invention can add required common hardware by software and realize, and can certainly comprise special IC, dedicated cpu, private memory, special components and parts etc. realize by specialized hardware.Generally, all functions completed by computer program can realize with corresponding hardware easily, and the particular hardware structure being used for realizing same function also can be diversified, such as mimic channel, digital circuit or special circuit etc.But under more susceptible for the purpose of the present invention condition, software program realizes is better embodiment.Based on such understanding, technical scheme of the present invention can embody with the form of software product the part that prior art contributes in essence in other words, this computer software product is stored in the storage medium that can read, as the floppy disk of computing machine, USB flash disk, portable hard drive, ROM (read-only memory) (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disc or CD etc., comprising some instructions in order to make a computer equipment (can be personal computer, server, or the network equipment etc.) perform method described in the present invention each embodiment.
In sum, above embodiment only in order to technical scheme of the present invention to be described, is not intended to limit; Although with reference to above-described embodiment to invention has been detailed description, those of ordinary skill in the art is to be understood that: it still can be modified to the technical scheme described in the various embodiments described above, or carries out equivalent replacement to wherein portion of techniques feature; And these amendments or replacement, do not make the essence of appropriate technical solution depart from the spirit and scope of various embodiments of the present invention technical scheme.
Accompanying drawing explanation
Fig. 1 is method flow of the present invention diagram.
Fig. 2 is that the picture internal memory optimization of the inventive method uses LRU to replace diagram.
Embodiment
Embodiments provide a kind of based on Android platform image processing method, the network of picture is read, present and be optimized, loading section is packaged into Open Framework, and adds HTTP connection pool management, the reading of batch picture can be realized.The more important thing is, add local image cache mechanism, adopt lru algorithm, calculate the weight of every pictures, frequency of utilization, with dynamic management buffer memory, avoid the phenomenon of OOM to occur.
For making goal of the invention of the present invention, feature, advantage can be more obvious and understandable, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is clearly and completely described, obviously, the embodiments described below are only the present invention's part embodiments, and not all embodiments.Based on the embodiment in the present invention, the every other embodiment that those skilled in the art obtains, all belongs to the scope of protection of the invention.

Claims (3)

1. based on an Android platform image processing method, it is characterized in that, comprise the steps:
S10: read by the network of picture, present and be optimized, loading section is packaged into Open Framework, and adds HTTP connection pool management, realizes batch picture and reads;
S11: add local image cache mechanism, adopts lru algorithm to calculate weight, the frequency of utilization of every pictures, with dynamic management buffer memory.
2. as claimed in claim 1 based on Android platform image processing method, it is characterized in that, in step S10, after using HTTP connection pool to be downloaded by picture, Android control rewrites onDraw method and carries out presenting of picture.
3. as claimed in claim 2 based on Android platform image processing method, it is characterized in that, in step S11, lru algorithm adopts the single linked list of band gauge outfit to store back end, head pointed gauge outfit, last node of tail pointed chained list.
CN201510062137.4A 2015-02-06 2015-02-06 Picture processing method based on Android platform Pending CN104615499A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510062137.4A CN104615499A (en) 2015-02-06 2015-02-06 Picture processing method based on Android platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510062137.4A CN104615499A (en) 2015-02-06 2015-02-06 Picture processing method based on Android platform

Publications (1)

Publication Number Publication Date
CN104615499A true CN104615499A (en) 2015-05-13

Family

ID=53149955

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510062137.4A Pending CN104615499A (en) 2015-02-06 2015-02-06 Picture processing method based on Android platform

Country Status (1)

Country Link
CN (1) CN104615499A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106294731A (en) * 2016-08-09 2017-01-04 四川网达科技有限公司 Enter management method and the device of database data
CN109218799A (en) * 2017-07-01 2019-01-15 武汉斗鱼网络科技有限公司 Android TV is switched fast method, storage medium, equipment and the system of high definition figure

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103760966A (en) * 2013-05-02 2014-04-30 乐视网信息技术(北京)股份有限公司 Picture buffering implementation method

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103760966A (en) * 2013-05-02 2014-04-30 乐视网信息技术(北京)股份有限公司 Picture buffering implementation method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
ANDROIDZHAOXIAOGANG: "enif项目源代码", 《HTTP://DOWNLOAD.CSDN.NET/DOWNLOAD/ANDROIDZHAOXIAOGANG/4797109》 *
CODEWEBLOG.COM: "android上的一个网络接口和图片缓存框架enif简析", 《HTTP://WWW.CODEWEBLOG.COM/ANDROID上的一个网络接口和图片缓存框架ENIF简析/》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106294731A (en) * 2016-08-09 2017-01-04 四川网达科技有限公司 Enter management method and the device of database data
CN109218799A (en) * 2017-07-01 2019-01-15 武汉斗鱼网络科技有限公司 Android TV is switched fast method, storage medium, equipment and the system of high definition figure
CN109218799B (en) * 2017-07-01 2021-04-27 武汉斗鱼网络科技有限公司 Method, storage medium, device and system for quickly switching high-definition images of android television

Similar Documents

Publication Publication Date Title
CN102750174B (en) file loading method and device
US20190220418A1 (en) Memory Management Method and Apparatus
CN102331986B (en) Database cache management method and database server
US8972690B2 (en) Methods and apparatuses for usage based allocation block size tuning
CN105718287B (en) A kind of program streaming execution method of intelligent terminal
CN104281528B (en) A kind of date storage method and device
CN108701079A (en) The system and method that flash memory with adaptive prefetching reads cache
US20120144092A1 (en) Efficient cache management
CN105493053A (en) Cache partitioning in a multicore processor
CN102023973A (en) Method, device and system for synchronizing database with application cache server
WO2020220971A1 (en) File loading method and apparatus, electronic device, and storage medium
CN108984130A (en) A kind of the caching read method and its device of distributed storage
CN104216902A (en) Paging data loading method, device and system based on server paging
CN101236564A (en) Mass data high performance reading display process
CN113392863A (en) Method and device for acquiring machine learning training data set and terminal
CN103513956A (en) Data processing method and device of processor
CN103229150B (en) data control method and system
CN1687899A (en) Method, system and module for dynamic downloading of applied programe to user identification
CN105426322B (en) A kind of forecasting method and device of data
CN110059024B (en) Memory space data caching method and device
CN104615499A (en) Picture processing method based on Android platform
CN112948025B (en) Data loading method and device, storage medium, computing equipment and computing system
CN112631504A (en) Method and device for realizing local cache by using off-heap memory
CN103823634A (en) Data processing method and system supporting non-random write mode
US11221770B2 (en) Providing a dynamic random-access memory cache as second type memory

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20150513