Skip to content

Commit

Permalink
NORM(markdown syntax)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilies1511 committed Oct 18, 2024
1 parent c8ba51e commit 1970d3f
Showing 1 changed file with 56 additions and 35 deletions.
91 changes: 56 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Garbage Collector - README

## Overview
Expand All @@ -19,7 +20,7 @@ This project provides a simple garbage collection system in C using a linked lis
## Files
- **gb_garbage_collector.c**: Implements the core garbage collection system, including adding memory blocks to the collection list, creating nodes, and freeing all memory.
- **gb_utils.c**: Provides utility functions for memory allocation, linked list operations, and printing the state of the garbage collector.
- **main_cleanup()**: A cleanup function that frees all memory, resets the garbage collector, and terminates the program.
- **main_cleanup**: A cleanup function that frees all memory, resets the garbage collector, and terminates the program.

## Usage

Expand All @@ -30,36 +31,46 @@ This project provides a simple garbage collection system in C using a linked lis

```c
t_garbage_collector *gc_init_garbage_collector(void);
```
2. **Allocate Memory with Garbage Collector**
Allocates memory and registers the allocated block with the garbage collector, so it can be freed later.
2. Allocate Memory with Garbage Collector
Allocates memory and registers the allocated block with the garbage collector, so it can be freed later.
```c
void *ft_malloc(size_t len);
```

```c
void *ft_malloc(size_t len);
Example:
Example:
```c
int *arr = (int *)ft_malloc(sizeof(int) * 10); // Allocates memory for 10 integers
```

```c
int *arr = (int *)ft_malloc(sizeof(int) * 10); // Allocates memory for 10 integers
3. Free All Allocated Memory
Frees all memory blocks tracked by the garbage collector and clears the linked list.
3. **Free All Allocated Memory**
Frees all memory blocks tracked by the garbage collector and clears the linked list.

```c
void gc_free_all(void);
Example:
```c
void gc_free_all(void);
```
```c
gc_free_all(); // Frees all allocated memory
4. Program Cleanup and Exit
The main_cleanup() function handles freeing all memory, clearing the garbage collector, and exiting the program.
Example:
```c
gc_free_all(); // Frees all allocated memory
```

```c
noreturn void main_cleanup(void);
Example:
4. **Program Cleanup and Exit**
The `main_cleanup()` function handles freeing all memory, clearing the garbage collector, and exiting the program.

```c
noreturn void main_cleanup(void);
```
Example:
```c
main_cleanup(); // Cleans up and exits the program
```

### Example Program

```c
main_cleanup(); // Cleans up and exits the program
Example Program
```c
#include "garbage_collector.h"
#include <stdio.h>
Expand All @@ -83,30 +94,40 @@ int main(void)

return 0;
}
Linked List Debugging
```
### Linked List Debugging
You can print the size of the garbage collector's linked list at any time to inspect how many memory blocks are being tracked:
```c
gc_print_linked_list(get_gc());
Cleanup Function
The main_cleanup() function does the following:
```

### Cleanup Function
The `main_cleanup()` function does the following:

- Calls `gc_free_all()` to free all allocated memory.
- Clears the garbage collector's internal state with `ft_bzero()`.
- Terminates the program with `exit()`.

Calls gc_free_all() to free all allocated memory.
Clears the garbage collector's internal state with ft_bzero().
Terminates the program with exit().
```c
noreturn void main_cleanup(void) {
gc_free_all();
ft_bzero(get_gc(), sizeof(t_garbage_collector));
exit(exit_stat); // Exits the program with the appropriate exit status
}
Compilation
To compile your program, include the necessary headers (garbage_collector.h, main.h, libft.h) and link the required libraries:
```
## Compilation
To compile your program, include the necessary headers (`garbage_collector.h`, `main.h`, `libft.h`) and link the required libraries:
```bash
cc -Wall -Werror -Wextra -g my_program gb_garbage_collector.c gb_utils.c
Future Work
Implement gc_overwrite(): A function to safely overwrite memory while being tracked by the garbage collector.
Extend error handling for memory operations.
License
```

## Future Work
- Implement `gc_overwrite()`: A function to safely overwrite memory while being tracked by the garbage collector.
- Extend error handling for memory operations.

## License
This project is open-source. You are free to use, modify, and distribute it under the relevant open-source license.

0 comments on commit 1970d3f

Please sign in to comment.