diff --git a/docs/Chapters/01-memory.html b/docs/Chapters/01-memory.html index ae5388b5..93dfb30c 100644 --- a/docs/Chapters/01-memory.html +++ b/docs/Chapters/01-memory.html @@ -485,7 +485,7 @@

Unlike stack memory, heap memory is allocated explicitly by programmers and it won’t be deallocated until it is explicitly freed (Chen and Guo 2022).

-

To store an object in the heap, you, the programmer, needs to explicitly tells Zig to do so, by using an allocator to allocate some space in the heap. In Section 3.3, I will present how you can use allocators to allocate memory in Zig.

+

To store an object in the heap, you, the programmer, needs to explicitly tell Zig to do so, by using an allocator to allocate some space in the heap. In Section 3.3, I will present how you can use allocators to allocate memory in Zig.

@@ -517,7 +517,7 @@

3.2 Stack overflows

Allocating memory on the stack is generally faster than allocating it on the heap. But this better performance comes with many restrictions. We have already discussed many of these restrictions of the stack in Section 3.1.4. But there is one more important limitation that I want to talk about, which is the size of the stack itself.

The stack is limited in size. This size varies from computer to computer, and it depends on a lot of things (the computer architecture, the operating system, etc.). Nevertheless, this size is usually not that big. This is why we normally use the stack to store only temporary and small objects in memory.

-

In essence, if you try to make an allocation on the stack, that is so big that exceeds the stack size limit, a stack overflow happens, and your program just crashes as a result of that. In other words, a stack overflow happens when you attempt to use more space than is available on the stack.

+

In essence, if you try to make an allocation on the stack, that is so big that it exceeds the stack size limit, a stack overflow happens, and your program just crashes as a result of that. In other words, a stack overflow happens when you attempt to use more space than is available on the stack.

This type of problem is very similar to a buffer overflow, i.e., you are trying to use more space than is available in the “buffer object”. However, a stack overflow always causes your program to crash, while a buffer overflow does not always cause your program to crash (although it often does).

You can see an example of a stack overflow in the example below. We are trying to allocate a very big array of u64 values on the stack. You can see below that this program does not run successfully, because it crashed with a “segmentation fault” error message.

@@ -1306,4 +1306,4 @@