内存池库? [英] memory pool library ?

查看:123
本文介绍了内存池库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道一个开源内存池库吗?我似乎无法找到任何在C中实现的(许多在C ++中可用,例如Boost)。 Google没有提供任何有用的东西......

解决方案

Grey Alien< gr ** @ andromeda.comwrites :


任何人都知道一个开源内存池库?我似乎无法找到任何在C中实现的(许多在C ++中可用,例如Boost)。谷歌

没有出现任何有用的东西...



这在很大程度上取决于你所追求的是什么样的汇集;

术语含糊不清。 Apache有一个内存实现

池,GNU libc通过它的另一个来自另一个。

-

欢迎来到精彩的世界未定义的行为,其中恶魔

是鼻子,而DeathStation用户则很紧张。 --Daniel Fox





Ben Pfaff写道:


Gray Alien< gr ** @ andromeda.comwrites:


>>任何人都知道开源内存池库?我似乎无法找到任何用C实现的(许多在C ++中可用,例如Boost)。谷歌没有提供任何有用的东西...




这在很大程度上取决于你追求的是什么样的汇集;

术语含糊不清。 Apache有一个内存实现

池,GNU libc通过它的assacks有另一个。



真的很简单。我目前在程序生命周期中多次分配/删除
内存(一个结构)的小部分,并且我想要

来在prog开始时分配内存(比如说5MB)所以我没有开始使用

malloc / free(更不用说碎片了)。然后我可以在编程生命周期中,在必要时,在编程生命周期中从池中请求/释放
块。


Gray Alien写道:


...我目前在程序生命周期中多次分配/释放一小部分

内存(一个结构),我想要

在prog开始时分配内存(比如说5MB)所以我没有开销

malloc / free(更不用说碎片了)。然后,我可以在prog生命周期中根据需要从池中请求/释放
块。



最简单的系统是使用固定大小的内存块。将

大块分成几个所需大小的块。当一个块被取消分配时,将其链接到一个空闲块列表中,用于

分配。没有搜索,没有合并。你可以在大约30分钟内写出这个 - 一些在这里,更不用说了!


-

Thad


Any one know of an open source memory pool library?. I can''t seem to
find any implemented in C (many available in C++ e.g. Boost). Google is
not turning up anything useful ...

解决方案

Grey Alien <gr**@andromeda.comwrites:

Any one know of an open source memory pool library?. I can''t seem to
find any implemented in C (many available in C++ e.g. Boost). Google
is not turning up anything useful ...

It very much depends on what kind of pooling you''re after; the
term is ambiguous. Apache has one implementation of memory
pools, GNU libc through its obstacks has another.
--
"Welcome to the wonderful world of undefined behavior, where the demons
are nasal and the DeathStation users are nervous." --Daniel Fox




Ben Pfaff wrote:

Grey Alien <gr**@andromeda.comwrites:

>>Any one know of an open source memory pool library?. I can''t seem to
find any implemented in C (many available in C++ e.g. Boost). Google
is not turning up anything useful ...



It very much depends on what kind of pooling you''re after; the
term is ambiguous. Apache has one implementation of memory
pools, GNU libc through its obstacks has another.

Anything simple really. I am currently alloc/dealloc small bits of
memory (a struct) several times during a programs lifecycle and I want
to alloc memory at prog start (say 5MB) so I don''t have the overhead of
malloc/free (not to mention fragmentation). I can then request/release
chunks from the pool as and when necessary, during the prog lifecycle.


Grey Alien wrote:

... I am currently alloc/dealloc small bits of
memory (a struct) several times during a programs lifecycle and I want
to alloc memory at prog start (say 5MB) so I don''t have the overhead of
malloc/free (not to mention fragmentation). I can then request/release
chunks from the pool as and when necessary, during the prog lifecycle.

The simplest system is to work with fixed-size memory blocks. Break the
large block into several blocks of the desired size. When a block is
deallocated, link it into a list of free blocks, which is used to
allocate. No searching, no merging. You can write that in about 30
minutes -- some here, much less!

--
Thad


这篇关于内存池库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆