读书时间 2010-05-24 C/C++

《Linux高级程序设计》2nd version,杨宗德

 

1. 杂问

Q:我们的系统如何保持其OS可移植性的?使用ANSI库吗?

 

2. extern

好像只有变量需要extern声明,function不需要,如下例:

 

[root@frank extern]# cat file.c
#include <stdio.h>
int i=0;
void test() {
        printf("in function: i=%d/n", i);
}

[root@frank extern]# cat test.c
#include <stdio.h>
//extern i;
int main() {
//      printf("in main, i=%d/n", i);
        test();
        return 0;
}

T:Got it ! 函数的默认storage type为extern,所以无需显式声明。

 

3. valgrind,内存调试工具

 

[root@frank valgrind]# cat sample.c
#include <stdio.h>

int main() {
        int i[5];
        if (i[0] == 0) {
                i[1]=1;
        }
        return 0;
}

 

[root@frank valgrind]# valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./sample
==3545== Memcheck, a memory error detector.
==3545== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==3545== Using LibVEX rev 1658, a library for dynamic binary translation.
==3545== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==3545== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==3545== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==3545== For more details, rerun with: -v
==3545==
==3545== Conditional jump or move depends on uninitialised value(s)
==3545==    at 0x804836A: main (in /study/books/alp2/valgrind/sample)
==3545==
==3545== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 13 from 1)
==3545== malloc/free: in use at exit: 0 bytes in 0 blocks.
==3545== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==3545== For counts of detected errors, rerun with: -v
==3545== All heap blocks were freed -- no leaks are possible.

 

4. 文件访问

缓冲文件访问会有用户态与内核态的切换,频繁使用对程序性能影响较大! Q:How ??? 2011/12/19

文件流指针FILE与文件描述符fd区别巨大,一个是库,一个是系统调用,对应于用户态及内核态的不同!

POSIX标准文件IO管理,open,close,read,write

 

5. 进程

Q:孤儿进程与僵尸进程? 2011/12/19

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值