简体   繁体   English

如何在不使用动态分配器的情况下动态访问 memory 包括 brk、sbrk 和 mmap

[英]How to access memory dynamically without using dynamic allocator include the brk, sbrk and mmap

I have been given a task to simulate heap space and implement malloc , free and realloc on this piece of memory.我的任务是模拟堆空间并在这块 memory 上实现mallocfreerealloc The size of this piece of memory is not fixed, but I am not allowed to use any standard library allocator, brk , sbrk , mmap , alloca , and variable-length array.这块 memory 的大小是不固定的,但是我不允许使用任何标准库分配器, brksbrkmmapalloca和变长数组。 Can anybody give me even a piece of hint on this?任何人都可以给我一点提示吗?

Thanks for you guys but static variables are also forbidden.谢谢你们,但 static 变量也被禁止。

My interpretation is that you are supposed to write an implementation on a simulated heap.我的解释是你应该在模拟堆上编写一个实现。 That is, you should write code that allows the user to allocate and deallocate address space.也就是说,您应该编写允许用户分配和释放地址空间的代码。 The memory does not physically have to be available, but your code should act as if it manages heap space of some arbitrary size. memory 在物理上不一定可用,但您的代码应该管理任意大小的堆空间一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM