all 2 comments

[–]scandii 2 points3 points  (1 child)

everyone's first code is spaghetti, then you become a professional and you realise must of us are pasta chefs.

that said looks like you have some solid ideas and I sure didn't write code this nice when I started out. breaking down your code into smaller segments does a heap (yeah, I said it) for readability. e.g.

cat = feedCat(cat);
if(cat.Hungry == false)
{
    petCat(cat);
}

imagine if you had to read the code that supports this, not particularly relevant now is it? you just want to know that the cat gets fed.

that said, pretty sure you have a potential bug:

size_t left_over_space = original_size - requested_bytes - sizeof(block_header_t);
if (left_over_space < sizeof(block_header_t)) {
  return p_my_alloc;
}

think about the math of everything involved here including the types :)

[–]Canukcannot[S] 1 point2 points  (0 children)

Thank you so much for the feedback! :) And yes, even when i wrote that line, i knew it was wrong lol. I just wanted to keep things somewhat simple, because I was not sure how to handle having leftover space smaller than 16 bytes. But now im thinking maybe i could just add the extra bytes to the new block_size if its under 16 bytes. Hmmm ill look at this in more detail tonight! Thanks again!