{"id":369,"date":"2008-10-19T20:46:05","date_gmt":"2008-10-20T00:46:05","guid":{"rendered":"http:\/\/www.rakkar.org\/blog\/?p=369"},"modified":"2008-10-19T20:46:05","modified_gmt":"2008-10-20T00:46:05","slug":"memory-heap-allocator-faster-than-newdelete","status":"publish","type":"post","link":"https:\/\/rakkar.org\/blog\/index.php\/2008\/10\/19\/memory-heap-allocator-faster-than-newdelete\/","title":{"rendered":"Memory heap allocator faster than new\/delete"},"content":{"rendered":"<p>\t\t\t\tHere&#8217;s a class that given a predefined area of memory, allows you to allocate and deallocate areas of that memory. In other words, a custom memory manager.<\/p>\n<p>Only partially done yet, but it&#8217;s already 25% or so faster than malloc and free<br \/>\n<a HREF=\"http:\/\/www.rakkar.org\/blog\/downloads\/DS_Allocator.h\">Header<\/a><br \/>\n<a HREF=\"http:\/\/www.rakkar.org\/blog\/downloads\/DS_Allocator.cpp\">CPP<\/a><\/p>\n<p><b>Full alloc, then dealloc<\/b><br \/>\nHeap = 1304 us<br \/>\nmalloc = 878256 us<\/p>\n<p><b>Fragmentation<\/b><br \/>\nHeap = 3525 us<br \/>\nmalloc = 4462 us<\/p>\n<p>Most of the speedup comes from linked lists of buckets. There are 7 buckets, from 32 bytes to 2048 bytes, incrementing in powers of two. 20% of the given memory is dedicated to buckets. If an allocation is requested and a bucket is available, the allocation goes to that bucket instead. Because buckets are contiguous and reserved, those allocations cannot cause fragmentation.<\/p>\n<p>The alignment boundary is 32 bytes, so all allocations returned to the user are aligned, and the average memory wasted per allocation is 32 bytes, excluding buckets.<\/p>\n<p>The speeds shown are with a critical section lock. This is not necessary, and for single threads it would be even faster.\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a class that given a predefined area of memory, allows you to allocate and deallocate areas of that memory. In other words, a custom memory manager. Only partially done yet, but it&#8217;s already 25% or so faster than malloc and free Header CPP Full alloc, then dealloc Heap = 1304 us malloc = 878256 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/369"}],"collection":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=369"}],"version-history":[{"count":0,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"wp:attachment":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}