4 comments

  • teo_zero1 day ago
    Please be aware that pointer arithmetic is not defined on void * pointers, although many compilers allow it. You had better use char * for &quot;data&quot;.<p>Also, your code is prone to overflow when you add data, used, alignment and size.<p>And finally, the realloc function could be reworked to do nothing if new_size is &lt;= old_size.
  • unwind22 minutes ago
    More obvious problems with the code as shown:<p>- The macros doing arithmetic (KiB, MIN etc) don&#x27;t put their arguments in parentheses, that is very dangerous.<p>- The code assumes that int and i32 are the same size.<p>- Don&#x27;t cast the return value of malloc(). Please Google this.<p>I appreciated the use of structs by value, that&#x27;s a nice design.<p>I agree there&#x27;s a risk of overflow in the arithmetic around sizes&#x2F;alignment, but with a 64-bit `usize` that should be mostly theoretical.
  • sweetjuly1 hour ago
    &gt; This will be used to align the data. For some reason, our computers are much better at dealing with data that is aligned at 8 bytes. This means that the start of each new allocation has to be at a multiple of 8 bytes.<p>Casting a pointer which is not aligned to its natural alignment has undefined behavior in C. It&#x27;s not just an issue of unaligned accesses being slow; in practice, your program might also crash or access unexpected data on real platforms with real compiler implementations.
  • mrlonglong1 day ago
    Why redefine the stdints?
    • veltas38 minutes ago
      They wanted shorter aliases for them to make their code clearer, I suppose.