我正在尝试实现我自己的内存分配器 malloc() 版本。但是有人指出,在我的情况下, brk() 已超过最大堆。
我需要在进行测试的平台上运行我的代码(所以我看不到测试)。
这是我对 malloc() 的实现:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
typedef struct obj_metadata {
size_t size;
struct obj_metadata *next;
struct obj_metadata *prev;
int is_free;
} obj_metadata;
void *mymalloc(size_t size)
{
if (size == 0)
{
return NULL;
}
else
{
return sbrk(size * sizeof(obj_metadata));
}
}
我在测试时遇到了这个错误:
Test "malloc-orders" exited with error: Assertion "addr <= heap + max_brk_size" at
test_framework/intercept.c:38 failed: New brk 0x7fbe6f4c7fe0 beyond max heap size (max heap
size=134217728, max heap=0x7fbe674c8000)
谁能告诉我如何解决这个问题?