-
Notifications
You must be signed in to change notification settings - Fork 0
/
index3.html
204 lines (183 loc) · 13.9 KB
/
index3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>I'm aaapei</title>
<meta name="author" content="aaapei">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Open Graph tags -->
<meta property="og:type" content="website"/>
<meta property="og:title" content="I'm aaapei"/>
<meta property="og:url" content="http://blog.aaapei.com"/>
<meta property="og:description" content="I'm aaapei"/>
<link rel="canonical" href="">
<link href="http://blog.aaapei.com/favicon.png" rel="shortcut icon">
<link href="http://blog.aaapei.com/theme/css/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="http://blog.aaapei.com/theme/css/pygments.css" media="screen, projection" rel="stylesheet" type="text/css">
<!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--
<link href="//fonts.googleapis.com/css?family=Open+Sans:400italic,400,700" rel='stylesheet' type='text/css'>
<link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel='stylesheet' type='text/css'>
<link href="//fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel='stylesheet' type='text/css'>
-->
<script src="//lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
</head>
<body>
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F42905fb57b3457075b7322a0893c5395' type='text/javascript'%3E%3C/script%3E"));
</script>
<div class="container">
<div class="left-col">
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img src="http://nos.netease.com/knowledge/85c5dfab-ec44-4818-a018-1fc31e8baa4f" alt="Profile Picture" style="width: 160px;" />
</div>
<hgroup>
<br/>
<h1><a href="http://blog.aaapei.com/">I'm aaapei</a></h1>
<h3>少年去游荡</h3>
</hgroup>
<nav id="main-nav">
<ul class="main-navigation">
<li><a href="http://blog.aaapei.com/.">首页</a></li>
<li><a href="http://blog.aaapei.com/categories.html">分类</a></li>
<li><a href="http://blog.aaapei.com/pages/sui-sui-nian">碎碎念</a></li>
</ul></nav>
<nav id="sub-nav">
<div class="social">
<a class="email" href="mailto:[email protected]" title="Email">Email</a>
<a class="weibo" href="http://weibo.com/a2pei" title="Weibo">Weibo</a>
<a class="rss" href="http://blog.aaapei.com/rss.xml" title="RSS">ATOM</a>
</div>
<section id="about-me">
<h2>关于我</h2>
<p>生活@hangzhou. 工作@netease.<br/> 移动端码农. 正在减肥的胖子. 食肉. <br/>想养喵但老婆不让</p>
</section>
</nav> </header>
</div>
</div>
<div class="mid-col">
<div class="mid-col-container">
<div id="content" class="inner">
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-08-09T00:00:00.000000+0800" itemprop="datePublished">2014-08-09</time>
</div>
<div class="tags">
<a href="http://blog.aaapei.com/tags/yu-ming">域名</a> </div>
</div> <h1 class="title" itemprop="name"><a href="http://blog.aaapei.com/article/2014/08/blogaaapeicom" itemprop="url">blog.aaapei.com</a></h1>
<div class="entry-content" itemprop="description"><p>前端时间为了科学上网买了个vps,准备用aaapei这个主域名收回来,用在vps跑一些试验性服务,blog切到二级子域名 blog.aaapei.com</p>
<p>最近一两个月会将aaapei.com的80端口重定向到blog子域名,顺便扯一句,godaddy的重定向服务在国内被禁,所以在vps上又跑了个tornado实例,专门做重定向;google analytics上看月pv也就几百,我一定是想多了 :<</p>
<br/ >
<a href="http://blog.aaapei.com/article/2014/08/blogaaapeicom">查看全文</a>
</div>
<div class="meta">
<span class="author">Posted by <a href="http://blog.aaapei.com/author/zhengwen.html">zhengwen</a></span>
</div>
</article>
<hr/>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-04-19T23:21:00.000000+0800" itemprop="datePublished">2014-04-19</time>
</div>
<div class="tags">
<a href="http://blog.aaapei.com/tags/android">android</a> , <a href="http://blog.aaapei.com/tags/lua">lua</a> </div>
</div> <h1 class="title" itemprop="name"><a href="http://blog.aaapei.com/article/2014/04/androidzhong-luajiao-ben-de-bu-shu" itemprop="url">android中lua脚本的部署</a></h1>
<div class="entry-content" itemprop="description"><p>“愤怒的小鸟”中,lua脚本是运行时部署在应用的data目录,同时做了脚本加密;<br>
但是如果你的lua脚本有了模块包,脚本就会有多级目录,而android的data目录下是不允许有子目录;<br>
当然,lua脚本也可以在运行时拷贝到外置sd卡中,不过既然放置在不安全的公共目录,就会有被第三方删除或篡改的危险,那么每次启动的时候必须做一次文件校验,同时,也必须对脚本进行加密,避免程序逻辑暴露; </p>
<h3>lua自定义加载器</h3>
<p>lua引擎提供了一个自定义加载器,当lua脚本中调用require时,会回调到自定义加载器的CFunction;利用这样特性,可以尝试取消掉脚本的运行时拷贝,而直接从应用的asset资源目录加载;自定义加载器的原理中,云风的blog中有介绍,<a href="http://blog.codingnow.com/2007/04/user_define_lua_loader.html">以自定义方式加载lua模块</a><br>
直接贴个代码实现 </p>
<div class="highlight"><pre><span></span><span class="kt">void</span> <span class="nf">addAssetLuaLoader</span><span class="p">(</span><span class="n">lua_State</span> <span class="o">*</span><span class="n">L</span><span class="p">,</span> <span class="n">lua_CFunction</span> <span class="n">func</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">func</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="n">lua_getglobal</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="s">"package"</span><span class="p">);</span>
<span class="n">lua_getfield</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="s">"loaders"</span><span class="p">);</span>
<span class="n">lua_pushcfunction</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="n">func</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span> <span class="n">i …</span></pre></div>
<br/ >
<a href="http://blog.aaapei.com/article/2014/04/androidzhong-luajiao-ben-de-bu-shu">查看全文</a>
</div>
<div class="meta">
<span class="author">Posted by <a href="http://blog.aaapei.com/author/zhengwen.html">zhengwen</a></span>
</div>
</article>
<hr/>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-02-19T19:50:00.000000+0800" itemprop="datePublished">2014-02-19</time>
</div>
<div class="tags">
<a href="http://blog.aaapei.com/tags/lua">lua</a> , <a href="http://blog.aaapei.com/tags/luajava">luajava</a> </div>
</div> <h1 class="title" itemprop="name"><a href="http://blog.aaapei.com/article/2014/02/luazai-kua-yu-yan-huan-jing-zhong-de-nei-cun-xie-lu" itemprop="url">lua在跨语言环境中的内存泄露</a></h1>
<div class="entry-content" itemprop="description"><p>前段时间在android环境中使用lua,采用的luabridge是luajava,遇到一个内存泄露问题,查了很久,终于定位了;</p>
<p>场景是这样的:<br>
1:在lua中创建了一个java对象,将jobject指针传递给java;对应在luajava中,即传递了一个luaobject给java;java保存了这个对象;<br>
2:在Lua中需要对这个java对象设置一个事件回调,比如说为某个控件setOnClickListener;<br>
其中设置的代码是这样的:</p>
<div class="highlight"><pre><span></span><span class="kd">local</span> <span class="n">viewclick_cb</span><span class="o">=</span><span class="p">{}</span>
<span class="k">function</span> <span class="nc">viewclick_cb</span><span class="p">.</span><span class="nf">onClick</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="n">self</span><span class="p">:</span><span class="n">cb</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="k">end</span>
<span class="kd">local</span> <span class="n">listenerProxy</span> <span class="o">=</span> <span class="n">luajava</span><span class="p">.</span><span class="n">createProxy</span><span class="p">(</span><span class="s1">'</span><span class="s">android.view.View$OnClickListener'</span><span class="p">,</span><span class="n">viewclick_cb</span><span class="p">)</span>
<span class="n">javaobjhandler</span><span class="p">:</span><span class="n">setOnClickListener</span><span class="p">(</span><span class="n">ListenerProxy</span><span class="p">)</span>
</pre></div>
<p>lua和java交互时,对象生命周期管理分两种情况:</p>
<blockquote>
<p>1:java对象传递个lua虚拟机,lua虚拟机为java对象创建一个userdata,在globalref中增加一个引用,标记这个java对象正在被使用;同时,为这个userdata设置一个__gc元方法,当lua对象需要被释放时,_gc元方法回调,释放掉java对象的globaref …</p></blockquote>
<br/ >
<a href="http://blog.aaapei.com/article/2014/02/luazai-kua-yu-yan-huan-jing-zhong-de-nei-cun-xie-lu">查看全文</a>
</div>
<div class="meta">
<span class="author">Posted by <a href="http://blog.aaapei.com/author/zhengwen.html">zhengwen</a></span>
</div>
</article>
<hr/>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-01-28T17:30:00.000000+0800" itemprop="datePublished">2014-01-28</time>
</div>
<div class="tags">
<a href="http://blog.aaapei.com/tags/android">android</a> </div>
</div> <h1 class="title" itemprop="name"><a href="http://blog.aaapei.com/article/2014/01/android-bitmap-tips" itemprop="url">android bitmap tips</a></h1>
<div class="entry-content" itemprop="description"><p>大部分android开发者只知道bitmap再使用之后,需要显式的调用一次bitmap.recycle,回收bitmap内存; </p>
<p>这个观点,在android3.0之后其实已经过时了,android3.0将bitmap所引用的位图资源从native heap移到虚拟机的heap空间,bitmap的生命周期由虚拟机管理,开发者只需要保证在应用中不在持有对bitmap的引用,即可保证不发生内存泄漏;位图资源的内存由GC进行回收;<br>
将bitmap的位图内存转移到虚拟机heap后,由于位图资源本身较大,造成gc的概率的增加 </p>
<h3>bitmap proxy</h3>
<p>在一般的应用场景中,bitmap的引用一般是和imageview关联;当大量imageview持有对bitmap的引用时,虚拟机无法释放bitmap的内存,导致oom;</p>
<p>针对这种场景,开发者可以实现一个bitmap的代理类,作为bitmap和imageview的中间层,在imageview不可见时(例如imageview是一个listview的子控件,listview发生滚动/activiy切换到后台),即释放掉对bitamp的引用;当imageview重新可见时,通过代理类重新去加载bitmap,以解耦bitmap和iamgeview的引用关系; </p>
<h3>inBitmap</h3>
<p>android在3.0之后新增了一个BitmapFactory.Options.inBitmap开关,加了这个开关之后,bitmapfactory在加载位图时候,会尝试使用inbitmap指向的已分配在heap中位图空间;而不是重新申请一块内存;从而减少了虚拟机最讨厌的短生命周期大内存对象; 不过这个开关有严格的使用场景,即两个bitamp的位图大小必须一致</p>
<br/ >
<a href="http://blog.aaapei.com/article/2014/01/android-bitmap-tips">查看全文</a>
</div>
<div class="meta">
<span class="author">Posted by <a href="http://blog.aaapei.com/author/zhengwen.html">zhengwen</a></span>
</div>
</article>
<hr/>
<nav id="pagenavi">
<a href="http://blog.aaapei.com/index2.html" class="prev">Prev</a>
<a href="http://blog.aaapei.com" class="center">文章列表</a>
<a href="http://blog.aaapei.com/index4.html" class="next">前一页</a>
</nav>
</div>
</div>
<footer id="footer" class="inner">
<p>Copyright © 2013 - aaapei - <span class="credit">Powered by <a href="http://getpelican.com">Pelican</a></span></p> </footer>
</div>
</div>
</body>
</html>