1#define DUCKDB_EXTENSION_MAIN
2#include "jemalloc-extension.hpp"
3
4#include "duckdb/common/allocator.hpp"
5#include "jemalloc/jemalloc.h"
6
7namespace duckdb {
8
9void JEMallocExtension::Load(DuckDB &db) {
10 // NOP: This extension can only be loaded statically
11}
12
13std::string JEMallocExtension::Name() {
14 return "jemalloc";
15}
16
17data_ptr_t JEMallocExtension::Allocate(PrivateAllocatorData *private_data, idx_t size) {
18 return data_ptr_cast(src: duckdb_jemalloc::je_malloc(size));
19}
20
21void JEMallocExtension::Free(PrivateAllocatorData *private_data, data_ptr_t pointer, idx_t size) {
22 duckdb_jemalloc::je_free(ptr: pointer);
23}
24
25data_ptr_t JEMallocExtension::Reallocate(PrivateAllocatorData *private_data, data_ptr_t pointer, idx_t old_size,
26 idx_t size) {
27 return data_ptr_cast(src: duckdb_jemalloc::je_realloc(ptr: pointer, size));
28}
29
30} // namespace duckdb
31
32extern "C" {
33
34DUCKDB_EXTENSION_API void jemalloc_init(duckdb::DatabaseInstance &db) {
35 duckdb::DuckDB db_wrapper(db);
36 db_wrapper.LoadExtension<duckdb::JEMallocExtension>();
37}
38
39DUCKDB_EXTENSION_API const char *jemalloc_version() {
40 return duckdb::DuckDB::LibraryVersion();
41}
42}
43
44#ifndef DUCKDB_EXTENSION_MAIN
45#error DUCKDB_EXTENSION_MAIN not defined
46#endif
47