first commit
This commit is contained in:
commit
26f583ec5e
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
_build
|
3
dune-project
Normal file
3
dune-project
Normal file
@ -0,0 +1,3 @@
|
||||
(lang dune 3.0)
|
||||
|
||||
(using mdx 0.2)
|
55
src/README.md
Normal file
55
src/README.md
Normal file
@ -0,0 +1,55 @@
|
||||
# Garbage
|
||||
|
||||
## Allocation mémoire
|
||||
|
||||
### Allocation statique
|
||||
|
||||
On peut allouer de la mémoire statiquement à deux endroits :
|
||||
|
||||
- dans le segment `.data` lors d'une initialisation explicite,
|
||||
- dans le segment `.bss` lors d'une initialisation par zéro.
|
||||
|
||||
<!-- $MDX file=memory_layout.c -->
|
||||
```c
|
||||
// memory_layout.c
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const int x = 3;
|
||||
|
||||
int y = 5;
|
||||
|
||||
static int i;
|
||||
|
||||
char *my_str = "this should appear in .data";
|
||||
|
||||
int main(void) {
|
||||
|
||||
printf("x = %d\n", x);
|
||||
|
||||
printf("y = %d\n", y);
|
||||
y = 10;
|
||||
printf("y = %d\n", y);
|
||||
|
||||
printf("i = %d\n", i);
|
||||
i = 42;
|
||||
printf("i = %d\n", i);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
```
|
||||
|
||||
```sh
|
||||
$ gcc memory_layout.c -o memory_layout.exe
|
||||
$ size ./memory_layout.exe
|
||||
text data bss dec hex filename
|
||||
1790 608 8 2406 966 ./memory_layout.exe
|
||||
```
|
||||
|
||||
### MDX test
|
||||
|
||||
```ocaml
|
||||
# 1 + 2;;
|
||||
- : int = 3
|
||||
```
|
27
src/memory_layout.c
Normal file
27
src/memory_layout.c
Normal file
@ -0,0 +1,27 @@
|
||||
// memory_layout.c
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const int x = 3;
|
||||
|
||||
int y = 5;
|
||||
|
||||
static int i;
|
||||
|
||||
char *my_str = "this should appear in .data";
|
||||
|
||||
int main(void) {
|
||||
|
||||
printf("x = %d\n", x);
|
||||
|
||||
printf("y = %d\n", y);
|
||||
y = 10;
|
||||
printf("y = %d\n", y);
|
||||
|
||||
printf("i = %d\n", i);
|
||||
i = 42;
|
||||
printf("i = %d\n", i);
|
||||
|
||||
exit(0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user