我试图弄清楚如何在操作系统的最低级别分配内存。据我所知,操作系统只是在对可用内存和不可用内存进行记账,而C编程语言将在最低级别进行分配。
因此,第一个示例是我作为一个简单的内存分配系统想到的,然后从以下资源中获取了一个示例:https : //github.com/levex/osdev。
示例1:
struct heap_elements {
int start_address;
int end_address;
int size;
int reservation;
};
struct heap_elements heap[25];
// Write len copies of val into dest.
void memset(int *dest, int val, int len)
{
int *temp = (int *)dest;
for ( ; len != 0; len--) *temp++ = val;
}
/*
* This function will take a source and destination and copy n amount
* - of bytes from the source to the destination address.
*/ …Run Code Online (Sandbox Code Playgroud)