Articles of malloc

使用tcmalloc – 如何正确加载malloc扩展?

在文件gperftools-2.2.1 / src / gperftools / malloc_extension.h中,它读取: // Extra extensions exported by some malloc implementations. These // extensions are accessed through a virtual base class so an // application can link against a malloc that does not implement these // extensions, and it will get default versions that do nothing. // // NOTE FOR C […]

mallinfo有64位的替代品吗?

在Linux上,我们有一个名为mallinfo的 (GNU C库)函数,它给你一些与内存分配有关的数字: struct mallinfo { int arena; /* Non-mmapped space allocated (bytes) */ int ordblks; /* Number of free chunks */ int smblks; /* Number of free fastbin blocks */ int hblks; /* Number of mmapped regions */ int hblkhd; /* Space allocated in mmapped regions (bytes) */ int usmblks; /* Maximum total allocated […]

如何在Linux上进行分配时logging堆栈?

在OS X上,在运行程序之前设置MallocStackLogging环境variables将导致malloc(3)和free(3)每次调用每个内存区域时logging堆栈。 这对于debugging内存损坏问题特别有用,因为您可以回顾已损坏的区域的历史logging,并找出哪部分代码是应该对内存负责。 我知道我可以在Linux上使用__malloc_hook来编写我自己的debugging工具的实现,但是我想知道是否没有更简单的方法来完成同样的事情? 在Linux上跟踪分配的build议方式是什么?

有一个命令,我可以打电话打印出malloc数据结构?

您好我不知道是否有任何现成的function,我可以打印所有的malloc数据结构,以便我可以看到哪个内存分配哪个variables? 我有这个内存腐败,当我释放一个variables它抱怨,但我不知道哪个variables是相邻的。 谢谢!

linux new / delete,malloc / free大内存块

我们有一个运行多个CORBA服务器进程的linux系统(kubuntu 7.10)。 服务器软件使用glibc库进行内存分配。 linux电脑有4G物理内存。 由于速度原因,交换被禁用。 在收到处理数据的请求后,其中一个服务器进程分配一个大的数据缓冲区(使用标准的C ++运算符'new')。 缓冲区大小取决于许多参数,但通常在1.2G字节左右。 它可以达到约1.9G字节。 当请求完成时,使用'delete'释放缓冲区。 这适用于分配相同大小的缓冲区的几个连续请求,或者如果请求分配比前一个更小的大小。 内存似乎是免费的 – 否则缓冲区分配尝试最终会失败,只需几个请求。 在任何情况下,我们都可以看到使用KSysGuard等工具为每个请求分配和释放缓冲区内存。 当一个请求需要一个比前一个更大的缓冲区时,就会出现问题。 在这种情况下,运算符“new”引发exception。 就好像已经从第一次分配中释放的内存不能被重新分配,即使有足够的空闲物理内存可用。 如果我在第一次操作之后终止并重新启动服务器进程,则第二次请求更大的缓冲区大小会成功。 即杀死进程似乎完全释放释放的内存回到系统。 任何人都可以提供关于这里可能发生的事情的解释吗? 这可能是某种碎片或映射表的大小问题? 我正在考虑用malloc / freereplacenew / delete,并使用mallopt来调整内存被释放到系统的方式。 顺便说一句 – 我不知道它是否与我们的问题有关,但服务器使用Pthreads创build和销毁每个处理请求。

Linux上使用的malloc版本

我只是看glibc malloc.c文件顶部的注释,它说: 您可能已经默认使用包含malloc的C库 这是基于这个malloc的一些版本(例如在 Linux版)。 您可能仍然想要使用该文件中的一个 自定义设置或避免与库相关的开销 版本。 我不明白为什么glibc代码会说一个版本的Linux可能会使用不同的代码在glibc malloc.c ? 请有人帮忙重新说这是什么意思? 我认为glibc malloc()是每个Linux将用于内存pipe理?

索引“mallocced”数组时遇到分段错误

我一直在为这个问题挣扎了好几个小时,而且对于发生的事情我感到不知所措。 这是program.c的代码: #include <stdio.h> #include <stdlib.h> #include <assert.h> #define SPACE 32 #define INITIAL 4 typedef struct { char *town; char *country; } town_t; typedef struct { int num_towns, current_size; town_t **towns_list; } index_t; int main(int argc, char *argv[]) { index_t town_index; town_index.current_size = INITIAL; town_index.towns_list = malloc(town_index.current_size * sizeof(*(town_index.towns_list))); assert(town_index.towns_list != NULL); printf("Step: %d\n", 1); […]

有一个malloc变种,在调用`free()`时清零块吗?

我想在系统范围内replace标准的malloc(通过LD_PRELOAD或者只是replace已安装的libc),将所有可能被释放的块清空。 有谁知道现有的解决scheme? 零堆在堆的未使用部分将使压缩它通过zramconfiguration更有效。 由于我需要比CPU更多的RAM,增加的CPU使用率不成问题。

mremap和malloc一起工作吗?

是 void * mremap(void *old_address, size_t old_size , size_t new_size, unsigned long flags); 兼容malloc()? GCC(C ++)和使用Linux。 谢谢。

一次使用函数 – 我应该使用malloc或不

我有一点点长的C代码,有一个函数只会被调用一次。 这包括一些像char array , int这样的variables。 代码是这样的: void onetimefcn(){ char example_array1[20]="hello…"; //… char example_array10[14]="hej…"; int x=3,y=432,z=321,d=4439; //some arithmatic operation //some char array operation: strcpy, strcmp // some for loops and if else conditions } 我将在embedded式Linux设备上运行该代码。 我想知道如果我应该使用malloc的所有variables在那个function,然后free它们? 会有助于有效利用资源,否则会出现一些严重的问题(如果是这样的话,会发生什么)?