Passthru中为什么要不直接把Packet发送或接收,而另外再建一个MyPacket用来发

NDIS4.0及5.0中的中间层驱动必须分配新的包描述符,即使不对包做任何修改(如同Passthru那样)。NDIS5.1支持Packet stack方式

看DDK的说明:
NDIS 4.0 and 5.0 intermediate drivers must allocate a new NDIS_PACKET to encapsulate data that they pass on. These intermediate drivers must also copy any out-of-band (OOB) data to the new packet. Even if the intermediate driver does nothing other than simply pass on incoming packets — for example, if it simply counts the packets — it must allocate a fresh packet descriptor and manage some or all of a new packet structure.

NDIS 5.1 intermediate drivers that support packet stacking avoid this extra data handling in most common cases. Each NDIS_PACKET allocated includes "stacks", where each stack is defined as:

typedef struct _NDIS_PACKET_STACK
{
ULONG_PTR IMReserved[2];
ULONG_PTR NdisReserved[4];
} NDIS_PACKET_STACK, *PNDIS_PACKET_STACK;

NDIS 5.1 intermediate drivers call the NdisIMGetCurrentPacketStack function to access the IMReserved member in the NDIS_PACKET_STACK structure. This member can be used by an NDIS 5.1 intermediate driver to store its context information, if any, for the packet. NDIS 4.0 and 5.0 intermediate drivers use the ProtocolReserved and MiniportReserved members, for sent and received packets, in the NDIS_PACKET structure. If a call to NdisIMGetCurrentPacketStack indicates *StacksRemaining is FALSE, the NDIS 5.1 intermediate driver must revert to the NDIS 5.0 packet handling model.

Every NDIS 4.0 and 5.0 intermediate driver must allocate new packet descriptors to replace those of the overlying driver. If an intermediate driver converts the packet from one format to another, it also can allocate buffer descriptors to map intermediate-allocated buffers into which the converted data is copied. If there is OOB data associated with the packet descriptor being copied, this data can be copied to the new OOB block associated with the intermediate-allocated packet descriptor, using the macro NDIS_OOB_DATA_FROM_PACKET, to obtain a pointer to the OOB data area and, then, calling NdisMoveMemory to move the contents into the OOB area associated with the new packet descriptor. Alternatively, such an intermediate driver can use the NDIS_GET_PACKET_XXX and NDIS_SET_PACKET_XXX macros to read specific items from the OOB data associated with the old packet descriptor and to write the OOB data for the new packet descriptor.

删除右键菜单中的Git

安装完Git之后,会发现在系统(此指windows)的右键菜单中会多出Git的三个选项:Git Init Here 、Git Gui 和Git Bash。

如果你用不着上述三个命令,而且也跟我一样觉着很长的右键菜单觉着不爽,那你可以按照以下的方法移除右键菜单的Git命令

1.找到你Git的安装路径,如:D:\Program\Git,在这个路径中找到“git-cheetah”文件夹

2. cd D:\Program\Git\git-cheetah

3. regsvr32 /u git_shell_ext.dll

对于 64位系统,执行

regsvr32 /u git_shell_ext64.dll

cmake两个错误的解决方法

问题1:

-- Check for working CXX compiler: CMAKE_CXX_COMPILER-NOTFOUND
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.

解决方法:

sudo apt-get install g++

问题2:

CMake Error at /usr/share/cmake-2.6/Modules/FindKDE4.cmake:84 (MESSAGE):
ERROR: cmake/modules/FindKDE4Internal.cmake not found in
/home/mm/.kde/share/apps;/usr/share/kde4/apps[/code]

解决方法:

sudo apt-get install kdelibs5-dev

Eclipse 启动后被 "Android Library Update" 任务所阻塞

有时候 Eclipse 启动后,会一直阻塞在 "Android Library Update" 任务中,无法执行任何操作,包括保存文件修改、编译、运行等,甚至正常退出 Eclipse 都不行。这一般是由于上一次的不正常退出所导致的。

如果反复重启 Eclipse 依然如此,可以试试这个办法:在启动 Eclipse 后,立即执行 "Clean all projects" 任务(必须赶在 "Android Library Update" 自动执行之前,否则会被其阻塞而无法做任何事情)。执行完 "Clean all projects" 之后,应该就不会再被阻塞了。

更彻底的办法是,删掉 workspace 下面的 .metadata 目录,不过该方法比较暴力,将会清除所有的 project 信息,建议慎用。

引用链接 http://minotes.net/notes/15

Ubuntu 12.04 Server安装Bittorrent Transmission

Ubuntu Server 没有图形界面,如果作为BT 下载服务器的话,可以使用Bittorrent Transmission 来通过Web界面操作,类似http://192.168.1.X:9091这样的方式管理下载。

1.安装服务器端

2.配置文件修改

主要调整如下部分的内容

也就是调整白名单为所有地址都可以网络访问,同时修改用户名密码到自己熟悉的即可。其中  "download-dir" 用来调整文件下载到的地址,这个自己调整即可。

3.使得配置信息生效(注意,必须使用此命令,否则Bittorrent Transmission 会在重启的时候把数据写回磁盘,导致修改无效)

4.修改系统配置文件,开放对于UDP的访问限制

增加如下语句

然后重启服务器。

5.通过浏览器访问即可。

Android 字体调整 fontScale 变化导致界面显示异常的问题

Android 字体调整,比如调整为超大字体,此时会导致Configuration 中的fontScale 变化导致界面显示异常。目前找到的办法为,在Application 的OnCreate 事件中增加如下代码

继承并覆盖 onConfigurationChanged 方法

在 AndroidManifest.xml 中的 application 部分增加处理 onConfigurationChanged 事件的声明

可以解决问题,但是会不会引起其他副作用,暂时未知。

Android 报告 java.lang.StackOverflowErrors 异常的问题分析

一般情况下,在使用比较复杂的布局的时候,尤其是 Fragment + ViewPager + SlideMenu 这种组合的情况下,会报告类似如下内容的崩溃栈信息

该异常在 2.X版本的Android系统上面表现尤为明显,往往 4.X版本的一切正常或者偶有卡顿,在 2.X版本上面直接崩溃。

分析一下,是一个 draw() -> dispatchDraw() -> drawChild() 的深度递归调用导致栈的溢出越界。对于 Android目前使用的 dalvik 虚拟机而言,系统默认的栈深度如下

Browsing for stack sizes through the dalvik source history:

也就是说,如果 draw() -> dispatchDraw() -> drawChild()  递归的深度太深,就会导致栈的不足问题。

解决方法, 目前貌似 dalvik 虚拟机 并不支持动态的修改栈的深度,这导致问题复杂化,首先,Fragment + ViewPager + SlideMenu  这种组合,即是什么都不增加,就已经有超过 10 层的递归了,这个可以在崩溃栈中的 drawChild 函数的数量就可以统计出来,这也就意味着,目前只有一条路可以走,那就是想办法减少布局的层次。有建议废弃 Fragment 来自己实现一套完整的东西,暂时还不建议如此操作。

一般方法就是

1.使用RelativeLayout 来减少尤其是 LinearLayout导致的布局深度问题,尽量在同层展开。

2.复杂布局的情况下,可以使用自定义View来实现,实在不行,可以自己计算坐标,直接绘制,比如用类似游戏的SurfaceView 之类的东西来替代。

3.利用 merge 来简化收缩布局,目前貌似FrameLayout 上面比较合适。

4.继承ViewGroup 的自定义View也是一层,这点不要忘记,能直接继承View的,就不要继承 ViewGroup

其他的方法,根据实际项目来处理好了。

Android抽象布局——include、merge 、ViewStub

在布局优化中,Android的官方提到了这三种布局,并介绍了这三种布局各有的优势,下面也是简单说一下他们的优势,以及怎么使用,记下来权当做笔记。

1、布局重用
标签能够重用布局文件,简单的使用如下:

1)标签可以使用单独的layout属性,这个也是必须使用的。

2)可以使用其他属性。标签若指定了ID属性,而你的layout也定义了ID,则你的layout的ID会被覆盖。
3)在include标签中所有的android:layout_*都是有效的,前提是必须要写layout_width和layout_height两个属性。
4)布局中可以包含两个相同的include标签,引用时可以使用如下方法解决(参考):

2、减少视图层级

标签在UI的结构优化中起着非常重要的作用,它可以删减多余的层级,优化UI。多用于替换FrameLayout或者当一个布局包含另一个时,标签消除视图层次结构中多余的视图组。例如你的主布局文件是垂直布局,引入了一个垂直布局的include,这是如果include布局使用的LinearLayout就没意义了,使用的话反而减慢你的UI表现。这时可以使用标签优化。

现在,当你添加该布局文件时(使用标签),系统忽略节点并且直接添加两个Button。更多介绍可以参考《Android Layout Tricks #3: Optimize by merging

3、需要时使用
标签最大的优点是当你需要时才会加载,使用他并不会影响UI初始化时的性能。各种不常用的布局想进度条、显示错误消息等可以使用标签,以减少内存使用量,加快渲染速度。是一个不可见的,大小为0的View。标签使用如下:

当你想加载布局时,可以使用下面其中一种方法:

当调用inflate()函数的时候,ViewStub被引用的资源替代,并且返回引用的view。 这样程序可以直接得到引用的view而不用再次调用函数findViewById()来查找了。
注:ViewStub目前有个缺陷就是还不支持 标签。

更多标签介绍可以参考《Android Layout Tricks #3: Optimize with stubs

转自 http://blog.csdn.net/xyz_lmn/article/details/14524567

Android 背景图片平铺

一般布局设置的背景图都是做拉伸处理,有时候我们需要背景图片做平铺处理,类似于网页开发中CSS的repeat。
在Android中可以使用如下方法使背景图片平铺。在drawable目录下创建一个repeat_bg.xml:

然后在布局的xml文件中可以这样引用: