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.
当你调用一个函数,实际上发生的是,函数得到了自己的内存块,相同的类型,是占有一样大小的内存的。
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, again, just as I said verbally a moment ago, if you're going here, you're literally touching, trying to read or change memory that's beyond the boundaries of a chunk of memory that you're supposed to be touching based on its length.
嗯,再次强调,就像我刚才说的,如果你从这里出发,你将依次接触到,试着读取或者改变内存,如果超出了你可以使用的,内存块长度的界限。
And when we return the string to you we're essentially telling you where this chunk of memory is.
当我们返回该字符串时,我们实际上是告诉你,这块存储单元位于哪里。
Well, if that function calls another function, you put another tray on, and so that new tray represents that function's chunk of memory.
好的,如果那个函数调用另一个函数,你再放一个托盘在上面,新的托盘代表,那个函数的内存块。
So the heap is a chunk of memory in a computer's RAM that's conceptually allocated to what's called dynamic memory allocation.
堆是在计算机RAM中的一块内存,它可以进行,动态内存分配。
Well, there's a chunk of memory called the heap that you can grab as much memory as you want so long as it exists for your program.
好的,这里有一块叫做堆的内存,这样你就可以获得你想要那么多的内存,因为它为你的程序而存在。
Well, this will, in fact, be declared, but, unfortunately, you're using a different chunk of memory.
好的,这个被声明了,但是,不幸的是,你在使用一块不同的内存。
Well, if you want to call a function, it's like putting another tray on that stack of trays and that tray represents a chunk of memory that, that function can use.
嗯,如果你想调用一个函数,这就像把一个托盘放到另一个托盘上,托盘代表一块,函数可以使用的内存。
I can certainly try to write the number 13 there, but bam, my program very likely will crash if this chunk of memory was not given to me previously by the operating system and maybe it is owned by the operating system.
我当然可以在那里写下数字13,但是“嘣“,如果这块内存不是系统预先给我的,我的程序很可能会崩溃,可能这块内存,是系统本身使用的。
Yeah, a pointer to this chunk of memory.
是的,一个指向这块内存的指针。
You're incrementing this chunk of memory.
你增加了这一块内存。
So A gets 1, B gets 2, now the swap function itself starts executing line by line; so I declare a chunk of memory called temp.
所以A等于1,B等于2,现在swap函数自己开始,一行一行地执行,所以我声明了,叫做temp的一块内存。
So that means if you-- whether you own a Mac, PC or whatever, you have a whole chunk of RAM memory which you can draw for instance as a rectangle, if you can't quite see.
也就是说,无论你的电脑是Mac也好,PC也好或其他什么的,你会有厚厚一块RAM存储器,我们可以把它画成长方形,你们有可能看不到。
So, now I have x pointing at a chunk of memory what's in this memory though?
那么,现在x指向一块内存,内存中是什么呢?
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,所以现在我交换这些值。
应用推荐