Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ operator new on Windows #86

Closed
seanmiddleditch opened this issue Jul 7, 2019 · 3 comments
Closed

C++ operator new on Windows #86

seanmiddleditch opened this issue Jul 7, 2019 · 3 comments

Comments

@seanmiddleditch
Copy link

While #85 makes this somewhat moot for me right now, it appears that overriding operator new in C++ on Windows is incomplete in mimalloc.

There's an #if 0 around the code in alloc-override-win.c that appears to be necessary to patch the operators. It's not documented why that's there.

Further, not all modern overloads of new are patched as of C++17. For example, there does not appear to be any patching for the std::align_val_t overloads, despite the mimalloc documentation.

@daanx
Copy link
Collaborator

daanx commented Jul 8, 2019

Thanks! Overriding the C++ operators is never necessary as they use malloc/free under the hood. Currently we only override them when compiling with a C++ compiler and only on macOS/Unix systems. The dynamic overriding on Windows is also still in flux so we disable it for now -- we might enable it again in the future for performance reasons.

@daanx daanx closed this as completed Jul 8, 2019
@seanmiddleditch
Copy link
Author

Overriding the C++ operators is never necessary as they use malloc/free under the hood

As discussed in #26, there is no such guarantee. Assuming new invokes malloc is relying on implementation-specific behavior within the standard library.

Even where it does... why would I want the align_val_t overloads of new to invoke malloc (and be forced to over-allocate and align within the block) rather than invoking an appropriate alignment-aware allocation entry point in the allocator?

@daanx
Copy link
Collaborator

daanx commented Jul 15, 2019

I agree Sean. I just pushed an update to the C++ overriding on Linux/BSD which is more complete and added the sized deletes on Windows. On windows there is still the #if 0 since we are actively working on an improved version. You can use #if 1 if you like -- it is as yet disabled since we observed problems on some (large) programs and it needs more investigation; for most programs it should be fine though :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants