MallocAllocator, wrongly computed size?

Issue #3 resolved
Anonymous created an issue

The following code is used to compute the final size to allocate in the MallocAllocator, but isn't it wrong to add "align" there, size includes necessary padding for alignment as well. Unless I'm mistaken this creates an empty space the size of the alignment after each allocation, is this intentional?

static inline uint32_t size_with_padding(uint32_t size, uint32_t align) {
    return size + align + sizeof(Header);

Comments (2)

  1. bitsquid repo owner

    No the size doesn't include the alignment padding.

    Since we don't now how the memory returned by malloc() will be aligned (one of the downsides of malloc()), we must ask for extra space, so that we can offset the block that we return to the user to achieve the desired alignment. (This is done by the data_pointer() function.)

  2. Log in to comment