#Custom allocator for C++ code?
1 messages · Page 1 of 1 (latest)
Nevermind, I thought about how it's linked in my case and it doesn't seem like i could do that...
you would have to override new/delete in C++ to call Zig functions through the C abi
although in all the major impls of the c++ standard library I'm aware of they just call malloc/free
however it could be useful to get the alignment from C++ and pass that to the Zig allocator
Yeah, that's what I thought
sadly the library i use is precompiled so I'd need to recompile it with my change for that to be possible
you can just link to an overridden new
that's kind of the point of being able to override new in C++
In C terms, new is just a weirdly named function symbol that is provided by the c++ standard library by default but can be overridden with a stronger definition
It's confusing to think about in my case because i use a lib that is a C bindings to a C++ library
and this library is provided in the form of a dll and a static lib, for use in C, so that you don't have to link libCPP...
i wonder if that would be possible in that case...
I guess it's not really possible for you to answer that, at this point im just thinking out loud lol
all you are doing is adding another static lib to the link command containing the functions
but thats interesting, thanks for the info !
yeah but could it be that the new implementation is in the DLL already?
that would be an unimaginely insane and unusable library
because that dll would override every other dll in the entire program
ahhh makes sense
i got a question though
then im guesing the new should be in the static part of the library right? since im not linking against libcpp
it should never ever be "in" any library
what provides the impl then?
it should be the executable's choice, so it should be in the executable
but i'm not linking against LibCPP, yet it works?
what would that affect?
sorry if im being unclear, my knowledge of that subject is fairly limited....
I think your best bet is trying it and seeing if it works
ask what?
hold on, writing the question in a way that makes sense lol
how does the library i'm using find the implementation of new in the default scenario, with no override?
im guessing it was compiled in the static library, right?
it says "I use new" and the loader goes and finds out who defines new
so new is provided by the system in the form of a dynamic library that the executable asks for?
well I don't really know what nonsense windows does
okay i just wanted to connect it to things i understand
okay!
thanks for helping me process this, i will try
it's possible that it doesn't work on windows, but everything I said is true everywhere else