Работа с интерфейсом аллокатора
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file tempFXAlloc.h
|
||||
* @author felex67 (admin@felexdev.ru)
|
||||
* @brief FXAlloc - fast pooled allocator-profiler
|
||||
* @version 0.0.1 dev
|
||||
* @date 2026-05-06
|
||||
*
|
||||
* License: Apache 2.0
|
||||
* */
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
// Windows
|
||||
#include <windows.h>
|
||||
#define thread_local __declspec(thread)
|
||||
typedef HANDLE fxsync_t;
|
||||
#else
|
||||
// Linux
|
||||
#include <pthread.h>
|
||||
#define thread_local __thread
|
||||
typedef pthread_mutex_t fxsync_t;
|
||||
#endif //_WIN32
|
||||
|
||||
#pragma pack(push, 8)
|
||||
/**
|
||||
* @brief Memory block meta-data
|
||||
* size: 24 bytes
|
||||
*/
|
||||
typedef struct FXMemoryBlock {
|
||||
FXMemoryBlock* next; ///< Next block in lifo
|
||||
FXMemoryBlock* list; ///< Next block total
|
||||
uint32_t thread_idx; ///< Thread index
|
||||
uint32_t grade_idx; ///< Grade index
|
||||
} FXMemoryBlock;
|
||||
#pragma pack(push, 8)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Grade pool
|
||||
*
|
||||
*/
|
||||
typedef struct FXGradePool {
|
||||
FXMemoryBlock* prealloced;
|
||||
FXMemoryBlock* lifo;
|
||||
FXMemoryBlock* list_first;
|
||||
FXMemoryBlock* list_last;
|
||||
uint32_t ntotal;
|
||||
uint32_t nbusy;
|
||||
uint32_t nalloc;
|
||||
uint32_t nprealloc;
|
||||
} FXGradePool;
|
||||
|
||||
#pragma pack(push, 8)
|
||||
/**
|
||||
* @brief Thread memory pool
|
||||
*
|
||||
*/
|
||||
typedef struct FXThreadPool {
|
||||
uint32_t isActive;
|
||||
uint32_t ngrades;
|
||||
FXGradePool grades[];
|
||||
} FXThreadPool;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct FXGlobalMemoryPool {
|
||||
FXThreadPool** pools;
|
||||
fxsync_t mutex;
|
||||
} FXGlobalMemoryPool;
|
||||
Reference in New Issue
Block a user