Emil Askarov P3210
6 unresolved threads
src
CMakeLists.txt +1 -1
main.c +105 -0
mem.c +112 -18
+ 1
- 1
+ 105
- 0
\ No newline at end of file
+ 112
- 18
53 | 66 | |
54 | /* освободить всю память, выделенную под кучу */ | |
55 | void heap_term( ) { | |
56 | /* ??? */ | |
57 | } | |
58 | ||
59 | 67 | #define BLOCK_MIN_CAPACITY 24 |
60 | 68 | |
61 | 69 | /* --- Разделение блоков (если найденный свободный блок слишком большой )--- */ |
62 | 70 | |
63 | 71 | static bool block_splittable( struct block_header* restrict block, size_t query) { |
64 | return block-> is_free && query + offsetof( struct block_header, contents ) + BLOCK_MIN_CAPACITY <= block->capacity.bytes; | |
72 | return block->is_free && query + offsetof( struct block_header, contents ) + BLOCK_MIN_CAPACITY <= block->capacity.bytes; | |
65 | 73 | } |
66 | 74 | |
67 | 75 | static bool split_if_too_big( struct block_header* block, size_t query ) { |
Please register or sign in to reply |
54 | /* освободить всю память, выделенную под кучу */ | |
55 | void heap_term( ) { | |
56 | /* ??? */ | |
57 | } | |
58 | ||
59 | 67 | #define BLOCK_MIN_CAPACITY 24 |
60 | 68 | |
61 | 69 | /* --- Разделение блоков (если найденный свободный блок слишком большой )--- */ |
62 | 70 | |
63 | 71 | static bool block_splittable( struct block_header* restrict block, size_t query) { |
64 | return block-> is_free && query + offsetof( struct block_header, contents ) + BLOCK_MIN_CAPACITY <= block->capacity.bytes; | |
72 | return block->is_free && query + offsetof( struct block_header, contents ) + BLOCK_MIN_CAPACITY <= block->capacity.bytes; | |
65 | 73 | } |
66 | 74 | |
67 | 75 | static bool split_if_too_big( struct block_header* block, size_t query ) { |
68 | /* ??? */ | |
|
41 | } | |
42 | ||
43 | void test_allocated_two_blocks_then_released() { | |
44 | void *b1 = _malloc(BASE_ALLOC_SIZE); | |
45 | void *b2 = _malloc(BASE_ALLOC_SIZE*2); | |
46 | void *b3 = _malloc(BASE_ALLOC_SIZE*3); | |
47 | assert(b1 != NULL); | |
48 | assert(b2 != NULL); | |
49 | assert(b3 != NULL); | |
50 | ||
51 | _free(b1); | |
52 | _free(b2); | |
53 | ||
54 | assert(b2 != NULL); | |
55 | ||
56 | _free(b2); | |
|
39 | _free(b1); | |
40 | heap_term(); | |
41 | } | |
42 | ||
43 | void test_allocated_two_blocks_then_released() { | |
44 | void *b1 = _malloc(BASE_ALLOC_SIZE); | |
45 | void *b2 = _malloc(BASE_ALLOC_SIZE*2); | |
46 | void *b3 = _malloc(BASE_ALLOC_SIZE*3); | |
47 | assert(b1 != NULL); | |
48 | assert(b2 != NULL); | |
49 | assert(b3 != NULL); | |
50 | ||
51 | _free(b1); | |
52 | _free(b2); | |
53 | ||
54 | assert(b2 != NULL); | |
|
54 | assert(b2 != NULL); | |
55 | ||
56 | _free(b2); | |
57 | heap_term(); | |
58 | } | |
59 | ||
60 | void test_grow_heap_extended(void *heap) { | |
61 | size_t initial_region_size = ((struct region *) heap)->size; | |
62 | ||
63 | void *block = _malloc(5 * TEST_HEAP_SIZE); | |
64 | struct block_header *new_block_header = get_header(block); | |
65 | size_t expanded_region_size = ((struct region *) heap)->size; | |
66 | ||
67 | assert(initial_region_size < expanded_region_size); | |
68 | assert(new_block_header); | |
69 | assert(new_block_header->capacity.bytes >= 5 * TEST_HEAP_SIZE); | |
|
@368988 исправил замечания, проверьте, пожалуйста
Замечания учтены, все исправлено.
Принято
closed
Preferences
Files with large changes are collapsed by default.
Files with large changes are collapsed by default.
Files with large changes are collapsed by default.
было бы хорошо проверять block == NULL
исправил
нужно, чтобы сплитилось на максимальное из query и BLOCK_MIN_CAPACITY
в эту функцию уже передается конечно максимум из query и BLOCK_MIN_CAPACITY, но в целом соглашусь
исправил