内存缓冲区管理器,已批量分配. [英] memory buffer manager, bulk allocated.

查看:79
本文介绍了内存缓冲区管理器,已批量分配.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个数据缓冲区,该缓冲区存储大量4-5字节数据,并以不相同的顺序获取它们.该过程使用的其余资源很大且动态,因此碎片将严重影响性能.

数据被一个接一个地添加,然后被批量删除,但不能完全删除.

因此,我计划使用内存管理器将其实现为大容量分配的内存块.最好的方法是什么?

I need a data buffer which stores large number of 4-5 byte data and fetch them not in the same order they were allocated. The rest of the resources used by the process are large and dynamic so fragmentation will seriously affect performance.

Data is added one by one and removed in bulk but not fully.

So I plan to implement it as a bulk allocated memory chunk with a memory manager. What is the best way to do it?

推荐答案

在书中 ^ ],有一章关于小对象分配.他介绍了一种管理内存中许多小对象的有效方法(以一种有效的方式自己分配和取消分配它们).
我不知道这是否值得为此买书.但是,本书的其余部分也很有趣.
In the book Modern C++ design[^] by Andrei Alenxandrescu, there''s a chapter about small object allocation. He describes an efficient way of managing a lot of small objects in memory (allocating and deallocating them yourself in an efficient way).
I don''t know if this worth to buy the book just for that. However, the rest of the book is interesting too.


您的软件是在计算机上单独工作还是仅是预期与它一起运行的众多应用程序之一?

如果希望它单独工作,则只需分配一个大容量缓冲区,然后为自己编写一个算法即可处理各种片段(您需要一些辅助结构来跟踪空闲块,对其进行压缩和最合适).

但是请注意,这样的科学"不是当今的业务":这类算法几十年来众所周知,并且都嵌入到现代操作系统的内存分配器中,这些内存分配器可以毫不费力地管理碎片你可以使自己.因此,即使您通过系统将数据一一分配...也可能获得相同的效率.

如果期望它可以与所有可能的桌面应用程序一起运行...分配大量内存是不可行的:您应该在需要时请求内存,然后在不再需要时返回它,否则您的应用将对其他应用不公平".

如果您可以预测批量"中的数据将被释放以及批量"的大小,则可以尝试优化分配数量.

此时,您可以分配与批量一样大的"plex",然后再分配到plex中,并在完全空闲时将plex返回系统.
Does your software work alone on the computer or will it just one of many applications that are expected to run with it?

If it is expected to work alone, just allocate a bulk buffer and write yourself an algorithm that take care of the various fragments (you need some ancillary structures to track free blocks, compact them and best-fit).

But beware that''s such a "science" is not "today business": these kind of algorithms are well known from decades, and are all embedded into memory allocators of the modern operating systems, that manage fragmentation nerveless with no difference of what you can make yourself. So, even if you allocate through the system one data by one ... may be you get the same efficiency.

If it is expected to run together with all possible desktop apps ... allocating a big bulk is not the way to go: you should ask for memory as you need it and return it as you don''t need it anymore, otherwise your app will not be "fair" to other apps.

You can try to optimize the number of allocation if you can predict in wich "bulk" a data will be released and how large that "bulk" will be.

You can -at that point- allocate "plexes" large as the bulks, and suballocate into the plexes, returning the plexes to the system as they become completely free.


这篇关于内存缓冲区管理器,已批量分配.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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