简体   繁体   English

如何在C中实现内存模拟?

[英]How to implement memory simulation in C?

Basically I need to have two lists, one of which keeps the list of empty memory holes by storing the starting point and the size of each hole. 基本上,我需要有两个列表,其中一个通过存储每个孔的起点和大小来保留空内存孔的列表。 The other one, keeps information about various processes (while there is no actual process data, rather just the id and starting location and size). 另一个保留有关各种进程的信息(虽然没有实际的进程数据,而只是id和起始位置和大小)。

So, I understand that I will need to have two structs, each of which defines the "hole" and the "process". 因此,我知道我将需要具有两个结构,每个结构都定义“孔”和“过程”。 I will need to have two lists to store these objects. 我将需要两个列表来存储这些对象。

What I don't understand, is how to "initialize memory". 我不明白的是如何“初始化内存”。 For example, if the user wants to initialize(5000 bytes), what should the initialize method do in respect to the two lists? 例如,如果用户要初始化(5000字节),那么对于两个列表,initialize方法应该做什么?

您只需清空进程列表(因为未分配内存),并创建一个从地址0到地址4999的单个孔(因为这些地址为空)。

Just implement a regular memory manager with malloc() and free() equivalents and extend it to support extra control data (eg your process IDs). 只需使用等效的malloc()和free()实现常规的内存管理器,并将其扩展为支持额外的控制数据(例如,您的进程ID)即可。 Or allocate a large block of memory, carve it up in smaller per-process pieces and implement memory management inside of those pieces. 或分配一个较大的内存块,将其分成较小的每个进程块,然后在这些块内部实施内存管理。 Take a look, for example, at Doug Lea's memory allocator . 例如,看看Doug Lea的内存分配器

See also Wikipedia on Memory Management in general. 通常也可以参见Wikipedia有关内存管理的内容。 Follow links. 跟随链接。

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

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