标题:发两个在linux下折腾的结果 linux的意义在于折腾
取消只看楼主
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
结帖率:100%
 问题点数:0 回复次数:0 
发两个在linux下折腾的结果 linux的意义在于折腾
程序代码:
#!/bin/bash
# sunpinyin_speed_up.sh
# Sunpinyin Speed Up Script for Ubuntu (by memory caching, and no data loss)
# You can run this script in background on GNOME logging in.
# Originally written Hubert Star, modified by Bob Robot (http://).
# Modified by zklhp.
# Capture the exit signal, make sure it is the FIRST uncommented line.
trap "do_exit" SIGHUP SIGINT SIGQUIT SIGTERM
SUN_DIR="${HOME}/.sunpinyin"
SUN_DIR_BACKUP="${HOME}/.sunpinyin_backup"
SHM_DIR="/dev/shm"
SHM_SUN_DIR="/dev/shm/.sunpinyin"
# Backup the userdict and restore all changes made by this script on exit.
do_exit() {
    mv -f "${SHM_SUN_DIR}" "${HOME}"
    rm -Rdf "${SHM_SUN_DIR}"
    rm -Rdf "${SUN_DIR}"
    mv -f "${SUN_DIR_BACKUP}" "${SUN_DIR}"
    exit 0
}
# Work around for abnormal quit.
if [ -e "${SUN_DIR_BACKUP}" ]; then
    rm -Rdf "${SHM_SUN_DIR}"
    mv -f "${SUN_DIR_BACKUP}" "${SUN_DIR}"
fi
# Rename the real userdict, copy it to RAM and make a symblic link back.
# From now on the modification and query on userdict takes place in RAM.
cp -Rf "${SUN_DIR}" "${SHM_DIR}"
mv -f "${SUN_DIR}" "${SUN_DIR_BACKUP}"
ln -sf "${SHM_SUN_DIR}" "${SUN_DIR}"
# I start fcitx here.
fcitx
# Automatically backup the userdict, make sure not losing the modification.
p_count=0
while [ true ]; do
    p_count=$(($p_count+1))
    sleep 1800
 
    if [ $p_count == 2 ]; then
    p_count=0
    cp -Rf "${SHM_SUN_DIR}" "${HOME}"
    fi
done


解决了sunpinyin用户词库慢的问题 根据网上的一个代码改写 网上的代码只是把用户词库文件放内存了 但那样 一旦对用户词库做插入操作SQLite会生成一个journal文件 而当用户词库比较大的时候 这个文件在硬盘上的话是很慢的 于是 整个目录全部放在内存里面

该方法有一定的危险性 建议使用前做好备份 这样的话在我这里还是会卡的 只不过卡1秒 基本不影响使用就是了

这个方法的通用性比较好 可以推广到其他因为硬盘效率低而影响流畅性的软件上 前提是内存足够

第二个 linux下的emacs打开最大化或全屏

程序代码:
(if (string-equal system-type "gnu/linux")
    (progn
      (add-hook 'after-make-frame-functions
        (lambda (new-make-frame)
          (select-frame new-make-frame)
          (set-frame-parameter nil 'fullscreen 'maximized)
          )
        (set-frame-parameter nil 'fullscreen 'maximized)
        )
      )
  )


maximized 改成fullboth就是全屏 改天试试windows下好使不好使。。

打完收工


[ 本帖最后由 zklhp 于 2013-3-10 10:17 编辑 ]
搜索更多相关主题的帖子: memory written background linux 
2013-03-10 10:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-400319-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016488 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved