您有任何有用的意见/建议/评论吗? 谢谢。 - Chris M. Thomasson http://appcore.home.comcast.netHere is the code: http://pastebin.com/m4a405e67One advantage to using a region allocator is that you can usually skip mostcalls to free. Instead you can merge multiple free calls into a single resetcall. Here is simple example:__________________________________________________ _________________int main(void) {allocator this_allocator;/* create allocator instance with initial region size of 8192 anda low-watermark region count of 2*/if (! allocator_create(&this_allocator, 8192, 2)) {for (;;) {int i;for (i = 1; i < 1024; ++i) {allocator_request(&this_allocator, i);}allocator_reset(&this_allocator);}allocator_destroy(&this_allocator);}return 0;}__________________________________________________ _________________The above program will never run out of memory... However, this algorihtmdoes not prohibit you from using free. For example:__________________________________________________ _________________int main(void) {allocator this_allocator;if (! allocator_create(&this_allocator, 8192, 2)) {for (;;) {int i;for (i = 1; i < 1024; ++i) {void* const ptr = allocator_request(&this_allocator, i);if (ptr) {allocator_release(&this_allocator, ptr);}}}allocator_destroy(&this_allocator);}return 0;}__________________________________________________ _________________Do you have any helpful comments/suggestions/critiques?Thanks.--Chris M. Thomasson http://appcore.home.comcast.net推荐答案" C hris Thomasson < cr ***** @ comcast.netwrote in message 新闻:aL ************************* *****@comcast.com。 .."Chris Thomasson" <cr*****@comcast.netwrote in messagenews:aL******************************@comcast.com. .. 这是代码: http://pastebin.com/m4a405e67 [...] WHOOPS!我发布了错误的糟糕版本! 这是一个很好的版本: http://pastebin.com/m31a4ad41 我非常抱歉这个非感觉!!! ; ^([...]WHOOPS! I posted wrong crappy version!Here is the good one: http://pastebin.com/m31a4ad41I am VERY sorry for that NON-SENSE!!!;^(" Chris Thomasson"< cr ***** @ comcast.netwrote in message news:t7 *** ***************************@comcast.com .."Chris Thomasson" <cr*****@comcast.netwrote in messagenews:t7******************************@comcast.com. .. Chris Thomasson< cr ***** @ comcast.netwrote in message 新闻:aL ******************** **********@comcast.com .."Chris Thomasson" <cr*****@comcast.netwrote in messagenews:aL******************************@comcast.com. .. >这是代码: http://pastebin.com/m4a405e67 [...] WHOOPS!我发布了错误的糟糕版本! 这是好的: http:// pas tebin.com/m31a4ad41 ^^^^^^^^^^^^^^^^^ 有错误;但似乎仍然编译! :^ / 这是摆脱错误的版本: typedef struct region_s region; typedef struct region_s { unsigned char * buf; size_t size; size_t offset; unsigned count; dlnode节点; }; ''struct region_s''上的前导typedef很糟糕。修复: http://pastebin.com/m52ba914 似乎编译成功。即使在Comeau ......; ^)^^^^^^^^^^^^^^^^^has error; but still seems to compile! :^/Here is version that gets rid of error:typedef struct region_s region;typedef struct region_s {unsigned char* buf;size_t size;size_t offset;unsigned count;dlnode node;};The leading typedef on ''struct region_s'' is bad. Fix: http://pastebin.com/m52ba914It seems to compile successfully. Even on Comeau... ;^) 我非常抱歉这个非感觉!!! ; ^(I am VERY sorry for that NON-SENSE!!!;^(" Chris Thomasson"< cr ***** @ comcast.netwrote in message news:aL ****************************** @ comcast.com .."Chris Thomasson" <cr*****@comcast.netwrote in messagenews:aL******************************@comcast.com. .. 这是代码:Here is the code: [...] 有没有人试过这个分配器: http://pastebin.com/m52ba914 ?[...]Has anybody tried this allocator yet: http://pastebin.com/m52ba914? 这篇关于简单的单线程区域分配器......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 22:05