Autosave: 2024-04-20 14:30:05
This commit is contained in:
parent
a4a0cfffa8
commit
66c55e149d
2 changed files with 12 additions and 1 deletions
BIN
.zk/notebook.db
BIN
.zk/notebook.db
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
id: 18bl
|
id: 18bl
|
||||||
title: Heap_memory
|
title: Heap_memory
|
||||||
tags: [memory]
|
tags: [memory, C]
|
||||||
created: Saturday, April 20, 2024
|
created: Saturday, April 20, 2024
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -20,4 +20,15 @@ _garbage collection_. In a language like C, this is the explicit concern of the
|
||||||
programmer and is not abstracted away. Failure to properly manage garbage
|
programmer and is not abstracted away. Failure to properly manage garbage
|
||||||
collection is what causes [[Memory_leaks]].
|
collection is what causes [[Memory_leaks]].
|
||||||
|
|
||||||
|
Here is an example of managing heap memory allocation in C:
|
||||||
|
|
||||||
|
```c
|
||||||
|
void * data;
|
||||||
|
data = malloc(512)
|
||||||
|
```
|
||||||
|
|
||||||
|
The first line assigns a special _pointer_ variable (indicated by `void *`
|
||||||
|
rather than `int` or `str`) . This is a variable only holds a memory address.
|
||||||
|
The `malloc` method assigns 512 bytes to the `data` variable.
|
||||||
|
|
||||||
## Related notes
|
## Related notes
|
||||||
|
|
Loading…
Add table
Reference in a new issue