frankencode / ccalloc

A fast mmap based C++ memory allocator
Other
0 stars 1 forks source link

Allocate a class instance #1

Open bolunli11 opened 4 years ago

bolunli11 commented 4 years ago

Hello,

I'm wondering that how to use ccalloc to allocate memory space for C++ class instance? Thanks.

frankencode commented 4 years ago

I've created an improved version of ccalloc called "kissmalloc". You'll find the code here: https://gitlab.com/frankencode/kissmalloc . Check out the section in the README: "How to use in C++".

bolunli11 commented 4 years ago

Thanks! Because I want to allocate memory in signal handler, and malloc/free are unsafe functions, so is the mmap way provided by kissmalloc safe in signal handler?

frankencode commented 4 years ago

That is an odd use-case. I never even considered signal-safety. kissmalloc is designed for modern multi-threaded applications. In those you usually block the signal mask of all threads and run in one dedicated thread sigwait(2). The good old signal(2) syscall is pretty much depreciated.