Making a simple Dynamic Memory Allocator (malloc)

preview_player
Показать описание
In this video I discuss how to make a simple dynamic Memory Allocator.

CODECRAFTERS x DWB:
Рекомендации по теме
Комментарии
Автор

Creo que no he encontrado a nadie que lo explique mejor . Gracias!!!

braulio
Автор

I love your content so much. Cannot wait to watch this

ENDESGA
Автор

3:30 the real problem with defragmentation is that you cannot move heap data around, as you would invalidate any pointer that was acquired before the defragmentation. As far as I know, generic heap defragmentation is impossible in low level languages, except maybe for a very restricted set of programs.
I can only think of heap defragmentation being possible in high-level languages where the programmer cannot ever directly access pointers and heap data is always kept behind two levels of indirection (an object on the heap is owned by a reference counting smart pointer and the programmer is given a reference to the smart pointer), allowing for the mutation of the pointer to the actual heap data (for defrag) without invalidating any reference the programmer may have lying around.

nicholas_obert
Автор

0:31 only few know what the number 0x7c00 really means

groxxxx
Автор

free() needs to know the size passed to malloc(). It can not turn off all the contiguous '1's because it could deallocate another blocks

isidroarias
Автор

I loved your videos! where can I learn more about making an OS?

iagojacob
Автор

Is a bitmap commonly used? I thought the most common is a freelist since that makes scanning easy and is an implicit data structure (so it works well with things like sbrk).

Skybrg
Автор

Ummmm.... But when you defrag the blocks, how do you notify the consument its pointer to the data has changed ?
What I mean by that:

int *data = malloc(N); // data now points to 0x123
// allocate bunch of data and free everything except data*, so that memory is fragmented
// at some point defrag in malloc runs once you allocated something
// data* still points to 0x123, however by defragging everything has moved to lets say beginning, so the actual data is stored at 0x0
data[0] = 5; // CG, you've just pagefaulted.

panjak
Автор

Can you maybe show how one would implement a dynamic memory allocator that also keeps track of the amount of memory allocated, such that calling free() doesn't require the additional size parameter?

Bard_Gaming
Автор

void* my_alloc(size_t bytes) { return malloc(bytes); } // ez

yarrakobama
Автор

We need your help for making an amd64 OS because I understand the best from you.

FamilyAcc-yquj
Автор

When will we start making the GUI of this OS 😢

Pranavbg_
Автор

Could you help me with the os tutorial? I created an array inside the c file, and when I try to access the array, all the values are null or 0. Could you show me how to fix this?

josetheyose
Автор

It's not true you can move memory in linear way with memove moving a pointer elsewhere

darknais
Автор

To access heap memory in C++ you don’t use malloc/free nor new and delete, they are considered a bad practice since C++11 since you need to manually manage objects lifetimes and when they are deleted, instead you need to use smart pointers

Edit: I know this video talks about a lower level approach, I was just speaking about a more general use case.

pixfri
Автор

ill try out the free project for september in codecrafters, if it's cool enough

ゾカリクゾ
welcome to shbcf.ru