DEV Community

Discussion on: Writing My Own Dynamic Memory Management

Collapse
 
cklasacrcez profile image
cklasacrcez • Edited

Hi! I checked your algorithm on a few examples and it does not work properly at all. That is, it does not free memory properly.

// CONSOLE OUTPUT
a:00293D34
b:00292D24
c:00292D10
d:00291D00  -> Here the address should be the same as for b
f:00291D00
Enter fullscreen mode Exit fullscreen mode
     // THE CODE
    int* a = (int*)mem_alloc(sizeof(int)); 
    int* b = (int*)mem_alloc(0x1000);
    int* c = (int*)mem_alloc(sizeof(int));
    std::cout << "a:" << a << std::endl; 
    std::cout << "b:" << b << std::endl;
    std::cout << "c:" << c << std::endl;

    mem_free(b);

    int* d = (int*)mem_alloc(0x1000); // here should be adress of B 
    std::cout << "d:" << d << std::endl;

    int* e = (int*)mem_alloc(sizeof(int));
    mem_free(d);

    int* f = (int*)mem_alloc(0x1000);
    std::cout << "f:" << f << std::endl;
Enter fullscreen mode Exit fullscreen mode
Collapse
 
frosnerd profile image
Frank Rosner

Hmmmm... I tested it a bit but didn't write any thorough unit tests. Do you know what's broken?

Collapse
 
fox3211 profile image
Fox

your merge_current_node_into_previous function not returning anything when it suppose to return void*

Thread Thread
 
frosnerd profile image
Frank Rosner

Oops! Thanks! :) Feel free to submit a PR :)

Thread Thread
 
fox3211 profile image
Fox

how i new to this site

Thread Thread
 
frosnerd profile image
Frank Rosner

You can open a new PR on GitHub. You can find instructions how to contribute to GitHub projects on the internet, such as dataschool.io/how-to-contribute-on...

Let me know if you get stuck :)

Thread Thread
 
fox3211 profile image
Fox

ok so is my answer is the right answer about whats broken

Thread Thread
 
frosnerd profile image
Frank Rosner

I don't know but if you make a PR / try it out we can test it :)

Thread Thread
 
fox3211 profile image
Fox

is there a private chat feature

Thread Thread
 
frosnerd profile image
Frank Rosner

I followed you so we can use dev.to/connect or you can hit me up on Twitter :)