[OT] I wrote a (better?) heap memory manager, is it good for anything?

Mehrdad via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 9 01:48:36 PDT 2014


Hi all,

This is barely relevant to D, but I thought I'd try posting it 
here because I thought the audience might be interested. Let me 
know if I should post it somewhere else.

Long story short, I wrote my own C++ heap memory manager a while 
ago from scratch. First, here's a description:

Cons:
- Average-case performance is somewhat worse than heap managers 
provided by the OS or language runtimes
- I'm not quite ready to open-source it yet (partly because I'm 
not sure if it's worth licensing commercially vs. open-sourcing, 
and partly because I'm not quite confident it's completely 
bug-free yet)

Pros:
- It was built from the ground-up to have dependable worst-case 
performance, and I think it's *pretty good* and robust under 
various allocation patterns
- It keeps metadata entirely separate from data -- so when 
allocate a 4KB page of memory, it's not going to allocate an 
extra 4KB behind it just to put a "length" field there, which has 
given me problems before. (This can reduce the working set of the 
process considerably depending on your allocation granularity.)
- It is alignment-agnostic -- so, it allocates _exactly_ as much 
as requested (no performance penalty for this whatsoever)
- It's platform-independent (it's worked on Windows and also on 
Linux the few times I tried it) -- it's pretty easy to supply 
your own memory manager underneath, too.
- It has a very simple C (and C++) interface:

	typedef uintptr_t ManageMemory(
		void *context, uintptr_t address, size_t size,
		bool deallocate, bool commitment);
	extern ManageMemory manage_system_memory;
	void *memory_heap_construct(
		void *p, ManageMemory *manager, void *context);
	void memory_heap_destroy(void *p);
	void *memory_heap_allocate(
		void *heap, size_t size, void *hint);
	void memory_heap_deallocate(
		void *heap, void *address, size_t size);
	size_t memory_heap_size();

I was basically wondering if had any particular workloads they 
were interested in testing this on and giving me feedback on it. 
For now I'd give you a .DLL or a .so (though I haven't 
redistributed Linux binaries before, so I'd have to figure out 
how to do that) and the C/C++ header so you can use it and see 
how it is. Maybe you'd find it potentially useful for D too, but 
I guess that depends on how well it performs.

Let me know if you're interested.


More information about the Digitalmars-d mailing list