[C++] Why can't I find the address of the block's header in my custom allocator?

StackMasher

Well-Known Member
OP
Member
Joined
Nov 29, 2016
Messages
136
Trophies
0
Age
21
XP
380
Country
Here's the source code: https://github.com/RealPipeline/Paw/tree/master/src/memory
Basically, in the alloc function I return the blocks header + blockMetaSize, which is the size of the block header plus any extra bytes added in for alignment
In the free function, I try to get the header's address again by taking blockMetaSize from the address passed, but the address is incorrect
Here's some debug output:
Code:
in alloc()
0x7faf8ad70c20 (the address of the data to return), 64 (blockMetaSize), 0x7faf8ad70020 (header address)
In free()
0x7faf8ad70c20 (the address of the data to free (correct)), 64 (blockMetaSize), 0x7faf8ad70b20 (calculated header address (wrong by b00!)
 

StackMasher

Well-Known Member
OP
Member
Joined
Nov 29, 2016
Messages
136
Trophies
0
Age
21
XP
380
Country
Converting each pointer to uintptr_t rather than converting the whole expression to uintptr_t fixed it for some reason, I'm not sure why but it works
solved
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: Nintendo becomes responsible for 2024s virus