RAM is this memory recall or, as you'll soon find in problems Set One, that's used for ephemeral purposes.
内存是随机存储器,你们将,在习题集1中发现,它们用来短暂存储的目的。
I've got some internal variables I have to store, what kinds of things do I have to keep track of?
计算的时候需要占用多少内存,我需要存储一些内部变量,我需要记录哪些东西呢?
Well, because the memory we've been using for local variables, and for functions, storage space is what computer scientists generally call the stack.
好的,因为我们看到的内存是用于局部变量的,用于函数的,存储空间就是计算机科学家,通常说的堆。
And by that, I mean, not how much memory do I need to store the size of the input, it's really how much internal memory do I use up as I go through the computation?
需要占用多少内存,我意思并不是,存储输入需要多少内存,而是当我完成这个?
Here I actually need to tell the computer, "Give me some bytes in ram in which to store a value, and that value's going to be a floating point value."
这里我的确需要告诉计算机,“给我一些字节内存,来存储一个值,那个值将是,浮点型的数值“
It's just a little block of memory in RAM, you know, that represents four bytes, 32-bits and the Number Two is currently in it.
它只是一小块内存块,它表示4个字节,32位,那个数字2就存储在里面。
I want an actual copy in memory so that that string is in two different places.
我想要在内存中有一个拷贝,把字符串存储在,两个不同的地方。
ArgV You can think of this variable Arg V as literally an array a sequence of chunks of memory that literally are back to back to back in memory, and when you say bracket zero, by convention, you are referring to the variables stored here.
你可以想象这个变量,按顺序排列的一块块内存,依次地在内存中紧邻着的,当你指明,按照惯例,涉及,存储的变量在这里。
D-A-V-I-D Well, if I've got a five-letter word like D-A-V-I-D, well, that's like five bytes and yet we only have the ability thus far in this class to return one thing at a time I can't return five bytes to you, but wait a minute, those bytes by nature of a computer are just stored in RAM.
好的,如果有5个字母的单词,如,那是5个字节,我们只能返回一个东西,而不能返回5个字节,等一下,这些字节被计算机本能地,存储在内存中。
Now if you call a function, swap like increment or cube or swap, or in this case, foo, those variables are the parameters to that function, end up getting stored next in memory.
现在如果你调用一个函数,像increment或者cube或者,或者在这个例子里,foo,这些变量都是,函数的参数,在内存中存储。
They might very well be storing the addresses of memory elsewhere, but we just needed them as sort of a cheat sheet, a little address card to know where the original values x and y were.
它们存储在内存的其他地方是可以的,但是我们需要一个备忘单,一个地址卡,来知道,原始的值x和y是什么。
Almost everyone in this room has probably had a segfault at some point or core dump where you end up with this random file called core, which recall is just the contents of memory at the time your program crashed.
几乎这个教室里的所有人,在某个时候,都遇到过段错误,或者通过这个core文件的,存储器内核更新,这就是你的内存出现错误,你的程序崩溃掉了。
So before long, we'll see, especially for problems that we can't allocate an int every time we want to store something, because what if we want to store 140,000 English words.
所以不久后,我们将看到,特别是对于,我们不能为int分配内存,每次我们想要,存储一些东西时,因为当我们想要,存储140,000个英语单词时。
I'm going to delete that arrow and actually draw s2 as pointing to this chunk of memory because whereas before this sequence of chars might have lived at address 71 or whatever, well, this one might live at 91.
我不会把那个箭头删除,实际上我画了s2作为,这块内存的指针,因为,这个字符序列存储在地址71或其它的地方,这个可能存储在91的地方。
It's reasonable because it's meant TMP for temporary purposes just to call it temp or T-M-P for short, X and I can define temp as -- why don't I set it as equal to X, initially, because now that I've stored X in a separate chunk of memory, I can now change its value and then I can say Y gets, not X, but temp, and so now I've actually swapped these values.
这是合理的,因为它是为,暂时的目的,只要叫它Temp或简称它为,我可以定义temp为--为什么我不把它设定为等于,最初的,因为现在我把X存储在一个单独的内存块中,我现在可以改变它的值,然后我说Y等于,不是X,而是temp,所以现在我交换这些值。
应用推荐