Closed KTSnowy closed 1 year ago
@GitMensch, if you have time I'd like to request your review of the abstracted API for the OS-specific virtual memory functions. Once we finish the allocator, this PR will close our manual memory allocation issue (#28), and we'll use it for every dynamic memory allocation in the Otterkit runtime.
I'll definitely have a look, but this won't happen anytime soon, more "in weeks".
Hey everyone, GREAT NEWS! After doing a very basic benchmark of it, our allocator appears to be 4.5 times faster (both functions) than the system malloc on Windows. I ran the benchmark a couple of times and it seems consistent, our malloc and free pair is 4.5 times faster.
This is a very very basic benchmark, but it does show promising results. We're calling malloc, attempting to write to the start and end of the block, and freeing it right after. The calls are opaque to the C# compiler, so it won't optimize those out.
The NativeMemory.Alloc
method calls the system malloc directly (from what I've seen in their source code).
@GitMensch It looks like the likely
macro ended up helping a bit so I'll keep using it, at least in the allocator code.
There are some additional changes that ended up in the allocator branch that we need to merge with this as well, so this includes a few more files. There's also some big improvements for CASPAL that are needed in order to support cross-platform virtual memory allocation.
The code below is the CASPAL abstraction for OS-dependent virtual memory allocation, which is needed for the allocator design to work. I didn't want to pollute the allocator's source code with preprocessor spaghetti of
#if defined
s to conditionally compile into the appropriately function for each OS, so I abstracted those away into something that works mostly the same on all 3.