- Fixed incorrect init_connections() call in test_etcp_simple_traffic.c (was calling server_instance instead of client_instance) - Fixed double free in timeout_heap_pop() when handling deleted elements - Enhanced NULL pointer safety in uasync_print_resources() by removing complex heap manipulation - Added debug logging to timeout_heap_pop() for better error tracking Test results: test_etcp_simple_traffic now passes without double free errors
28 lines
1.4 KiB
C
28 lines
1.4 KiB
C
// memory_pool.h
|
|
#ifndef MEMORY_POOL_H
|
|
#define MEMORY_POOL_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#define MEMORY_POOL_MAX_FREE 64 // Максимальное количество свободных объектов в пуле (чтобы не накапливать слишком много)
|
|
|
|
struct memory_pool {
|
|
void* free_head; // Голова linked list свободных блоков (next хранится в начале каждого блока)
|
|
int free_count; // Количество свободных блоков
|
|
size_t object_size; // Размер объектов в пуле
|
|
size_t allocations; // Общее количество аллокаций (включая новые malloc)
|
|
size_t reuse_count; // Количество повторных использований из пула
|
|
};
|
|
|
|
// сам пул:
|
|
// если используем с элементами ll_queue то не забываем что к object_size надо прибавить sizeof(struct ll_entry)
|
|
struct memory_pool* memory_pool_init(size_t object_size);
|
|
void memory_pool_destroy(struct memory_pool* pool);
|
|
|
|
// элементы пула:
|
|
void* memory_pool_alloc(struct memory_pool* pool);
|
|
void memory_pool_free(struct memory_pool* pool, void* obj);
|
|
void memory_pool_get_stats(struct memory_pool* pool, size_t* allocations, size_t* reuse_count);
|
|
|
|
#endif // MEMORY_POOL_H
|