You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
873 B
36 lines
873 B
#include "aquery.h"
|
|
|
|
#include <memory>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <unordered_map>
|
|
|
|
Session* session;
|
|
|
|
|
|
void* Aalloc(size_t sz, deallocator_t deallocator){
|
|
void* mem = malloc(sz);
|
|
auto memmap = (std::unordered_map<void*, deallocator_t>*) session->memory_map;
|
|
memmap->operator[](mem) = deallocator;
|
|
return mem;
|
|
}
|
|
|
|
void Afree(void* mem){
|
|
auto memmap = (std::unordered_map<void*, deallocator_t>*) session->memory_map;
|
|
memmap->operator[](mem)(mem);
|
|
memmap->erase(mem);
|
|
}
|
|
|
|
void register_memory(void* ptr, deallocator_t deallocator){
|
|
auto memmap = (std::unordered_map<void*, deallocator_t>*) session->memory_map;
|
|
memmap->operator[](ptr) = deallocator;
|
|
}
|
|
|
|
void default_deallocator(void* ptr){
|
|
free(ptr);
|
|
}
|
|
|
|
__AQEXPORT__(void) init_session(Context* cxt){
|
|
session = &cxt->current;
|
|
}
|