一、DataTable
DataTable表示内存中数据的一个表,它完全是在内存中的一个独立存在,包含了这张表的全部信息。DataTable可以是从通过连接从数据库中读取出来形成的一个表,一旦将内容读到DataTable中,此DataTable就可以跟数据源断开而独立存在;也可以是完全由程序自己通过代码来建立的一个表。
◆ DataColumn
一个表是由行和列组成的一个两维的结构。表的结构是由DataColumn 对象的集合组成,DataColumn 对象集合可由DataTable.Columns 属性中能获取到,通过定义每一列的数据类型来确定表的架构,类似数据库中定义表。定义完表的结构就可以根据结构来生成DataRow,用DataTable.NewRow()方法来生成此DataTable结构的新行。
一个DataTable是由DataRow的集合组成的, DataRow的集合这个可以由DataTable.Rows 属性来访问。
DataTable还可以通过现有的列用Expression 属性的表达式创建一些列。
1、创建计算出的列
比如:已经有了一个表结构,表中有一个DataColumn的集合,其中有一个叫UnitPrice的列,你可以新建一个DataColumn,设置好ColumnName,再设置此列的表达式,DataColumn.Expression = "UnitPrice * 0.086",这个列的值就是名字为UnitPrice的列计算出来的,在创建表达式时,使用 ColumnName 属性来引用列。
2、第二个用途是创建聚合列
聚合列聚合通常沿着关系执行(有关关系的描述见下面DataRelation部分),如果order表有名为 detail 的子表,两个表之间通过order.orderid和detail.orderid两个列建立一个关系 DataRelation 对象名为“order2detail”,在主表order中就可以建立一个聚合列,将计算每个order在detail表中含有的所有item的价格的和:DataColumn.Expression = “sum(child(order2detail).price)",child(order2detail)表示通过关系order2detail联系到的子表,child(order2detail).price就表示子表的price列。
◆ DataRow
DataRow对象没有直接在代码中使用的构造函数,一般是从具有一定结构的DataTable用NewRow()方法来新建一个DataRow对象。一个DataRow根据其是独立的,还是属于某个DataTable,是否修改过,是否被DataTable删除等等不同的情况有不同的状态,由DataRow.RowState属性公开,如下表:
成员名称 说明
Added 该行已添加到 DataRowCollection 中,AcceptChanges 尚未调用。Deleted 该行已通过 DataRow 的 Delete 方法被删除。
Deleted 该行已通过 DataRow 的 Delete 方法被删除。
Detached 该行已被创建,但不属于任何 DataRowCollection。DataRow 在以下情况下立即处于此状态:创建之后添加到集合中之前;或从集合中移除之后。
Modified 该行已被修改,AcceptChanges 尚未调用。
Unchanged 该行自上次调用 AcceptChanges 以来尚未更改。
一个DataRow对象刚被创建之后其状态是Detached,是孤立的一个存在,所以建立了DataRow之后在DataRow中的单元填充了数据后还要通过DataTable.Rows.Add(DataRow)方法将此DataRow添加到DataTable,DataRow添加到DataTable后, 这个DataRow的状态就转变为Added。当修改了这个DataRow后,这个DataRow状态转为Modified,当用DataRow.Delete()方法删除DataRow后,DataRow状态将转为Deleted,不过此行还存在在DataTable中的,只是状态改变了,这时用DataTable.Rows.Count查看行数,跟删除前是一样的。只有在调用了DataTable.Remove(DataRow)方法后,此DataRow才被从DataTable移除,状态也回复到Detached孤立状态。
一旦调用了DataTable.AcceptChanges()方法后,所有的行将根据不同的状态做不同的处理,Added、Modified、Unchanged将保留当前值,Deleted的行将从DataTable中移除,最后所有的行的状态都置为Unchanged。当DataTable是从DataAdapter.Fill(DataSet,DataTable)方法填充而形成的,Fill()方法将自动调用AcceptChanges()方法,将DataTable的行状态都置为Unchanged。并且,如果Fill方法中指定的那个DataTable在要填充的那个DataSet不存在时,会生成一个跟数据源表同样的结构的DataTable并填充数据。
◆ DataRelation
表示两个 DataTable 对象之间的父/子关系。可以类比于数据库中的表之间的关系,父表相当于关系列为主键的表,子表相当于关系列为外键的表。DataRelation 构造函数一般为:DataRelation(String, DataColumn, DataColumn) ,string为关系名,第一个DataColumn为建立关系的父表列,第二个DataColumn为建立关系的子表列,建立关系的两个列的 DataType 值必须相同。
建立好了关系,必须把这个关系加入到DataTable的ParentRelations属性或ChildRelations 属性,这两个属性包含这个表的所有的跟父表的关系和跟子表的关系。若关系中此表是父表则将此关系加入到ChildRelations集合中,否则加入到ParentRelations集合中。
二、DataView
DataView表示用于排序、筛选、搜索、编辑和导航的 DataTable 的可绑定数据的自定义视图。可以将DataView同数据库的视图类比,不过有点不同,数据库的视图可以跨表建立视图,DataView则只能对某一个DataTable建立视图。DataView一般通过DataTable.DefaultView 属性来建立,再通过通过RowFilter 属性和RowStateFilter 属性建立这个DataTable的一个子集。
RowFilter属性用来筛选要查看DataTable中哪些行的表达式,这个表达式同上面所说的建立计算列的表达式相同。例如:"LastName = Smith ",这就是只查看列LastName的值为 Smith 的那些数据行。
RowStateFilter 属性用来设置 DataView 中的行状态筛选器,上面介绍DataRow时介绍了DataRow的状态,一个DataRow可能有五种状态,RowStateFilter就是可以通过这些状态来筛选要查看的行集。其实DataRow不仅有五种状态,DataRow还有版本的问题,比如当DataRow的状态为Modified,即这行已经被修改了,这时这个DataRow就会有两个版本,Current版本和Original版本(修改前的)。实际上RowStateFilter属性是综合了DataRow的状态和版本来筛选的(RowStateFilter确省值是CurrentRows)见下表:
成员名称 说明
Added 一个新行。
CurrentRows 包括未更改行、新行和已修改行的当前行。
Deleted 已删除的行。
ModifiedCurrent 当前版本,原始数据(请参阅 ModifiedOriginal)的修改版本。
ModifiedOriginal 原始版本(尽管它后来已被修改并以 ModifiedCurrent 形式存在)。
None 无。
OriginalRows 包括未更改行和已删除行的原始行。
Unchanged 未更改的行。
DataView.Count属性得到的计数是在应用了 RowFilter 和 RowStateFilter 之后,获取 DataView 中记录的数量。
DataView是建立在DataTable基础上的,DataView.Table 属性可以得到此DataView对应的那个DataTable。DataView的行叫DataRowView,可以从DataRowView直接通过DataRowView.Row 属性得到此DataRowView对应的DataRow。
三、DataGrid
这里说的DataGrid是winform中的DataGrid,一般都是跟DataView绑定来显示DataTable中的数据,和修改DataTable中的数据。
DotNet的DataGrid的功能强大,可是在使用上与以前的习惯不太一样,有时还比较麻烦,所以很多人都对这个DataGrid感到有些摸不着头脑,有一种无从下手的感觉,其实把一些概念搞清楚了许多问题就会迎刃而解了。
DataGrid通过DataSource 和 DataMember 属性来绑定其要显示的数据源。数据源一般是DataTable、DataView、DataSet等,不过将这些数据源绑定到DataGrid时实际上是绑定的DataView。若数据源是DataTable时,实际上是绑定了此DataTable的DefaultView,若数据源是DataSet时,则可以向 DataMember 属性设置一个字符串,该字符串指定要绑定到的表,然后再将DataMember指定的那个DataTable的DefaultView绑定到DataGrid。
所以DataGrid实际显示的是DataTable经过筛选的DataView。
source: http://www.cnblogs.com/zhengxiqiang/archive/2009/07/26/1531301.html
Thursday, May 19, 2011
Sunday, April 3, 2011
三个字的。。。你们知道怎么读吗
三个金念鑫(xīn) 三个水念淼(miǎo) 三个火念焱(yàn)
三个土念垚(yáo) 三个牛念犇(bēn) 三个手念掱(pá)
三个目念瞐(mò) 三个田念畾(lěi) 三个马念骉(biāo)
三个羊念羴(shān) 三个犬念猋(biāo) 三个鹿念麤(cū)
三个鱼念鱻(xiān) 三个贝念赑(bì) 三个力念劦(lie)
三个毛念毳(cuì) 三个耳念聶(niè) 三个车念轟(hōng)
三个直念矗(chù)三个龙念龘(tà、dá) 三个原念厵(yuán)
三个雷念靐(bìng) 三个飞念飝(fēi) 三个刀念刕(lí)
三个又念叒(ruò)三个士念壵(zhuàng) 三个小念尛(mó)
三个子念孨(zhuǎn) 三个止念歮(sè) 三个风念飍(xiū)
三个隼念雥(zá) 三个吉念嚞(zhé)三个言念譶(tà)
三个舌念舙(qì) 三个香念馫(xīn) 三个泉念灥(xún)
三个心念惢(suǒ) 三个白念皛(xiǎo)
Friday, April 1, 2011
美股报价和走势图 (转)
股票报价和走势图:
StockCharts(美股实时行情、报价和走势图,非常优秀的技术图形分析功能,操作界面友好,有免费服务和付费服务,加拿大股票数据有15分钟延迟)
BigCharts(老牌的股票图形网站,有一些独特的技术图形指标和MarketWatch提供的企业研究报告,能够显示季线图和年线图,但是技术指标不能调整变量,设置免费服务)
Prophet.net(这个网站不如前面两个知名,但它有一些独特的技术分析指标)
QuoteTracker(免费的即时报价和技术分析软件,功能强大,需要有券商交易帐号)
行业及个股选择:
BigCharts(行业分类列表,不同时间段的行业和类股强弱排序)
ClearStation(可根据不同的技术指标和基本面数据排列行业和个股)
Barchart(该网站用特有的Weighted Alpha对行业和类股进行强弱排序)
StockCharts(该站每天根据多种技术指标自动搜索美国和加拿大的股票和公共基金)
上市公司研究:
Yahoo Finance(非常全面的北美企业新闻、财务数据、内线交易和竞争企业比较等;并不是所有股票都显示实时报价,但是提供详尽的历史行情数据,以及期权价格和企业的基本面数据)
Reuters(与Yahoo Finance的内容类似,需要注册免费会员)
财经新闻:
MarketWatch(及时、全面的北美财经报道和股市评论,话题广泛、内容详实)
Yahoo Finance(转载多家新闻机构的北美股市报道,分门别类,更新及时)
Econoday(北美财经日历,含各种经济指标的历史图表)
bloomberg (及时、全面的北美财经报道和股市评论,话题广泛、内容详实)
投资教育:
Investopedia(深入浅出的投资教育文章和财经词典)
Investment FAQ(很多股票投资和财务规划方面的话题,观点犀利)
StockCharts(技术分析方面的文章,配图讲解,浅显易懂)
Technical Analysis from A to Z(全面、详尽的技术分析教学)
期货交易:
Chicago Mercantile Exchange(芝加哥商业交易所,E-mini指数期货在此交易,有中文)
Chicago Board of Trade(芝加哥商品交易所,道琼斯指数期货在此交易,有中文)
Commodity Futures Trading for Beginners(针对初学者的教育性文章)
StockCharts(美股实时行情、报价和走势图,非常优秀的技术图形分析功能,操作界面友好,有免费服务和付费服务,加拿大股票数据有15分钟延迟)
BigCharts(老牌的股票图形网站,有一些独特的技术图形指标和MarketWatch提供的企业研究报告,能够显示季线图和年线图,但是技术指标不能调整变量,设置免费服务)
Prophet.net(这个网站不如前面两个知名,但它有一些独特的技术分析指标)
QuoteTracker(免费的即时报价和技术分析软件,功能强大,需要有券商交易帐号)
行业及个股选择:
BigCharts(行业分类列表,不同时间段的行业和类股强弱排序)
ClearStation(可根据不同的技术指标和基本面数据排列行业和个股)
Barchart(该网站用特有的Weighted Alpha对行业和类股进行强弱排序)
StockCharts(该站每天根据多种技术指标自动搜索美国和加拿大的股票和公共基金)
上市公司研究:
Yahoo Finance(非常全面的北美企业新闻、财务数据、内线交易和竞争企业比较等;并不是所有股票都显示实时报价,但是提供详尽的历史行情数据,以及期权价格和企业的基本面数据)
Reuters(与Yahoo Finance的内容类似,需要注册免费会员)
财经新闻:
MarketWatch(及时、全面的北美财经报道和股市评论,话题广泛、内容详实)
Yahoo Finance(转载多家新闻机构的北美股市报道,分门别类,更新及时)
Econoday(北美财经日历,含各种经济指标的历史图表)
bloomberg (及时、全面的北美财经报道和股市评论,话题广泛、内容详实)
投资教育:
Investopedia(深入浅出的投资教育文章和财经词典)
Investment FAQ(很多股票投资和财务规划方面的话题,观点犀利)
StockCharts(技术分析方面的文章,配图讲解,浅显易懂)
Technical Analysis from A to Z(全面、详尽的技术分析教学)
期货交易:
Chicago Mercantile Exchange(芝加哥商业交易所,E-mini指数期货在此交易,有中文)
Chicago Board of Trade(芝加哥商品交易所,道琼斯指数期货在此交易,有中文)
Commodity Futures Trading for Beginners(针对初学者的教育性文章)
Saturday, March 26, 2011
Nook Color Tips (1)
. Why is everything on my screen so small?
- this is because the NookColor's stock LCD density is 169.333, which is pretty low (Galaxy Tab is 240). Unlike resolution, which is hardware-based, density is software-based and can be changed. If you search the market for LCD density, there are a couple apps that will do this--a free one that
won't survive a hard reboot, and a paid one that (supposedly) will.
If you want to make it permanent for free, you can edit your build.prop file. Again, use Root Explorer to open system/build.prop (BACKUP FIRST!), find the following two lines:
ro.sf.lcd_density.xdpi=169.33333
ro.sf.lcd_density.ydpi=169.33333
If you wanted your density to be 250, you'd replace them with the following single line:
ro.sf.lcd_density=250
Save the edited file, and reboot.Here are two of my Galaxy Tab-esque homescreens set to 250:
Now, jacking up your LCD density much above 200 will make your status bar look wonky and cut-off. One solution for this is to set it to 250, like above (by changing build.prop - I think the apps I mentioned only allow multiples of 20), which will make it look clean (as long as wifi is on).
The only problem there is that you'll lose your status bar clock and Notifications in portrait mode . . .
. . . the solution for THIS is to get two apps: hellostatusbar, and quick launch. Set quick launch to open hellostatusbar on a home- button double press, and it will display your Notifications.
Also note that raising the density can cut-off parts of the stock Barnes & Noble software (they're designed for the lower density), so this mod is probably better for people like me who use the Kindle app and ezPDF for reading.
Any other battery-saving tips?
In case you missed the rival xda threads arguing over who thought of it first, there was a potentially useful battery-saving trick in there:
Go back in Root Explorer, and in system/app, mount as r-w and rename Phone .apk and TelephonyProvider.apk to anything else (adding .bak onto the end would be fine).
Basically, you're removing android system files that may be wasting juice looking for a non-existent cell service. It's unsure if or how much this actually improves battery life, but it very well could, and it certainly won't hurt anything changing their names.
How can I prevent the Nook from automatically updating the firmware?
- Change the name of etc/security/otacerts.zip to anything else (doing this in Root Explorer works fine). So far, this had looked pretty solid in successfully disabling OTA updates.
Why won't YouTube play videos in HD?
For some reason, the YouTube that's installed from rooting won't do it. To get a version that plays HD:
- uninstall your current YouTube via Titanium Backup
- download this version from the Evo (credit aludal): http://db.tt/y5vVvI2
- rather than installing this one, rename it youtube.apk and copy it into system/app (w/permissions matching the other apk's in that folder)
It should be there now, ready to play HQ clips. If not, reboot first.
- this is because the NookColor's stock LCD density is 169.333, which is pretty low (Galaxy Tab is 240). Unlike resolution, which is hardware-based, density is software-based and can be changed. If you search the market for LCD density, there are a couple apps that will do this--a free one that
won't survive a hard reboot, and a paid one that (supposedly) will.
If you want to make it permanent for free, you can edit your build.prop file. Again, use Root Explorer to open system/build.prop (BACKUP FIRST!), find the following two lines:
ro.sf.lcd_density.xdpi=169.33333
ro.sf.lcd_density.ydpi=169.33333
If you wanted your density to be 250, you'd replace them with the following single line:
ro.sf.lcd_density=250
Save the edited file, and reboot.Here are two of my Galaxy Tab-esque homescreens set to 250:
Now, jacking up your LCD density much above 200 will make your status bar look wonky and cut-off. One solution for this is to set it to 250, like above (by changing build.prop - I think the apps I mentioned only allow multiples of 20), which will make it look clean (as long as wifi is on).
The only problem there is that you'll lose your status bar clock and Notifications in portrait mode . . .
. . . the solution for THIS is to get two apps: hellostatusbar, and quick launch. Set quick launch to open hellostatusbar on a home- button double press, and it will display your Notifications.
Also note that raising the density can cut-off parts of the stock Barnes & Noble software (they're designed for the lower density), so this mod is probably better for people like me who use the Kindle app and ezPDF for reading.
Any other battery-saving tips?
In case you missed the rival xda threads arguing over who thought of it first, there was a potentially useful battery-saving trick in there:
Go back in Root Explorer, and in system/app, mount as r-w and rename Phone .apk and TelephonyProvider.apk to anything else (adding .bak onto the end would be fine).
Basically, you're removing android system files that may be wasting juice looking for a non-existent cell service. It's unsure if or how much this actually improves battery life, but it very well could, and it certainly won't hurt anything changing their names.
How can I prevent the Nook from automatically updating the firmware?
- Change the name of etc/security/otacerts.zip to anything else (doing this in Root Explorer works fine). So far, this had looked pretty solid in successfully disabling OTA updates.
Why won't YouTube play videos in HD?
For some reason, the YouTube that's installed from rooting won't do it. To get a version that plays HD:
- uninstall your current YouTube via Titanium Backup
- download this version from the Evo (credit aludal): http://db.tt/y5vVvI2
- rather than installing this one, rename it youtube.apk and copy it into system/app (w/permissions matching the other apk's in that folder)
It should be there now, ready to play HQ clips. If not, reboot first.
Tuesday, March 8, 2011
Using Google Docs to manage your stock portfolio
By integrating services like Google Finance, Search in to spreadsheet functions, google docs has paved the way for endless possibilities.
Google spreadsheet function
GoogleFinance() can be used to build stock portfolio tracker sheet that can fetch historical stock quotes to tell how your money is doing.Click here to see the stock portfolio tracker sheet on Google docs.
Here is how you can create a simple stock / mutual fund / asset tracker application using Google docs:
1. Create the stock portfolio tracker table structure
A typical portfolio tracker has the following columns:
- Name of the asset – Stock name, MF name etc.
- # of units / shares held
- Purchase date
- Purchase price (will be fetched from GoogleFinance using formulas)
- Current price (also fetched from GoogleFinance)
- Gain / Loss % and values
2. The formulas to fetch current and historical quotes
Assuming the stock / company symbol as per the listing exchange is in cell B2 and purchase date is in cell C2, we can fetch historical stock price for that symbol on purchase date by the formula,
=GoogleFinance(B2,"price",C2)But there is a problem with this formula as result is not single cell, but a 2×2 range as shown on the right.
It returns date and price in 2 columns. We are only interested in the price of the stock on that date (ie bottom right cell in the returned range). We can fetch that value by using concatenate(), find() and mid() functions to parse out the required text. So the formula now becomes:
=concatenate(GoogleFinance(B2,"price",C2)) and then in the cell where the historical price is needed we enter=value(mid(M2,3+find(":",M2,1+find(":",M2)),99))In order to fetch the current stock price we just need to enter
=googlefinance(B2)Note: Make sure that you use correct symbols for stocks / mutual funds and mm/dd/yyyy date formats for purchase date.
or try =index(googlefinance(…),2,2).
3. Finally add Gain / Loss calculations
This is a simple step where in we compute value on purchase and value today and then use them to compute Gain / Loss. We can modify the table to add some conditional formatting so that when a loss is made the numbers are in red color.
4. Enhancing the Portfolio Tracker
That is all. This is how we can create a simple stock portfolio tracker. But there are several interesting ways in which you can extend this.
- Add a spreadsheet form and use that to record stock purchases.
- Perform a thorough analysis of your holdings, research the companies, price trends etc. without leaving the spreadsheet.
- Get alerts when a price threshold is met, through RSS / email updates
- Add some graphs to see how / where your money going
source: http://chandoo.org/wp/2008/09/12/track-stock-mf-portfolio-google-docs/
Monday, February 21, 2011
Mac OS X 下使用 SSD固态硬盘优化设置手册
本文是把SSD固态硬盘作为第二硬盘装载的,采用光驱位硬盘托架安装。
把 MBP 拆开,SuperDrive 取下,把原来的硬盘取出,放入光驱位硬盘托架,把 SSD 接在原来的硬盘所接的 SATA 口,然后把硬盘托架安装回原来光驱的位置。这种搭配是为了保证用 SSD 做系统盘 (挂载在 / 上) 时系统能正确的让硬盘休眠。当然,如果你比较奢侈地买两块 SSD,也可以让他们组成 RAID0,这样性能就更夸张了。
给在 SSD固体硬盘所在卷分区安装系统,只需要分一个区。新的系统会把原来那块硬盘也列出来。
这时修改 /etc/fstab,加入: /dev/disk1s2 /Users/用户名/Downloads hfs rw
上面的用户名是你的系统登录用户名字,自己替换一下!
这个做法是把原来那块硬盘挂载在我自己这个用户的 Downloads 目录,这样所有下载的内容都会放在这块比较大的硬盘上 (当然有用的我以后会转移到 SSD 上),考虑到 Downloads 主要起的就是一个临时的缓冲作用,这样还是比较方便的。然后重启机器,就能发现这块硬盘只被挂载在上述目录下了。
除了下载内容,我还在这个目录放以下内容:
VMware Fusion 的虚拟机文件,这是从别的机器复制过来的,直接放在这个卷的 /Virtual Machines 目录下,然后在 VMware Fusion 里打开就行了。需要注意的是以后 VMware 里创建新虚拟机的时候也得记住选择目录,别放在自己的 $HOME/Documents 下面了。
iTunes 媒体库,这个可以在 iTunes 的 Preferences -> Advanced -> iTunes Media folder location 选择。我是先在这里选好了,然后从原来的机器里导入以前的 iTunes 数据。
其他下载软件的默认下载位置,包括 uTorrent, Transmission 和 aMule。
下面是一些优化步骤:
用 noatime 方式挂载系统盘,这样可以减少不必要的 I/O 次数,虽然 SSD 做这些操作非常快速,但考虑到最后访问时间这个属性其实很少用到,大家关心的一般都是最后修改时间和创建时间,所以完全可以关闭这个属性,这在 Unix/Linux 下是非常常见的文件系统优化选项。一个简单的方法是,修改 /etc/fstab,加入:
/dev/disk0s2 / hfs rw,noatime
重启后,系统盘的挂载就带上 noatime 选项了:
$ mount | grep " / "
/dev/disk0s2 on / (hfs, local, journaled, noatime)
禁用冬眠 (hibernate) 模式以节省空间。在 Mac 耗尽电池时,会进入“冬眠”模式,将内存中的所有内容写入磁盘,下次唤醒后从这些内容恢复状态。所以系统会在 /var/vm 维护一个和内存等大的 sleepimage 文件,考虑到 SSD 空间宝贵,而一般绝少会遇到耗尽电池的情况,可以禁用掉这个功能以节省空间:
$ sudo pmset -a hibernatemode 0
$ sudo rm /var/vm/sleepimage
减少临时文件的读写。
RAMDisk 是常见的性能优化手段,对于内存充足的机器,把频繁读写的内容放到一个用内存为存储的虚拟磁盘中,能大大加快速度。虽然 Macintosh Performance Guide 最近的一个研究表明 RAMDisk 并不能很大地提升如 Photoshop 这类软件操作的性能,至少投入产出比不是很经济,但至少用它来保存一些本来就可以随意丢弃的数据是个很好的思路。Mac OS X SSD Tweaks 提供了创建 RAMDisk 的脚本,他的做法是在系统启动时创建一个 256M 的 RAMDisk,挂载在 /private/tmp 上面。他还建议把 ~/Library/Caches 也放到 RAMDisk 里。最大的问题是,如果你长期不重启 (我一般的重启周期是 80 ~ 100 天),那有的临时文件,比如 ~/Library/Caches/com.apple.Safari/Webpage Previews/ 会增长到数百 M 甚至上 G。如果被它占满了 RAMDisk 的空间,那其他缓存数据就写不进去了。
考虑到 RAMDisk 是个比较有风险的优化手段,也可以用以下方法禁用掉 Safari 的 Webpage Previews 以减少临时文件读写。如果你像我一样从来不用 Safari 的“Top Sites”功能,一定会很讨厌它凭空占用大量的空间。
$ chmod 500 ~/Library/Caches/com.apple.Safari/Webpage Previews/
关闭 Spotlight 索引也是一个有用的优化手段,如果你像我这样从来不用 Spotlight 的话。
如果是MAC OS X的用户,可以参考一下上面的SSD固态硬盘优化的过程,虽然不做优化也可以用,但是这样做可以保证系统性能最佳,以及可以延长MLC SSD固态硬盘的寿命,所以如果你太算小白的话,还是可以动手试试的!
source: http://www.u2game.net/bbs/thread-29808-1-1.html
把 MBP 拆开,SuperDrive 取下,把原来的硬盘取出,放入光驱位硬盘托架,把 SSD 接在原来的硬盘所接的 SATA 口,然后把硬盘托架安装回原来光驱的位置。这种搭配是为了保证用 SSD 做系统盘 (挂载在 / 上) 时系统能正确的让硬盘休眠。当然,如果你比较奢侈地买两块 SSD,也可以让他们组成 RAID0,这样性能就更夸张了。
给在 SSD固体硬盘所在卷分区安装系统,只需要分一个区。新的系统会把原来那块硬盘也列出来。
这时修改 /etc/fstab,加入: /dev/disk1s2 /Users/用户名/Downloads hfs rw
上面的用户名是你的系统登录用户名字,自己替换一下!
这个做法是把原来那块硬盘挂载在我自己这个用户的 Downloads 目录,这样所有下载的内容都会放在这块比较大的硬盘上 (当然有用的我以后会转移到 SSD 上),考虑到 Downloads 主要起的就是一个临时的缓冲作用,这样还是比较方便的。然后重启机器,就能发现这块硬盘只被挂载在上述目录下了。
除了下载内容,我还在这个目录放以下内容:
VMware Fusion 的虚拟机文件,这是从别的机器复制过来的,直接放在这个卷的 /Virtual Machines 目录下,然后在 VMware Fusion 里打开就行了。需要注意的是以后 VMware 里创建新虚拟机的时候也得记住选择目录,别放在自己的 $HOME/Documents 下面了。
iTunes 媒体库,这个可以在 iTunes 的 Preferences -> Advanced -> iTunes Media folder location 选择。我是先在这里选好了,然后从原来的机器里导入以前的 iTunes 数据。
其他下载软件的默认下载位置,包括 uTorrent, Transmission 和 aMule。
下面是一些优化步骤:
用 noatime 方式挂载系统盘,这样可以减少不必要的 I/O 次数,虽然 SSD 做这些操作非常快速,但考虑到最后访问时间这个属性其实很少用到,大家关心的一般都是最后修改时间和创建时间,所以完全可以关闭这个属性,这在 Unix/Linux 下是非常常见的文件系统优化选项。一个简单的方法是,修改 /etc/fstab,加入:
/dev/disk0s2 / hfs rw,noatime
重启后,系统盘的挂载就带上 noatime 选项了:
$ mount | grep " / "
/dev/disk0s2 on / (hfs, local, journaled, noatime)
禁用冬眠 (hibernate) 模式以节省空间。在 Mac 耗尽电池时,会进入“冬眠”模式,将内存中的所有内容写入磁盘,下次唤醒后从这些内容恢复状态。所以系统会在 /var/vm 维护一个和内存等大的 sleepimage 文件,考虑到 SSD 空间宝贵,而一般绝少会遇到耗尽电池的情况,可以禁用掉这个功能以节省空间:
$ sudo pmset -a hibernatemode 0
$ sudo rm /var/vm/sleepimage
减少临时文件的读写。
RAMDisk 是常见的性能优化手段,对于内存充足的机器,把频繁读写的内容放到一个用内存为存储的虚拟磁盘中,能大大加快速度。虽然 Macintosh Performance Guide 最近的一个研究表明 RAMDisk 并不能很大地提升如 Photoshop 这类软件操作的性能,至少投入产出比不是很经济,但至少用它来保存一些本来就可以随意丢弃的数据是个很好的思路。Mac OS X SSD Tweaks 提供了创建 RAMDisk 的脚本,他的做法是在系统启动时创建一个 256M 的 RAMDisk,挂载在 /private/tmp 上面。他还建议把 ~/Library/Caches 也放到 RAMDisk 里。最大的问题是,如果你长期不重启 (我一般的重启周期是 80 ~ 100 天),那有的临时文件,比如 ~/Library/Caches/com.apple.Safari/Webpage Previews/ 会增长到数百 M 甚至上 G。如果被它占满了 RAMDisk 的空间,那其他缓存数据就写不进去了。
考虑到 RAMDisk 是个比较有风险的优化手段,也可以用以下方法禁用掉 Safari 的 Webpage Previews 以减少临时文件读写。如果你像我一样从来不用 Safari 的“Top Sites”功能,一定会很讨厌它凭空占用大量的空间。
$ chmod 500 ~/Library/Caches/com.apple.Safari/Webpage Previews/
关闭 Spotlight 索引也是一个有用的优化手段,如果你像我这样从来不用 Spotlight 的话。
如果是MAC OS X的用户,可以参考一下上面的SSD固态硬盘优化的过程,虽然不做优化也可以用,但是这样做可以保证系统性能最佳,以及可以延长MLC SSD固态硬盘的寿命,所以如果你太算小白的话,还是可以动手试试的!
source: http://www.u2game.net/bbs/thread-29808-1-1.html
Sunday, February 20, 2011
Mac something ....
1. To find 'Showing Package Contents'
cd /Applications to get there and cd ~ to return to your home folder
or
Applications folder, locate Twitter, right click, Show Package Contents
2. MacKeeper 0.9.7.1 http://soft.macx.cn/soft3944.htm
JDiskReport http://www.jgoodies.com/freeware/jdiskreport/index.html
3. *Mac OSX: Where has my hard drive space gone? http://ask.metafilter.com/109945/Mac-OSX-Where-has-my-hard-drive-space-gone
*Cleaning Your Mac's Hard Drive http://guides.macrumors.com/Cleaning_Your_Mac%27s_Hard_Drive
*Freeing Up Hard Disk Space http://guides.macrumors.com/Freeing_Up_Hard_Disk_Space
*Free up Hard Disk space http://creativebits.org/mac_os_x/free_up_hard_disk_space
*How to Free Up 3GB of Hard Drive Space on Your Mac In 2 Minutes http://macyay.com/free-up-3gb-of-space-in-2-minutes/
*Running out of disk space on a Mac? http://www.askdavetaylor.com/running_out_of_disk_space_on_a_mac.html
*How to Free Up Hard Disk Space with Squeeze http://mac.appstorm.net/how-to/utilities-how-to/how-to-free-up-hard-disk-space-with-squeeze/
*4 Easy Steps to Free Up Hard Drive Space on your Mac OS X Hard Drive http://xentek.net/articles/452/free-up-hard-drive-space-on-your-mac/
5.
cd /Applications to get there and cd ~ to return to your home folder
or
Applications folder, locate Twitter, right click, Show Package Contents
2. MacKeeper 0.9.7.1 http://soft.macx.cn/soft3944.htm
JDiskReport http://www.jgoodies.com/freeware/jdiskreport/index.html
3. *Mac OSX: Where has my hard drive space gone? http://ask.metafilter.com/109945/Mac-OSX-Where-has-my-hard-drive-space-gone
*Cleaning Your Mac's Hard Drive http://guides.macrumors.com/Cleaning_Your_Mac%27s_Hard_Drive
*Freeing Up Hard Disk Space http://guides.macrumors.com/Freeing_Up_Hard_Disk_Space
*Free up Hard Disk space http://creativebits.org/mac_os_x/free_up_hard_disk_space
*How to Free Up 3GB of Hard Drive Space on Your Mac In 2 Minutes http://macyay.com/free-up-3gb-of-space-in-2-minutes/
*Running out of disk space on a Mac? http://www.askdavetaylor.com/running_out_of_disk_space_on_a_mac.html
*How to Free Up Hard Disk Space with Squeeze http://mac.appstorm.net/how-to/utilities-how-to/how-to-free-up-hard-disk-space-with-squeeze/
*4 Easy Steps to Free Up Hard Drive Space on your Mac OS X Hard Drive http://xentek.net/articles/452/free-up-hard-drive-space-on-your-mac/
5.
Subscribe to:
Posts (Atom)