Well, it turns out on most computers an address of the location and memory, aka a pointer, is itself 32 bits.
好的,它是一个计算机内存地址,或者说一个指针,占32位。
We're kind of restricting ourselves to only certain chunks of memory, at least for now, but it certainly creating problems.
我们现在我们自己只能在某一块内存中,至少是现在,当然这样也会产生问题。
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?
需要占用多少内存,我意思并不是,存储输入需要多少内存,而是当我完成这个?
You double click an icon, the program gets loaded into memory, well, conceptually where does your program end up?
双击一个图标,程序就被加载到内存中,那么,程序在哪里结束?
RAM is this memory recall or, as you'll soon find in problems Set One, that's used for ephemeral purposes.
内存是随机存储器,你们将,在习题集1中发现,它们用来短暂存储的目的。
So, you know, we've got a bunch of juicy topics to dive into this week involving pointers and memory.
这周我们有很多有趣的主题,包括指针和内存。
One of the perhaps easiest ones to put your finger on is what if the computer is out of memory?
一个可能的情况是,计算机的内存不足?
So both of these stories involve floating point values, but only in this case am I actually allocating memory.
所以这两个故事都涉及到浮点类型,但是只有那样我们才能真正地分配到内存。
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.
当你调用一个函数,实际上发生的是,函数得到了自己的内存块,相同的类型,是占有一样大小的内存的。
But we know already from week zero that computers ultimately represent all information with numbers, and if they want to represent letters inside memory, well what do they do or what do they use?
但是自从上周我们已经知道,计算机最终是用数字来表示所有的,信息,如果它们要描绘,在内存中的字母,它们该怎么做,用什么方式呢?
Now, if I've asked the user for a string and then a moment later I ask the user for another string, well, they're going to end up in different locations in memory just by nature of get string.
现在,如果我要用户输入一个字符串,一会儿之后我要用户输入另一个字符串,他们最终是在,不同的内存地址中。
Its name is malloc for memory allocation and what malloc does for us is we say, hmm, the user has typed in a three-letter word.
它为我们分配内存地址,它为用户输入的3个字母单词,分配地址。
You actually need to kind of do this and then you can swap these two numbers but it requires 50 percent more memory.
你实际上需要这样做,然后才能交换两个数字,但是它需要多50%的内存。
Two pieces of memory actually touching each other or you touching memory that you don't actually own, in which case the computer doesn't really know what to do and just, bam.
两块内存相互覆盖,或者你覆盖了不存在的内存,那样的话计算机不知道,该怎么做,只有崩溃。
Is is saying, do these things point to exactly the same spot in memory, the same instance.
指向内存中的同一位置,同一个实例,深意义上的相等。
So now that we begin to have this ability to express strings in memory, to understand what they are, we can start to apply actually real-world algorithms to them.
现在我们开始用这个技能来在内存中表达字符串,来理解它们是什么,我们可以开始,我们可以对其使用实际的,现实生活中的算法。
It turns out that slightly before the stack, slightly before this conceptual chunk of memory, there's other things called environment variables that we may see over time but elsewhere in memory are other things.
结果是稍微在堆之前,稍微在这个内存块概念之前,另外还一个东西叫做环境变量,我们之后可能看到,内存中的其他地方,是其他的东西。
Well, because the memory we've been using for local variables, and for functions, storage space is what computer scientists generally call the stack.
好的,因为我们看到的内存是用于局部变量的,用于函数的,存储空间就是计算机科学家,通常说的堆。
Not by some very arcane numeric address inside my computer's memory, but by a symbol, by a name.
不是通过一些在我电脑内存中的神秘的数字地址,而是通过一个符号,一个名字。
foo You probably weren't calling foo ad nauseam here but segmentation fault refers to segments of memory colliding.
你可能不会倒胃口地调用,但是段错误是涉及内存段冲突。
That is the address in memory in the heap of the first byte that the user typed in.
那是用户输入的字符串第一个字节,内存中堆的地址。
Well, if you forget where the memory is that you asked for, well, in fact, that is how you make a memory leak.
嗯,如果你忘了你申请的内存在哪里,呃,实际上,这就是造成内存泄露的原因。
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就存储在里面。
Somewhere in memory, back to back to back or all of the strings and with them can we store actual words and phrases.
在内存某处,紧邻的或者所有的字符串,我们用它们可以存储实际的单词,和短语。
2 3 Down here we said this is like 4, 5, 6 and 1, 2, 3 so this is going to be memory location 7, 7, 7, 7, 1 whatever.
在这下面,这是,4,5,6,和,这将是内存地址,7,7,7,7,1,不管是什么。
Which may take up some arbitrary amount of memory. In that case, I'm back to this problem.
然后将接下来的每一个内存块设置为,指向数组对应元素值的指针。
Well, if that function calls another function, you put another tray on, and so that new tray represents that function's chunk of memory.
好的,如果那个函数调用另一个函数,你再放一个托盘在上面,新的托盘代表,那个函数的内存块。
You can touch almost any part of memory in the computer systems that you want with your program, but do you want to?
通过你的程序,你可以触及到计算机系统,内存的任意部分,但是那是你想要的吗?
So even though we're not literally throwing RAM away, we're not physically moving anything, conceptually, we have to go through memory in this order back to back to back and then undo it.
即使我们没有把内存依次扔掉,我们物理上没有移动任何东西,概念地,我们必须按照顺序经过内存,回到这里然后撤销它。
Or another way of thinking about it, is remember I said when I call that class definition it creates an instance, that's a pointer to some spot in memory that's got some local information around it.
也就是一个指向,内存中某处的指针,这个地方存有一些,这个实例的信息,浅意义的相等也就是说,看看这两个东西是不是。
应用推荐