#Help with custom free() function

3 messages · Page 1 of 1 (latest)

kindred fjord
#

Hi all, I'm working on custom free / malloc functions using free and used linked lists, and I've been stuck on free for quite a while. I finished malloc a while ago and successfully changed the header pointers of the lists to reflect the change in data. However, in this free function, it's telling me that the head should be equal to 0x20, but isn't. I'm very confused - can someone point me in the right direction? Here's the offending snippet:

{        
    Trace::out2("progression\n");

    //remove from used list
    //void* newUsedEnd = (void*)((uint32_t)(pUsed) + sizeof(Used));        //split the used block to accomodate exact size
    //unsigned int sizeLeftOver = sizeof(Used) - pUsed->mData;
    this->poHeap->RemoveUsedNode(pUsed);

    const uint32_t usedData = GET_ALLOC_SIZE(pUsed->mData);
    unsigned int remSize = this->poHeap->currUsedMem - usedData;

    Free* pFree = new(pUsed) Free(*pUsed);
    this->poHeap->AddFreeNode(pFree);
    void* newFreeEnd = (void*)((uint32_t)(pFree + 1) + usedData);

    uint32_t hdrTotal = (uint32_t)((pUsed->mData + sizeof(Used)) - pUsed->mData);
    Free* uConvert = new Free(remSize - hdrTotal);
    Used* pAddUsed = new (newFreeEnd) Used(*uConvert);

    Trace::out2("0x%02x\n", this->poHeap->pFreeHead);

    this->poHeap->AddUsedNode(pAddUsed);```
worn parcelBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

kindred fjord
#

anyone?