So we see that I've doubled the size of the vector but I've much more than doubled the number of calls.
所以我们看到我,把向量的大小翻倍了,但是我调用的次数,不仅仅是翻倍了。
So if I call, let's , let's set up s to be, I don't know, some big long list.
那让我们来调用一次吧,让我们建立一个,怎么说。
When you call a function, what actually happens is that function gets its own chunk of memory that's identical in size to the data type that it expects.
当你调用一个函数,实际上发生的是,函数得到了自己的内存块,相同的类型,是占有一样大小的内存的。
You have one rule invoking another rule and then you can get a sentence like "Fred thinks Barney likes Wilma."
遵循调用前一个规则的这个规则,这样你就得到了,像"弗雷德觉得巴尼喜欢威尔玛",这样的句子
max val I'm not going to call the other max val here, because we know what happens when I do that.
我不打算调用其他,因为我们知道当,我这么做会发生什么。
And the main one is, I get to just decide, how do I want to use this, and call it.
但是这真的会有一些好处,最重要的一点是,我需要决定,我要如何来使用这个方法,以及如何来调用它。
When I call this class definition, it calls init, init and I give it an x and a y value.
我说过,当我们,调用这个类的定义的时候,它会去调用。
s1 It's a little square, it's going to be called s1 and that's what exists as of line two of this program, GetSting but now I've called get string.
这是一个正方形,叫做1,这就是程序中第二行代码所表示的,现在我调用。
Pardon? 17 million. Computers are fast, fortunately. Well, that's a lot of calls.
幸运的是电脑很快,好了,调用次数真是多。
It implies that this algorithm is calling itself again and again, and again, and on each time the size of the problem I'm trying to sort is being divided by what?
这就说明此算法会一次又一次地调用自己,每次我要排序的问题规模大小,会除以多少呢?
- Well, just a moment ago, we did have -- -- and this time I'll use some chalk here -- a moment ago, we did have a picture depicting what was going on when you call the function.
好的,刚才,我们确实有-,这一次我将用一些粉笔-,刚才,我们有一张图描绘了当我们调用函数的时候,会发生什么事情。
Code is right here. And all it's doing is when I'm getting into the different places I'm simply printing out information about where I am. What I want you to see palindrome is notice what happened here.
代码就在这儿,它的作用是当我运行到不同地方时,就输出我所在方位的信息,我想让你们看的就是注意这儿发生了什么,好了我调用了一个。
And one of the ways you can make a program crash, intentionally or not, is to essentially use up too much memory or call too many functions and what happens is, bam, one hits the other and bad things happen.
其中一个方式能使你的程序崩溃掉,有意或无意的,它本质上使用了太多的内存,或者调用了太多的函数,所发生的,崩掉,一个冲突了另一个,然后发生了坏事情。
If I haven't solved the problem, let me solve it, and store the answer away for later reference.
让我解决它,然后保留答案以备下次调用。
Actually it's not 40, I think these are, 75 alright. So the answer is 75 and the number of calls is 1.7 million.
实际上不是4,我觉得,好了,所以答案是5,调用次数是1百70万次。
foo You probably weren't calling foo ad nauseam here but segmentation fault refers to segments of memory colliding.
你可能不会倒胃口地调用,但是段错误是涉及内存段冲突。
The even better news is that Fib instead of 25 calls, it was only 11 calls.
更好的消息是,上次调用了25次,这次只调用了11次。
a I'm not, so come down here check palindrome that the two end points a and a are the same and call this again also.
判断两端都是,然后再次调用,注意发生了什么。
And I would be able to simply bury away the details of how those other instances are created from how I want to use them by simply calling methods on the classes.
也就是一些线段的组合,我还可以把怎么实现那些,实例的细节包装起来,把它和调用实例分开来,我们下次还会接着讲这个。
And that then let's me get to, basically, base this code. Having done that, height I simply call base with get float, I call height with get float, and do the rest of the work.
现在让我们看看这段代码,其实已经写好了,我简单的调用下,用来得到一个浮点数,再调用下,来得到另外一个浮点数,然后做剩下的工作就可以了。
I'm much better having an exception get handled at the time of input than to let that prop -- that value rather propagate through a whole bunch of code until eventually it hits an error 17 calls later, and you have no clue where it came from.
不是我期望的格式,这时我最好有一个异常处理,而不是让其传下去,这个值传到代码的整个分支,最终会导致一个错误17调用的发生,并且你不知道这个错误是哪里来的。
Python So I'm using the Python try except to check whether or not the thing is in the memo or not.
所以我将让,去调用except去判断该物品,是否已经在memo中。
You're calling functions, functions, functions, but you're allocating heap, heap, heap, heap memory for your words.
我们一直调用函数,函数,函数,你一直为单词分配堆,堆,堆,堆。
Right now it's empty, actually it's not quite empty, it has a pointer back to the class.
当我调用了这个类的,定义声明的时候,它在内存中的特定点。
Every time I use it, I'm creating a new instance, that's a different thing inside of memory.
我每次调用它,我就新建了一个类,这在内存中是个不同的事情。
That's a good thing. And instead of 17 million calls, I have 1800 calls.
真好,我们只调用了1800次函数,而不是一开始的1百70万次。
8 Here, it gets a maximum value of 48 and 85 calls.
这里它的最大值是8,函数调用了85次。
9 it is. And it made a total of 13 calls.
是29,一共调用了13次。
Step 5, now this is an example of what we'll henceforth call a condition or a branch because it's sort of a fork in the road.
步骤五,这是一个关于我们调用一个条件,或者分支语句的例子,因为这是一个岔路口。
So I don't want them to have to call something with two arguments.
所以我不希望它们,调用什么两个自变量。
应用推荐