Skip to content

Commit

Permalink
Merge pull request #1193 from Arnaud-de-Grandmaison-ARM/memory-allocator
Browse files Browse the repository at this point in the history
[LP] dynamic memory allocator: misc small fixes or rewording.
  • Loading branch information
jasonrandrews authored Aug 28, 2024
2 parents a293e7f + e451cf2 commit 6a96e7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ The C library looks for a chunk of memory with a size of at least X bytes within
parameter passed to `malloc`. For instance, on Ubuntu Linux, this is done by GLIBC.

The example at the top of the page is trivial, of course. As it is we could just
statically allocate both integers like this:
initialize both `a` and `b` at compilation time like this:

```C
void fn() {
int a, b = 0;
int a = 0;
int *b = NULL;
}
```

Variables `a` and `b` work fine if they are not needed outside of the function. In other
This works fine as `a` and `b` are not needed outside of the function or in other
words, if the lifetime of the data is equal to that of the function.

A more complex example (shown below) demonstrates when this is not the case, and the values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To begin, decide which functions your memory allocator will provide. We
have already described `malloc` and `free` but there are more provided by the
[C library](https://en.cppreference.com/w/c/memory).

This demo assumes you just need `malloc` and `free`. The new implementations will
This learning path assumes you just need `malloc` and `free`. The new implementations will
be called `simple_malloc` and `simple_free`. Start with just these two functions and write
out their behaviors.

Expand Down Expand Up @@ -96,7 +96,7 @@ range = 0x0 + 4 = 0x4;
Pointer: 0x4 Size: N-4 Allocated: False
range = 0x4 + (N-4) = 1 beyond the end of the heap, so the walk is finished.
range = 0x4 + (N-4) = N beyond the end of the heap, so the walk is finished.
```

`simple_free` uses the pointer given to it to find the range it needs to de-allocate.
Expand Down

0 comments on commit 6a96e7d

Please sign in to comment.