# malloc **Repository Path**: lin_wei_hung/malloc ## Basic Information - **Project Name**: malloc - **Description**: Implement malloc() - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-09-19 - **Last Updated**: 2023-02-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # malloc ## 介绍 Implement malloc(). ### Dummy Malloc Simply ssign the requested memory. ### First Fit Divide memory into chunks list. Traverse the chunks list and stop when we find a free block with enough space. **void *** `ff_calloc` define variable `new`'s type as `size_t *`, instead of `void *`. Because `void*` cannot be changed. The real reason is that, `void *` can be transformed into many other types. And their lengths vary (char: 4 bytes, int: 8 bytes, ...). Compiler would not be sure about how many digits to move when `void *a; a++` is called. ### Free & Copy - Use double linked list to fuse neighboring blocks - Copy from source block to destination block 整个项目中有几个地方我不是很明白: - `struct s_block` 中用 `char data[1]` 来保证 byte precision, 我没有理解这里 byte precision 的意思 #### 软件架构 ```bash dummy_malloc/: |---dummy_malloc.c first_fit/: ```