-
在使用
C
语言编写程序时,往往会有动态分配内存的需求,比如动态分配数组。动态申请的内存必须是一块连续的地址空间,在不再需要这块内存时,又会对内存进行释放操作。当进行多次申请、释放之后,地址空间中会出现许多大大小小的空闲块,这些空闲块可能无法满足新的内存申请,这样就导致空闲块“被浪费了”,从而降低了内存的使用率。
设计较差的分配器不仅仅会造成内存使用率较低的问题,也很有可能花费更多的时间来搜索空闲块,造成系统吞吐率变低。
总结而言,分配器的目的有以下两个:
- 最大化内存利用率。
- 最大化吞吐量。
-
CSAPP Attack Lab V.2016.01.11
$ ./hex2raw < input/phase_5.txt | ./rtarget -q Cookie: 0x59b997fa Type string:Touch3!: You called touch3("59b997fa") Valid solution for level 3 with target rtarget PASS: Would have posted the following: user id bovik course 15213-f15 lab attacklab result 1:PASS:0xffffffff:rtarget:3:88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 06 1A 40 00 00 00 00 00 C5 19 40 00 00 00 00 00 AB 19 40 00 00 00 00 00 48 00 00 00 00 00 00 00 DD 19 40 00 00 00 00 00 34 1A 40 00 00 00 00 00 27 1A 40 00 00 00 00 00 D6 19 40 00 00 00 00 00 C5 19 40 00 00 00 00 00 FA 18 40 00 00 00 00 00 35 39 62 39 39 37 66 61
-
CSAPP Bomb Lab V.2016.01.12
$ ./bomb inputs.txt Welcome to my fiendish little bomb. You have 6 phases with which to blow yourself up. Have a nice day! Phase 1 defused. How about the next one? That's number 2. Keep going! Halfway there! So you got that one. Try this one. Good work! On to the next... Curses, you've found the secret phase! But finding it and solving it are quite different... Wow! You've defused the secret stage! Congratulations! You've defused the bomb!
-
怎么用
FoldRight
实现FoldLeft
呢?两个函数的签名如下def foldLeft[A,B]: (List[A], B) => ((B, A) => B) => B def foldRight[A,B]: (List[A], B) => ((A, B) => B) => B
-
CSAPP Data Lab V.2016.05.04。
$ ./btest Score Rating Errors Function 1 1 0 bitAnd 2 2 0 getByte 3 3 0 logicalShift 4 4 0 bitCount 4 4 0 bang 1 1 0 tmin 2 2 0 fitsBits 2 2 0 divpwr2 2 2 0 negate 3 3 0 isPositive 3 3 0 isLessOrEqual 4 4 0 ilog2 2 2 0 float_neg 4 4 0 float_i2f 4 4 0 float_twice Total points: 41/41
-
斐波拉契数列,即形如
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...
,通项公式为An = An-1 + An-2
的数列。那么怎么用递归的方式求出指定位置的斐波拉契数呢?