Skip to content

full change in implementing windows malloc support#3170

Open
mar-yan24 wants to merge 2 commits intogoogle-deepmind:mainfrom
mar-yan24:mark/win-alloc
Open

full change in implementing windows malloc support#3170
mar-yan24 wants to merge 2 commits intogoogle-deepmind:mainfrom
mar-yan24:mark/win-alloc

Conversation

@mar-yan24
Copy link
Copy Markdown
Contributor

Summary -

Fixes #2337: Windows memory allocation failure when creating many MjData instances.

Not sure if there is much interest in still resolving this issue by @okmatija or @yuvaltassa but I did a simple edit on the original MRE to print the memory allocation and discovered that the origin of the issue. In engine_io.c three mju_malloc calls are made for each MjData using aligned malloc so its overloading the VMS.

Before:
image

After:
image

Fix

For allocations >= 64KB on windows, I just replaced _aligned_malloc with VirtualAlloc(MEM_RESERVE) and a vectored exception handler that commits pages on first access. This basically just mimics the linux overcommit behavior.

I am pretty confident that this implementation is safe but a review or some help with the code implementation if needed would be nice.

@mar-yan24
Copy link
Copy Markdown
Contributor Author

the more i work on this solution the more im confused on whether or not it is optimal, just implemented a quick fix to pass one of the test cases. any suggestions would be great

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

Successfully merging this pull request may close these issues.

Memory allocation error using Windows OS

1 participant