数组的内存管理 [英] Array memory management

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

问题描述

我做我的计算机科学项目。我使用C.一个要求对我们来说,我们不能保持分配的内存小块做多处理器编程。内存可以在大块需要时进行分配。

I am doing my Computing Science project. I am doing Multiprocessor programming using C. One requirement for us it that, we cannot keep allocating small chunks of memory. Memory can be allocated in big chunks when needed.

所以,想象一下我用的结构在我的计划。而我的程序的工作方式需要动态内存分配。但是,在我们使用的硬件非常昂贵的。所以最好的解决办法是在开始分配的内存大水池,每当需要从这个池分配内存。

So imagine I use structures in my program. And the way that my program works requires dynamic memory allocation. But it is very costly in the hardware that we are using. So the best solution would be to allocate a big pool of memory at the beginning and whenever needed allocate memory from this pool.

我设想这个工作的方式是,我会分配这些结构的位阵列或写入分配,从这个池来释放内存,我自己的内存管理模块。但我想知道写这些模块最为理想的方式。有没有能帮助我管理内存或任何库是有一些方法,这些可写?

The way I envision this to work is that, I will allocate a bit array of these structures and write my own memory management module which allocates and frees memory from this pool. But I want to know the most ideal way to write these modules. Are there any libraries which can assist me in managing memory or is there some way that these can be written?

编辑:这是我使用平台:它运行的Ubuntu的AMD皓龙系统。该皓龙处理器具有NUMA架构,我想分配内存时利用了这一点。因此,不是用malloc,我使用 numa_alloc_onnode 哪一个特定节点上分配内存。我想用这个来分配内存的一大块,然后用一个内存管理器来管理此内存。

Here is the platform that I use: an AMD opteron system which runs Ubuntu. The opterons has NUMA architecture and I want to make use of this when allocating memory. Hence instead of using malloc, I use numa_alloc_onnode which allocates memory on one specific node. I want to allocate a big chunk of memory using this and then use a memory manager to manage this memory.

推荐答案

有一吨的内存池经理在那里,一些商业和一些开源。看看他们,随意你有一个概述后,在这里提出更具体的问题。

There are a ton of memory pool managers out there, some commercial and some open source. Have a look at them, and feel free to ask more specific questions here after you have an overview.

一些谷歌的结果(C内存池管理器开源):

Some google results (c memory pool manager open source):

http://256stuff.com/sources/mpool/

http://www.ravenbrook.com/project/mps/

下面是来自IBM关于这个问题的好文章:

Here's a good article from IBM on the subject:

http://www.ibm.com/developerworks/linux/library / L内存/

既然你提到一个多处理器环境中(虽然不直接相关的内存管理),这也是一个值得读:

And since you mention a multiprocessor environment (although not directly related to memory management), this is also a worthwhile read:

http://drdobbs.com/go-parallel/article/ showArticle.jhtml?=条款ArticleID 217500206

http://drdobbs.com/go-parallel/article/showArticle.jhtml?articleID=217500206

更新

有取决于库的所需可移植性不同的方法。如果便携性是很重要的,库presents各地的malloc(或释放calloc)包抓的内存块,然后应用更有效的实现(如针对特定目标的图书馆要实现测量)。即针对特定的操作系统通常会使用本地操作系统调用,获得一些性能和可移植性的成本,利用该操作系统的细节的能力的库。

There are different approaches depending on the desired portability of the library. If portability is important, the library presents a wrapper around malloc (or calloc) to grab chunks of memory and then apply a more efficient implementation (as measured against the particular goals the library wants to achieve). A library that targets a specific OS will typically use native operating system calls, gaining some performance and the ability to leverage specifics of that operating system at the cost of portability.

这是内存管理库,力争为特定目标而有所不同。这里有一些目标,我已经看到了多年来:

The specific goals that memory management libraries strive for vary. Here are some goals I have seen over the years:


  • 对于大与小的对象单独的管理策略

  • 事情将生活将迅速删除长与事
  • 单独的管理策略

  • 调试内存管理问题(例如写一个特定的模式到分配的内存和分配上月底一些额外的填充,使得调试功能,可查看该填充是由超出范围的指针访问,覆盖)

  • 更快的存储器存取一个特定平台的给定约束条件(例如某些分配可能是昂贵的,更为相对便宜)。

  • 支持的内存碎片整理(例如,通过真正分配指针的指针,以用于存取存储器特殊语义)。

更新2

根据您的更新......我的第四个项目符号适用。下面是对NUMA架构创建一个堆管理器良好的阅读(在文章的结尾源$ C ​​$ C):

Based on your update... my fourth bullet point applies. Here's a good read on creating a heap manager for a NUMA architecture (source code at the end of the article):

http://ebookbrowse.com/numa-aware-heap-memory-manager-article-final-pdf-d12526838

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

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